11da66f75SEd Tanous /* 21da66f75SEd Tanous // Copyright (c) 2018 Intel Corporation 31da66f75SEd Tanous // 41da66f75SEd Tanous // Licensed under the Apache License, Version 2.0 (the "License"); 51da66f75SEd Tanous // you may not use this file except in compliance with the License. 61da66f75SEd Tanous // You may obtain a copy of the License at 71da66f75SEd Tanous // 81da66f75SEd Tanous // http://www.apache.org/licenses/LICENSE-2.0 91da66f75SEd Tanous // 101da66f75SEd Tanous // Unless required by applicable law or agreed to in writing, software 111da66f75SEd Tanous // distributed under the License is distributed on an "AS IS" BASIS, 121da66f75SEd Tanous // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131da66f75SEd Tanous // See the License for the specific language governing permissions and 141da66f75SEd Tanous // limitations under the License. 151da66f75SEd Tanous */ 161da66f75SEd Tanous #pragma once 171da66f75SEd Tanous 181da66f75SEd Tanous #include "node.hpp" 194851d45dSJason M. Bills #include "registries.hpp" 204851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 214851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2246229577SJames Feist #include "task.hpp" 231da66f75SEd Tanous 24e1f26343SJason M. Bills #include <systemd/sd-journal.h> 25e1f26343SJason M. Bills 264851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 274851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 281da66f75SEd Tanous #include <boost/container/flat_map.hpp> 291ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 300657843aSraviteja-b #include <dump_offload.hpp> 31cb92c03bSAndrew Geissler #include <error_messages.hpp> 321214b7e7SGunnar Mills 334418c7f0SJames Feist #include <filesystem> 34cd225da8SJason M. Bills #include <string_view> 35abf2add6SEd Tanous #include <variant> 361da66f75SEd Tanous 371da66f75SEd Tanous namespace redfish 381da66f75SEd Tanous { 391da66f75SEd Tanous 405b61b5e8SJason M. Bills constexpr char const* crashdumpObject = "com.intel.crashdump"; 415b61b5e8SJason M. Bills constexpr char const* crashdumpPath = "/com/intel/crashdump"; 425b61b5e8SJason M. Bills constexpr char const* crashdumpInterface = "com.intel.crashdump"; 435b61b5e8SJason M. Bills constexpr char const* deleteAllInterface = 445b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 455b61b5e8SJason M. Bills constexpr char const* crashdumpOnDemandInterface = 46424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 475b61b5e8SJason M. Bills constexpr char const* crashdumpRawPECIInterface = 48424c4176SJason M. Bills "com.intel.crashdump.SendRawPeci"; 496eda7685SKenny L. Ku constexpr char const* crashdumpTelemetryInterface = 506eda7685SKenny L. Ku "com.intel.crashdump.Telemetry"; 511da66f75SEd Tanous 524851d45dSJason M. Bills namespace message_registries 534851d45dSJason M. Bills { 544851d45dSJason M. Bills static const Message* getMessageFromRegistry( 554851d45dSJason M. Bills const std::string& messageKey, 564851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 574851d45dSJason M. Bills { 584851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 594851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 604851d45dSJason M. Bills [&messageKey](const MessageEntry& messageEntry) { 614851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 624851d45dSJason M. Bills messageKey.c_str()); 634851d45dSJason M. Bills }); 644851d45dSJason M. Bills if (messageIt != registry.cend()) 654851d45dSJason M. Bills { 664851d45dSJason M. Bills return &messageIt->second; 674851d45dSJason M. Bills } 684851d45dSJason M. Bills 694851d45dSJason M. Bills return nullptr; 704851d45dSJason M. Bills } 714851d45dSJason M. Bills 724851d45dSJason M. Bills static const Message* getMessage(const std::string_view& messageID) 734851d45dSJason M. Bills { 744851d45dSJason M. Bills // Redfish MessageIds are in the form 754851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 764851d45dSJason M. Bills // the right Message 774851d45dSJason M. Bills std::vector<std::string> fields; 784851d45dSJason M. Bills fields.reserve(4); 794851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 804851d45dSJason M. Bills std::string& registryName = fields[0]; 814851d45dSJason M. Bills std::string& messageKey = fields[3]; 824851d45dSJason M. Bills 834851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 844851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 854851d45dSJason M. Bills { 864851d45dSJason M. Bills return getMessageFromRegistry( 874851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 884851d45dSJason M. Bills } 894851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 904851d45dSJason M. Bills { 914851d45dSJason M. Bills return getMessageFromRegistry( 924851d45dSJason M. Bills messageKey, 934851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 944851d45dSJason M. Bills } 954851d45dSJason M. Bills return nullptr; 964851d45dSJason M. Bills } 974851d45dSJason M. Bills } // namespace message_registries 984851d45dSJason M. Bills 99f6150403SJames Feist namespace fs = std::filesystem; 1001da66f75SEd Tanous 101cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 10219bd78d9SPatrick Williams std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, 103cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 104cb92c03bSAndrew Geissler 105cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 106cb92c03bSAndrew Geissler sdbusplus::message::object_path, 107cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 108cb92c03bSAndrew Geissler 109cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string& s) 110cb92c03bSAndrew Geissler { 111cb92c03bSAndrew Geissler if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert") 112cb92c03bSAndrew Geissler { 113cb92c03bSAndrew Geissler return "Critical"; 114cb92c03bSAndrew Geissler } 115cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") 116cb92c03bSAndrew Geissler { 117cb92c03bSAndrew Geissler return "Critical"; 118cb92c03bSAndrew Geissler } 119cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug") 120cb92c03bSAndrew Geissler { 121cb92c03bSAndrew Geissler return "OK"; 122cb92c03bSAndrew Geissler } 123cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") 124cb92c03bSAndrew Geissler { 125cb92c03bSAndrew Geissler return "Critical"; 126cb92c03bSAndrew Geissler } 127cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error") 128cb92c03bSAndrew Geissler { 129cb92c03bSAndrew Geissler return "Critical"; 130cb92c03bSAndrew Geissler } 131cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") 132cb92c03bSAndrew Geissler { 133cb92c03bSAndrew Geissler return "OK"; 134cb92c03bSAndrew Geissler } 135cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice") 136cb92c03bSAndrew Geissler { 137cb92c03bSAndrew Geissler return "OK"; 138cb92c03bSAndrew Geissler } 139cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 140cb92c03bSAndrew Geissler { 141cb92c03bSAndrew Geissler return "Warning"; 142cb92c03bSAndrew Geissler } 143cb92c03bSAndrew Geissler return ""; 144cb92c03bSAndrew Geissler } 145cb92c03bSAndrew Geissler 14616428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 14739e77504SEd Tanous const std::string_view& field, 14839e77504SEd Tanous std::string_view& contents) 14916428a1aSJason M. Bills { 15016428a1aSJason M. Bills const char* data = nullptr; 15116428a1aSJason M. Bills size_t length = 0; 15216428a1aSJason M. Bills int ret = 0; 15316428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 154271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 155271584abSEd Tanous reinterpret_cast<const void**>(&data), &length); 15616428a1aSJason M. Bills if (ret < 0) 15716428a1aSJason M. Bills { 15816428a1aSJason M. Bills return ret; 15916428a1aSJason M. Bills } 16039e77504SEd Tanous contents = std::string_view(data, length); 16116428a1aSJason M. Bills // Only use the content after the "=" character. 16216428a1aSJason M. Bills contents.remove_prefix(std::min(contents.find("=") + 1, contents.size())); 16316428a1aSJason M. Bills return ret; 16416428a1aSJason M. Bills } 16516428a1aSJason M. Bills 16616428a1aSJason M. Bills static int getJournalMetadata(sd_journal* journal, 16739e77504SEd Tanous const std::string_view& field, const int& base, 168271584abSEd Tanous long int& contents) 16916428a1aSJason M. Bills { 17016428a1aSJason M. Bills int ret = 0; 17139e77504SEd Tanous std::string_view metadata; 17216428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 17316428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 17416428a1aSJason M. Bills if (ret < 0) 17516428a1aSJason M. Bills { 17616428a1aSJason M. Bills return ret; 17716428a1aSJason M. Bills } 178b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 17916428a1aSJason M. Bills return ret; 18016428a1aSJason M. Bills } 18116428a1aSJason M. Bills 182a3316fc6SZhikuiRen static bool getTimestampStr(const uint64_t usecSinceEpoch, 183a3316fc6SZhikuiRen std::string& entryTimestamp) 18416428a1aSJason M. Bills { 185a3316fc6SZhikuiRen time_t t = static_cast<time_t>(usecSinceEpoch / 1000 / 1000); 18616428a1aSJason M. Bills struct tm* loctime = localtime(&t); 18716428a1aSJason M. Bills char entryTime[64] = {}; 18899131cd0SEd Tanous if (nullptr != loctime) 18916428a1aSJason M. Bills { 19016428a1aSJason M. Bills strftime(entryTime, sizeof(entryTime), "%FT%T%z", loctime); 19116428a1aSJason M. Bills } 19216428a1aSJason M. Bills // Insert the ':' into the timezone 19339e77504SEd Tanous std::string_view t1(entryTime); 19439e77504SEd Tanous std::string_view t2(entryTime); 19516428a1aSJason M. Bills if (t1.size() > 2 && t2.size() > 2) 19616428a1aSJason M. Bills { 19716428a1aSJason M. Bills t1.remove_suffix(2); 19816428a1aSJason M. Bills t2.remove_prefix(t2.size() - 2); 19916428a1aSJason M. Bills } 20039e77504SEd Tanous entryTimestamp = std::string(t1) + ":" + std::string(t2); 20116428a1aSJason M. Bills return true; 20216428a1aSJason M. Bills } 20316428a1aSJason M. Bills 204a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp) 205a3316fc6SZhikuiRen { 206a3316fc6SZhikuiRen int ret = 0; 207a3316fc6SZhikuiRen uint64_t timestamp = 0; 208a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 209a3316fc6SZhikuiRen if (ret < 0) 210a3316fc6SZhikuiRen { 211a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 212a3316fc6SZhikuiRen << strerror(-ret); 213a3316fc6SZhikuiRen return false; 214a3316fc6SZhikuiRen } 215a3316fc6SZhikuiRen return getTimestampStr(timestamp, entryTimestamp); 216a3316fc6SZhikuiRen } 217a3316fc6SZhikuiRen 21816428a1aSJason M. Bills static bool getSkipParam(crow::Response& res, const crow::Request& req, 219271584abSEd Tanous uint64_t& skip) 22016428a1aSJason M. Bills { 22116428a1aSJason M. Bills char* skipParam = req.urlParams.get("$skip"); 22216428a1aSJason M. Bills if (skipParam != nullptr) 22316428a1aSJason M. Bills { 22416428a1aSJason M. Bills char* ptr = nullptr; 225271584abSEd Tanous skip = std::strtoul(skipParam, &ptr, 10); 22616428a1aSJason M. Bills if (*skipParam == '\0' || *ptr != '\0') 22716428a1aSJason M. Bills { 22816428a1aSJason M. Bills 22916428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(skipParam), 23016428a1aSJason M. Bills "$skip"); 23116428a1aSJason M. Bills return false; 23216428a1aSJason M. Bills } 23316428a1aSJason M. Bills } 23416428a1aSJason M. Bills return true; 23516428a1aSJason M. Bills } 23616428a1aSJason M. Bills 237271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 23816428a1aSJason M. Bills static bool getTopParam(crow::Response& res, const crow::Request& req, 239271584abSEd Tanous uint64_t& top) 24016428a1aSJason M. Bills { 24116428a1aSJason M. Bills char* topParam = req.urlParams.get("$top"); 24216428a1aSJason M. Bills if (topParam != nullptr) 24316428a1aSJason M. Bills { 24416428a1aSJason M. Bills char* ptr = nullptr; 245271584abSEd Tanous top = std::strtoul(topParam, &ptr, 10); 24616428a1aSJason M. Bills if (*topParam == '\0' || *ptr != '\0') 24716428a1aSJason M. Bills { 24816428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(topParam), 24916428a1aSJason M. Bills "$top"); 25016428a1aSJason M. Bills return false; 25116428a1aSJason M. Bills } 252271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 25316428a1aSJason M. Bills { 25416428a1aSJason M. Bills 25516428a1aSJason M. Bills messages::queryParameterOutOfRange( 25616428a1aSJason M. Bills res, std::to_string(top), "$top", 25716428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 25816428a1aSJason M. Bills return false; 25916428a1aSJason M. Bills } 26016428a1aSJason M. Bills } 26116428a1aSJason M. Bills return true; 26216428a1aSJason M. Bills } 26316428a1aSJason M. Bills 264e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal* journal, std::string& entryID, 265e85d6b16SJason M. Bills const bool firstEntry = true) 26616428a1aSJason M. Bills { 26716428a1aSJason M. Bills int ret = 0; 26816428a1aSJason M. Bills static uint64_t prevTs = 0; 26916428a1aSJason M. Bills static int index = 0; 270e85d6b16SJason M. Bills if (firstEntry) 271e85d6b16SJason M. Bills { 272e85d6b16SJason M. Bills prevTs = 0; 273e85d6b16SJason M. Bills } 274e85d6b16SJason M. Bills 27516428a1aSJason M. Bills // Get the entry timestamp 27616428a1aSJason M. Bills uint64_t curTs = 0; 27716428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 27816428a1aSJason M. Bills if (ret < 0) 27916428a1aSJason M. Bills { 28016428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 28116428a1aSJason M. Bills << strerror(-ret); 28216428a1aSJason M. Bills return false; 28316428a1aSJason M. Bills } 28416428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 28516428a1aSJason M. Bills if (curTs == prevTs) 28616428a1aSJason M. Bills { 28716428a1aSJason M. Bills index++; 28816428a1aSJason M. Bills } 28916428a1aSJason M. Bills else 29016428a1aSJason M. Bills { 29116428a1aSJason M. Bills // Otherwise, reset it 29216428a1aSJason M. Bills index = 0; 29316428a1aSJason M. Bills } 29416428a1aSJason M. Bills // Save the timestamp 29516428a1aSJason M. Bills prevTs = curTs; 29616428a1aSJason M. Bills 29716428a1aSJason M. Bills entryID = std::to_string(curTs); 29816428a1aSJason M. Bills if (index > 0) 29916428a1aSJason M. Bills { 30016428a1aSJason M. Bills entryID += "_" + std::to_string(index); 30116428a1aSJason M. Bills } 30216428a1aSJason M. Bills return true; 30316428a1aSJason M. Bills } 30416428a1aSJason M. Bills 305e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID, 306e85d6b16SJason M. Bills const bool firstEntry = true) 30795820184SJason M. Bills { 308271584abSEd Tanous static time_t prevTs = 0; 30995820184SJason M. Bills static int index = 0; 310e85d6b16SJason M. Bills if (firstEntry) 311e85d6b16SJason M. Bills { 312e85d6b16SJason M. Bills prevTs = 0; 313e85d6b16SJason M. Bills } 314e85d6b16SJason M. Bills 31595820184SJason M. Bills // Get the entry timestamp 316271584abSEd Tanous std::time_t curTs = 0; 31795820184SJason M. Bills std::tm timeStruct = {}; 31895820184SJason M. Bills std::istringstream entryStream(logEntry); 31995820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 32095820184SJason M. Bills { 32195820184SJason M. Bills curTs = std::mktime(&timeStruct); 32295820184SJason M. Bills } 32395820184SJason M. Bills // If the timestamp isn't unique, increment the index 32495820184SJason M. Bills if (curTs == prevTs) 32595820184SJason M. Bills { 32695820184SJason M. Bills index++; 32795820184SJason M. Bills } 32895820184SJason M. Bills else 32995820184SJason M. Bills { 33095820184SJason M. Bills // Otherwise, reset it 33195820184SJason M. Bills index = 0; 33295820184SJason M. Bills } 33395820184SJason M. Bills // Save the timestamp 33495820184SJason M. Bills prevTs = curTs; 33595820184SJason M. Bills 33695820184SJason M. Bills entryID = std::to_string(curTs); 33795820184SJason M. Bills if (index > 0) 33895820184SJason M. Bills { 33995820184SJason M. Bills entryID += "_" + std::to_string(index); 34095820184SJason M. Bills } 34195820184SJason M. Bills return true; 34295820184SJason M. Bills } 34395820184SJason M. Bills 34416428a1aSJason M. Bills static bool getTimestampFromID(crow::Response& res, const std::string& entryID, 345271584abSEd Tanous uint64_t& timestamp, uint64_t& index) 34616428a1aSJason M. Bills { 34716428a1aSJason M. Bills if (entryID.empty()) 34816428a1aSJason M. Bills { 34916428a1aSJason M. Bills return false; 35016428a1aSJason M. Bills } 35116428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 35239e77504SEd Tanous std::string_view tsStr(entryID); 35316428a1aSJason M. Bills 35416428a1aSJason M. Bills auto underscorePos = tsStr.find("_"); 35516428a1aSJason M. Bills if (underscorePos != tsStr.npos) 35616428a1aSJason M. Bills { 35716428a1aSJason M. Bills // Timestamp has an index 35816428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 35939e77504SEd Tanous std::string_view indexStr(entryID); 36016428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 36116428a1aSJason M. Bills std::size_t pos; 36216428a1aSJason M. Bills try 36316428a1aSJason M. Bills { 36439e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 36516428a1aSJason M. Bills } 366271584abSEd Tanous catch (std::invalid_argument&) 36716428a1aSJason M. Bills { 36816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 36916428a1aSJason M. Bills return false; 37016428a1aSJason M. Bills } 371271584abSEd Tanous catch (std::out_of_range&) 37216428a1aSJason M. Bills { 37316428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37416428a1aSJason M. Bills return false; 37516428a1aSJason M. Bills } 37616428a1aSJason M. Bills if (pos != indexStr.size()) 37716428a1aSJason M. Bills { 37816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37916428a1aSJason M. Bills return false; 38016428a1aSJason M. Bills } 38116428a1aSJason M. Bills } 38216428a1aSJason M. Bills // Timestamp has no index 38316428a1aSJason M. Bills std::size_t pos; 38416428a1aSJason M. Bills try 38516428a1aSJason M. Bills { 38639e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 38716428a1aSJason M. Bills } 388271584abSEd Tanous catch (std::invalid_argument&) 38916428a1aSJason M. Bills { 39016428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 39116428a1aSJason M. Bills return false; 39216428a1aSJason M. Bills } 393271584abSEd Tanous catch (std::out_of_range&) 39416428a1aSJason M. Bills { 39516428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 39616428a1aSJason M. Bills return false; 39716428a1aSJason M. Bills } 39816428a1aSJason M. Bills if (pos != tsStr.size()) 39916428a1aSJason M. Bills { 40016428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 40116428a1aSJason M. Bills return false; 40216428a1aSJason M. Bills } 40316428a1aSJason M. Bills return true; 40416428a1aSJason M. Bills } 40516428a1aSJason M. Bills 40695820184SJason M. Bills static bool 40795820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles) 40895820184SJason M. Bills { 40995820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 41095820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 41195820184SJason M. Bills 41295820184SJason M. Bills // Loop through the directory looking for redfish log files 41395820184SJason M. Bills for (const std::filesystem::directory_entry& dirEnt : 41495820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 41595820184SJason M. Bills { 41695820184SJason M. Bills // If we find a redfish log file, save the path 41795820184SJason M. Bills std::string filename = dirEnt.path().filename(); 41895820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 41995820184SJason M. Bills { 42095820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 42195820184SJason M. Bills } 42295820184SJason M. Bills } 42395820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 42495820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 42595820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 42695820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 42795820184SJason M. Bills 42895820184SJason M. Bills return !redfishLogFiles.empty(); 42995820184SJason M. Bills } 43095820184SJason M. Bills 431*5cb1dd27SAsmitha Karunanithi inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp, 432*5cb1dd27SAsmitha Karunanithi const std::string& dumpType) 433*5cb1dd27SAsmitha Karunanithi { 434*5cb1dd27SAsmitha Karunanithi std::string dumpPath; 435*5cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 436*5cb1dd27SAsmitha Karunanithi { 437*5cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 438*5cb1dd27SAsmitha Karunanithi } 439*5cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 440*5cb1dd27SAsmitha Karunanithi { 441*5cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 442*5cb1dd27SAsmitha Karunanithi } 443*5cb1dd27SAsmitha Karunanithi else 444*5cb1dd27SAsmitha Karunanithi { 445*5cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 446*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 447*5cb1dd27SAsmitha Karunanithi return; 448*5cb1dd27SAsmitha Karunanithi } 449*5cb1dd27SAsmitha Karunanithi 450*5cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 451*5cb1dd27SAsmitha Karunanithi [asyncResp, dumpPath, dumpType](const boost::system::error_code ec, 452*5cb1dd27SAsmitha Karunanithi GetManagedObjectsType& resp) { 453*5cb1dd27SAsmitha Karunanithi if (ec) 454*5cb1dd27SAsmitha Karunanithi { 455*5cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 456*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 457*5cb1dd27SAsmitha Karunanithi return; 458*5cb1dd27SAsmitha Karunanithi } 459*5cb1dd27SAsmitha Karunanithi 460*5cb1dd27SAsmitha Karunanithi nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"]; 461*5cb1dd27SAsmitha Karunanithi entriesArray = nlohmann::json::array(); 462*5cb1dd27SAsmitha Karunanithi 463*5cb1dd27SAsmitha Karunanithi for (auto& object : resp) 464*5cb1dd27SAsmitha Karunanithi { 465*5cb1dd27SAsmitha Karunanithi bool foundDumpEntry = false; 466*5cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 467*5cb1dd27SAsmitha Karunanithi { 468*5cb1dd27SAsmitha Karunanithi if (interfaceMap.first == 469*5cb1dd27SAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 470*5cb1dd27SAsmitha Karunanithi { 471*5cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 472*5cb1dd27SAsmitha Karunanithi break; 473*5cb1dd27SAsmitha Karunanithi } 474*5cb1dd27SAsmitha Karunanithi } 475*5cb1dd27SAsmitha Karunanithi 476*5cb1dd27SAsmitha Karunanithi if (foundDumpEntry == false) 477*5cb1dd27SAsmitha Karunanithi { 478*5cb1dd27SAsmitha Karunanithi continue; 479*5cb1dd27SAsmitha Karunanithi } 480*5cb1dd27SAsmitha Karunanithi std::time_t timestamp; 481*5cb1dd27SAsmitha Karunanithi uint64_t size = 0; 482*5cb1dd27SAsmitha Karunanithi entriesArray.push_back({}); 483*5cb1dd27SAsmitha Karunanithi nlohmann::json& thisEntry = entriesArray.back(); 484*5cb1dd27SAsmitha Karunanithi const std::string& path = 485*5cb1dd27SAsmitha Karunanithi static_cast<const std::string&>(object.first); 486*5cb1dd27SAsmitha Karunanithi std::size_t lastPos = path.rfind("/"); 487*5cb1dd27SAsmitha Karunanithi if (lastPos == std::string::npos) 488*5cb1dd27SAsmitha Karunanithi { 489*5cb1dd27SAsmitha Karunanithi continue; 490*5cb1dd27SAsmitha Karunanithi } 491*5cb1dd27SAsmitha Karunanithi std::string entryID = path.substr(lastPos + 1); 492*5cb1dd27SAsmitha Karunanithi 493*5cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : object.second) 494*5cb1dd27SAsmitha Karunanithi { 495*5cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 496*5cb1dd27SAsmitha Karunanithi { 497*5cb1dd27SAsmitha Karunanithi 498*5cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 499*5cb1dd27SAsmitha Karunanithi { 500*5cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 501*5cb1dd27SAsmitha Karunanithi { 502*5cb1dd27SAsmitha Karunanithi auto sizePtr = 503*5cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 504*5cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 505*5cb1dd27SAsmitha Karunanithi { 506*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 507*5cb1dd27SAsmitha Karunanithi break; 508*5cb1dd27SAsmitha Karunanithi } 509*5cb1dd27SAsmitha Karunanithi size = *sizePtr; 510*5cb1dd27SAsmitha Karunanithi break; 511*5cb1dd27SAsmitha Karunanithi } 512*5cb1dd27SAsmitha Karunanithi } 513*5cb1dd27SAsmitha Karunanithi } 514*5cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 515*5cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 516*5cb1dd27SAsmitha Karunanithi { 517*5cb1dd27SAsmitha Karunanithi 518*5cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 519*5cb1dd27SAsmitha Karunanithi { 520*5cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 521*5cb1dd27SAsmitha Karunanithi { 522*5cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 523*5cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 524*5cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 525*5cb1dd27SAsmitha Karunanithi { 526*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 527*5cb1dd27SAsmitha Karunanithi break; 528*5cb1dd27SAsmitha Karunanithi } 529*5cb1dd27SAsmitha Karunanithi timestamp = 530*5cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 531*5cb1dd27SAsmitha Karunanithi break; 532*5cb1dd27SAsmitha Karunanithi } 533*5cb1dd27SAsmitha Karunanithi } 534*5cb1dd27SAsmitha Karunanithi } 535*5cb1dd27SAsmitha Karunanithi } 536*5cb1dd27SAsmitha Karunanithi 537*5cb1dd27SAsmitha Karunanithi thisEntry["@odata.type"] = "#LogEntry.v1_5_1.LogEntry"; 538*5cb1dd27SAsmitha Karunanithi thisEntry["@odata.id"] = dumpPath + entryID; 539*5cb1dd27SAsmitha Karunanithi thisEntry["Id"] = entryID; 540*5cb1dd27SAsmitha Karunanithi thisEntry["EntryType"] = "Event"; 541*5cb1dd27SAsmitha Karunanithi thisEntry["Created"] = crow::utility::getDateTime(timestamp); 542*5cb1dd27SAsmitha Karunanithi thisEntry["Name"] = dumpType + " Dump Entry"; 543*5cb1dd27SAsmitha Karunanithi 544*5cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["@odata.type"] = 545*5cb1dd27SAsmitha Karunanithi "#OemLogEntry.v1_0_0.OpenBmc"; 546*5cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = size; 547*5cb1dd27SAsmitha Karunanithi 548*5cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 549*5cb1dd27SAsmitha Karunanithi { 550*5cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = 551*5cb1dd27SAsmitha Karunanithi "Manager"; 552*5cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] = 553*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 554*5cb1dd27SAsmitha Karunanithi "attachment/" + 555*5cb1dd27SAsmitha Karunanithi entryID; 556*5cb1dd27SAsmitha Karunanithi } 557*5cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 558*5cb1dd27SAsmitha Karunanithi { 559*5cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = "OEM"; 560*5cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] = 561*5cb1dd27SAsmitha Karunanithi "System"; 562*5cb1dd27SAsmitha Karunanithi thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] = 563*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 564*5cb1dd27SAsmitha Karunanithi "attachment/" + 565*5cb1dd27SAsmitha Karunanithi entryID; 566*5cb1dd27SAsmitha Karunanithi } 567*5cb1dd27SAsmitha Karunanithi } 568*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Members@odata.count"] = 569*5cb1dd27SAsmitha Karunanithi entriesArray.size(); 570*5cb1dd27SAsmitha Karunanithi }, 571*5cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 572*5cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 573*5cb1dd27SAsmitha Karunanithi } 574*5cb1dd27SAsmitha Karunanithi 575*5cb1dd27SAsmitha Karunanithi inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp, 576*5cb1dd27SAsmitha Karunanithi const std::string& entryID, 577*5cb1dd27SAsmitha Karunanithi const std::string& dumpType) 578*5cb1dd27SAsmitha Karunanithi { 579*5cb1dd27SAsmitha Karunanithi std::string dumpPath; 580*5cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 581*5cb1dd27SAsmitha Karunanithi { 582*5cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/"; 583*5cb1dd27SAsmitha Karunanithi } 584*5cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 585*5cb1dd27SAsmitha Karunanithi { 586*5cb1dd27SAsmitha Karunanithi dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/"; 587*5cb1dd27SAsmitha Karunanithi } 588*5cb1dd27SAsmitha Karunanithi else 589*5cb1dd27SAsmitha Karunanithi { 590*5cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType; 591*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 592*5cb1dd27SAsmitha Karunanithi return; 593*5cb1dd27SAsmitha Karunanithi } 594*5cb1dd27SAsmitha Karunanithi 595*5cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 596*5cb1dd27SAsmitha Karunanithi [asyncResp, entryID, dumpPath, dumpType]( 597*5cb1dd27SAsmitha Karunanithi const boost::system::error_code ec, GetManagedObjectsType& resp) { 598*5cb1dd27SAsmitha Karunanithi if (ec) 599*5cb1dd27SAsmitha Karunanithi { 600*5cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec; 601*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 602*5cb1dd27SAsmitha Karunanithi return; 603*5cb1dd27SAsmitha Karunanithi } 604*5cb1dd27SAsmitha Karunanithi 605*5cb1dd27SAsmitha Karunanithi for (auto& objectPath : resp) 606*5cb1dd27SAsmitha Karunanithi { 607*5cb1dd27SAsmitha Karunanithi if (objectPath.first.str.find( 608*5cb1dd27SAsmitha Karunanithi "/xyz/openbmc_project/dump/entry/" + entryID) == 609*5cb1dd27SAsmitha Karunanithi std::string::npos) 610*5cb1dd27SAsmitha Karunanithi { 611*5cb1dd27SAsmitha Karunanithi continue; 612*5cb1dd27SAsmitha Karunanithi } 613*5cb1dd27SAsmitha Karunanithi 614*5cb1dd27SAsmitha Karunanithi bool foundDumpEntry = false; 615*5cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 616*5cb1dd27SAsmitha Karunanithi { 617*5cb1dd27SAsmitha Karunanithi if (interfaceMap.first == 618*5cb1dd27SAsmitha Karunanithi ("xyz.openbmc_project.Dump.Entry." + dumpType)) 619*5cb1dd27SAsmitha Karunanithi { 620*5cb1dd27SAsmitha Karunanithi foundDumpEntry = true; 621*5cb1dd27SAsmitha Karunanithi break; 622*5cb1dd27SAsmitha Karunanithi } 623*5cb1dd27SAsmitha Karunanithi } 624*5cb1dd27SAsmitha Karunanithi if (foundDumpEntry == false) 625*5cb1dd27SAsmitha Karunanithi { 626*5cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Can't find Dump Entry"; 627*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 628*5cb1dd27SAsmitha Karunanithi return; 629*5cb1dd27SAsmitha Karunanithi } 630*5cb1dd27SAsmitha Karunanithi 631*5cb1dd27SAsmitha Karunanithi std::time_t timestamp; 632*5cb1dd27SAsmitha Karunanithi uint64_t size = 0; 633*5cb1dd27SAsmitha Karunanithi 634*5cb1dd27SAsmitha Karunanithi for (auto& interfaceMap : objectPath.second) 635*5cb1dd27SAsmitha Karunanithi { 636*5cb1dd27SAsmitha Karunanithi if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry") 637*5cb1dd27SAsmitha Karunanithi { 638*5cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 639*5cb1dd27SAsmitha Karunanithi { 640*5cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Size") 641*5cb1dd27SAsmitha Karunanithi { 642*5cb1dd27SAsmitha Karunanithi auto sizePtr = 643*5cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 644*5cb1dd27SAsmitha Karunanithi if (sizePtr == nullptr) 645*5cb1dd27SAsmitha Karunanithi { 646*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 647*5cb1dd27SAsmitha Karunanithi break; 648*5cb1dd27SAsmitha Karunanithi } 649*5cb1dd27SAsmitha Karunanithi size = *sizePtr; 650*5cb1dd27SAsmitha Karunanithi break; 651*5cb1dd27SAsmitha Karunanithi } 652*5cb1dd27SAsmitha Karunanithi } 653*5cb1dd27SAsmitha Karunanithi } 654*5cb1dd27SAsmitha Karunanithi else if (interfaceMap.first == 655*5cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Time.EpochTime") 656*5cb1dd27SAsmitha Karunanithi { 657*5cb1dd27SAsmitha Karunanithi for (auto& propertyMap : interfaceMap.second) 658*5cb1dd27SAsmitha Karunanithi { 659*5cb1dd27SAsmitha Karunanithi if (propertyMap.first == "Elapsed") 660*5cb1dd27SAsmitha Karunanithi { 661*5cb1dd27SAsmitha Karunanithi const uint64_t* usecsTimeStamp = 662*5cb1dd27SAsmitha Karunanithi std::get_if<uint64_t>(&propertyMap.second); 663*5cb1dd27SAsmitha Karunanithi if (usecsTimeStamp == nullptr) 664*5cb1dd27SAsmitha Karunanithi { 665*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 666*5cb1dd27SAsmitha Karunanithi break; 667*5cb1dd27SAsmitha Karunanithi } 668*5cb1dd27SAsmitha Karunanithi timestamp = 669*5cb1dd27SAsmitha Karunanithi static_cast<std::time_t>(*usecsTimeStamp); 670*5cb1dd27SAsmitha Karunanithi break; 671*5cb1dd27SAsmitha Karunanithi } 672*5cb1dd27SAsmitha Karunanithi } 673*5cb1dd27SAsmitha Karunanithi } 674*5cb1dd27SAsmitha Karunanithi } 675*5cb1dd27SAsmitha Karunanithi 676*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 677*5cb1dd27SAsmitha Karunanithi "#LogEntry.v1_5_1.LogEntry"; 678*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID; 679*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = entryID; 680*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["EntryType"] = "Event"; 681*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Created"] = 682*5cb1dd27SAsmitha Karunanithi crow::utility::getDateTime(timestamp); 683*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry"; 684*5cb1dd27SAsmitha Karunanithi 685*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = 686*5cb1dd27SAsmitha Karunanithi "#OemLogEntry.v1_0_0.OpenBmc"; 687*5cb1dd27SAsmitha Karunanithi asyncResp->res 688*5cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = 689*5cb1dd27SAsmitha Karunanithi size; 690*5cb1dd27SAsmitha Karunanithi 691*5cb1dd27SAsmitha Karunanithi if (dumpType == "BMC") 692*5cb1dd27SAsmitha Karunanithi { 693*5cb1dd27SAsmitha Karunanithi asyncResp->res 694*5cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] = 695*5cb1dd27SAsmitha Karunanithi "Manager"; 696*5cb1dd27SAsmitha Karunanithi asyncResp->res 697*5cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] = 698*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 699*5cb1dd27SAsmitha Karunanithi "attachment/" + 700*5cb1dd27SAsmitha Karunanithi entryID; 701*5cb1dd27SAsmitha Karunanithi } 702*5cb1dd27SAsmitha Karunanithi else if (dumpType == "System") 703*5cb1dd27SAsmitha Karunanithi { 704*5cb1dd27SAsmitha Karunanithi asyncResp->res 705*5cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] = 706*5cb1dd27SAsmitha Karunanithi "OEM"; 707*5cb1dd27SAsmitha Karunanithi asyncResp->res 708*5cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] = 709*5cb1dd27SAsmitha Karunanithi "System"; 710*5cb1dd27SAsmitha Karunanithi asyncResp->res 711*5cb1dd27SAsmitha Karunanithi .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] = 712*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/" 713*5cb1dd27SAsmitha Karunanithi "attachment/" + 714*5cb1dd27SAsmitha Karunanithi entryID; 715*5cb1dd27SAsmitha Karunanithi } 716*5cb1dd27SAsmitha Karunanithi } 717*5cb1dd27SAsmitha Karunanithi }, 718*5cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 719*5cb1dd27SAsmitha Karunanithi "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 720*5cb1dd27SAsmitha Karunanithi } 721*5cb1dd27SAsmitha Karunanithi 722*5cb1dd27SAsmitha Karunanithi inline void deleteDumpEntry(crow::Response& res, const std::string& entryID) 723*5cb1dd27SAsmitha Karunanithi { 724*5cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 725*5cb1dd27SAsmitha Karunanithi 726*5cb1dd27SAsmitha Karunanithi auto respHandler = [asyncResp](const boost::system::error_code ec) { 727*5cb1dd27SAsmitha Karunanithi BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done"; 728*5cb1dd27SAsmitha Karunanithi if (ec) 729*5cb1dd27SAsmitha Karunanithi { 730*5cb1dd27SAsmitha Karunanithi BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error " 731*5cb1dd27SAsmitha Karunanithi << ec; 732*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 733*5cb1dd27SAsmitha Karunanithi return; 734*5cb1dd27SAsmitha Karunanithi } 735*5cb1dd27SAsmitha Karunanithi }; 736*5cb1dd27SAsmitha Karunanithi crow::connections::systemBus->async_method_call( 737*5cb1dd27SAsmitha Karunanithi respHandler, "xyz.openbmc_project.Dump.Manager", 738*5cb1dd27SAsmitha Karunanithi "/xyz/openbmc_project/dump/entry/" + entryID, 739*5cb1dd27SAsmitha Karunanithi "xyz.openbmc_project.Object.Delete", "Delete"); 740*5cb1dd27SAsmitha Karunanithi } 741*5cb1dd27SAsmitha Karunanithi 742043a0536SJohnathan Mantey static void ParseCrashdumpParameters( 743043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params, 744043a0536SJohnathan Mantey std::string& filename, std::string& timestamp, std::string& logfile) 745043a0536SJohnathan Mantey { 746043a0536SJohnathan Mantey for (auto property : params) 747043a0536SJohnathan Mantey { 748043a0536SJohnathan Mantey if (property.first == "Timestamp") 749043a0536SJohnathan Mantey { 750043a0536SJohnathan Mantey const std::string* value = 7518d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 752043a0536SJohnathan Mantey if (value != nullptr) 753043a0536SJohnathan Mantey { 754043a0536SJohnathan Mantey timestamp = *value; 755043a0536SJohnathan Mantey } 756043a0536SJohnathan Mantey } 757043a0536SJohnathan Mantey else if (property.first == "Filename") 758043a0536SJohnathan Mantey { 759043a0536SJohnathan Mantey const std::string* value = 7608d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 761043a0536SJohnathan Mantey if (value != nullptr) 762043a0536SJohnathan Mantey { 763043a0536SJohnathan Mantey filename = *value; 764043a0536SJohnathan Mantey } 765043a0536SJohnathan Mantey } 766043a0536SJohnathan Mantey else if (property.first == "Log") 767043a0536SJohnathan Mantey { 768043a0536SJohnathan Mantey const std::string* value = 7698d78b7a9SPatrick Williams std::get_if<std::string>(&property.second); 770043a0536SJohnathan Mantey if (value != nullptr) 771043a0536SJohnathan Mantey { 772043a0536SJohnathan Mantey logfile = *value; 773043a0536SJohnathan Mantey } 774043a0536SJohnathan Mantey } 775043a0536SJohnathan Mantey } 776043a0536SJohnathan Mantey } 777043a0536SJohnathan Mantey 778a3316fc6SZhikuiRen constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 779c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node 7801da66f75SEd Tanous { 7811da66f75SEd Tanous public: 7821da66f75SEd Tanous template <typename CrowApp> 783c4bf6374SJason M. Bills SystemLogServiceCollection(CrowApp& app) : 784029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/") 785c4bf6374SJason M. Bills { 786c4bf6374SJason M. Bills entityPrivileges = { 787c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 788c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 789c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 790c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 791c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 792c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 793c4bf6374SJason M. Bills } 794c4bf6374SJason M. Bills 795c4bf6374SJason M. Bills private: 796c4bf6374SJason M. Bills /** 797c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 798c4bf6374SJason M. Bills */ 799c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 800c4bf6374SJason M. Bills const std::vector<std::string>& params) override 801c4bf6374SJason M. Bills { 802c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 803c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 804c4bf6374SJason M. Bills // it has a duplicate entry for members 805c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 806c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 807c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 808029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 809c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 810c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 811c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 812c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 813c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 814029573d4SEd Tanous logServiceArray.push_back( 815029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}}); 816*5cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 817c9bb6861Sraviteja-b logServiceArray.push_back( 818*5cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}}); 819c9bb6861Sraviteja-b #endif 820c9bb6861Sraviteja-b 821d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 822d53dd41fSJason M. Bills logServiceArray.push_back( 823cb92c03bSAndrew Geissler {{"@odata.id", 824424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 825d53dd41fSJason M. Bills #endif 826c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 827c4bf6374SJason M. Bills logServiceArray.size(); 828a3316fc6SZhikuiRen 829a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 830a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 831a3316fc6SZhikuiRen const std::vector<std::string>& subtreePath) { 832a3316fc6SZhikuiRen if (ec) 833a3316fc6SZhikuiRen { 834a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 835a3316fc6SZhikuiRen return; 836a3316fc6SZhikuiRen } 837a3316fc6SZhikuiRen 838a3316fc6SZhikuiRen for (auto& pathStr : subtreePath) 839a3316fc6SZhikuiRen { 840a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 841a3316fc6SZhikuiRen { 842a3316fc6SZhikuiRen nlohmann::json& logServiceArray = 843a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 844a3316fc6SZhikuiRen logServiceArray.push_back( 845a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 846a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 847a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 848a3316fc6SZhikuiRen logServiceArray.size(); 849a3316fc6SZhikuiRen return; 850a3316fc6SZhikuiRen } 851a3316fc6SZhikuiRen } 852a3316fc6SZhikuiRen }, 853a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 854a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 855a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 856a3316fc6SZhikuiRen std::array<const char*, 1>{postCodeIface}); 857c4bf6374SJason M. Bills } 858c4bf6374SJason M. Bills }; 859c4bf6374SJason M. Bills 860c4bf6374SJason M. Bills class EventLogService : public Node 861c4bf6374SJason M. Bills { 862c4bf6374SJason M. Bills public: 863c4bf6374SJason M. Bills template <typename CrowApp> 864c4bf6374SJason M. Bills EventLogService(CrowApp& app) : 865029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 866c4bf6374SJason M. Bills { 867c4bf6374SJason M. Bills entityPrivileges = { 868c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 869c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 870c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 871c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 872c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 873c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 874c4bf6374SJason M. Bills } 875c4bf6374SJason M. Bills 876c4bf6374SJason M. Bills private: 877c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 878c4bf6374SJason M. Bills const std::vector<std::string>& params) override 879c4bf6374SJason M. Bills { 880c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 881c4bf6374SJason M. Bills 882c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 883029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 884c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 885c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 886c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 887c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 888c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 889c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 890c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 891c4bf6374SJason M. Bills {"@odata.id", 892029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 893e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 894e7d6c8b2SGunnar Mills 895e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 896e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 897489640c6SJason M. Bills } 898489640c6SJason M. Bills }; 899489640c6SJason M. Bills 9001f56a3a6STim Lee class JournalEventLogClear : public Node 901489640c6SJason M. Bills { 902489640c6SJason M. Bills public: 9031f56a3a6STim Lee JournalEventLogClear(CrowApp& app) : 904489640c6SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 905489640c6SJason M. Bills "LogService.ClearLog/") 906489640c6SJason M. Bills { 907489640c6SJason M. Bills entityPrivileges = { 908489640c6SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 909489640c6SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 910489640c6SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 911489640c6SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 912489640c6SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 913489640c6SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 914489640c6SJason M. Bills } 915489640c6SJason M. Bills 916489640c6SJason M. Bills private: 917489640c6SJason M. Bills void doPost(crow::Response& res, const crow::Request& req, 918489640c6SJason M. Bills const std::vector<std::string>& params) override 919489640c6SJason M. Bills { 920489640c6SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 921489640c6SJason M. Bills 922489640c6SJason M. Bills // Clear the EventLog by deleting the log files 923489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 924489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 925489640c6SJason M. Bills { 926489640c6SJason M. Bills for (const std::filesystem::path& file : redfishLogFiles) 927489640c6SJason M. Bills { 928489640c6SJason M. Bills std::error_code ec; 929489640c6SJason M. Bills std::filesystem::remove(file, ec); 930489640c6SJason M. Bills } 931489640c6SJason M. Bills } 932489640c6SJason M. Bills 933489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 934489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 935489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 936489640c6SJason M. Bills if (ec) 937489640c6SJason M. Bills { 938489640c6SJason M. Bills BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 939489640c6SJason M. Bills messages::internalError(asyncResp->res); 940489640c6SJason M. Bills return; 941489640c6SJason M. Bills } 942489640c6SJason M. Bills 943489640c6SJason M. Bills messages::success(asyncResp->res); 944489640c6SJason M. Bills }, 945489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 946489640c6SJason M. Bills "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 947489640c6SJason M. Bills "replace"); 948c4bf6374SJason M. Bills } 949c4bf6374SJason M. Bills }; 950c4bf6374SJason M. Bills 95195820184SJason M. Bills static int fillEventLogEntryJson(const std::string& logEntryID, 95295820184SJason M. Bills const std::string logEntry, 95395820184SJason M. Bills nlohmann::json& logEntryJson) 954c4bf6374SJason M. Bills { 95595820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 956cd225da8SJason M. Bills // First get the Timestamp 957cd225da8SJason M. Bills size_t space = logEntry.find_first_of(" "); 958cd225da8SJason M. Bills if (space == std::string::npos) 95995820184SJason M. Bills { 96095820184SJason M. Bills return 1; 96195820184SJason M. Bills } 962cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 963cd225da8SJason M. Bills // Then get the log contents 964cd225da8SJason M. Bills size_t entryStart = logEntry.find_first_not_of(" ", space); 965cd225da8SJason M. Bills if (entryStart == std::string::npos) 966cd225da8SJason M. Bills { 967cd225da8SJason M. Bills return 1; 968cd225da8SJason M. Bills } 969cd225da8SJason M. Bills std::string_view entry(logEntry); 970cd225da8SJason M. Bills entry.remove_prefix(entryStart); 971cd225da8SJason M. Bills // Use split to separate the entry into its fields 972cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 973cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 974cd225da8SJason M. Bills boost::token_compress_on); 975cd225da8SJason M. Bills // We need at least a MessageId to be valid 976cd225da8SJason M. Bills if (logEntryFields.size() < 1) 977cd225da8SJason M. Bills { 978cd225da8SJason M. Bills return 1; 979cd225da8SJason M. Bills } 980cd225da8SJason M. Bills std::string& messageID = logEntryFields[0]; 98195820184SJason M. Bills 9824851d45dSJason M. Bills // Get the Message from the MessageRegistry 9834851d45dSJason M. Bills const message_registries::Message* message = 9844851d45dSJason M. Bills message_registries::getMessage(messageID); 985c4bf6374SJason M. Bills 9864851d45dSJason M. Bills std::string msg; 9874851d45dSJason M. Bills std::string severity; 9884851d45dSJason M. Bills if (message != nullptr) 989c4bf6374SJason M. Bills { 9904851d45dSJason M. Bills msg = message->message; 9914851d45dSJason M. Bills severity = message->severity; 992c4bf6374SJason M. Bills } 993c4bf6374SJason M. Bills 99415a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 99515a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 99615a86ff6SJason M. Bills if (logEntryFields.size() > 1) 99715a86ff6SJason M. Bills { 99815a86ff6SJason M. Bills std::string& messageArgsStart = logEntryFields[1]; 99915a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 100015a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 100115a86ff6SJason M. Bills if (!messageArgsStart.empty()) 100215a86ff6SJason M. Bills { 100315a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 100415a86ff6SJason M. Bills } 100515a86ff6SJason M. Bills 100615a86ff6SJason M. Bills messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize); 1007c4bf6374SJason M. Bills 10084851d45dSJason M. Bills // Fill the MessageArgs into the Message 100995820184SJason M. Bills int i = 0; 101095820184SJason M. Bills for (const std::string& messageArg : messageArgs) 10114851d45dSJason M. Bills { 101295820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 10134851d45dSJason M. Bills size_t argPos = msg.find(argStr); 10144851d45dSJason M. Bills if (argPos != std::string::npos) 10154851d45dSJason M. Bills { 101695820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 10174851d45dSJason M. Bills } 10184851d45dSJason M. Bills } 101915a86ff6SJason M. Bills } 10204851d45dSJason M. Bills 102195820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 102295820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 102395820184SJason M. Bills // between the '.' and the '+', so just remove them. 102495820184SJason M. Bills std::size_t dot = timestamp.find_first_of("."); 102595820184SJason M. Bills std::size_t plus = timestamp.find_first_of("+"); 102695820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 1027c4bf6374SJason M. Bills { 102895820184SJason M. Bills timestamp.erase(dot, plus - dot); 1029c4bf6374SJason M. Bills } 1030c4bf6374SJason M. Bills 1031c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 103295820184SJason M. Bills logEntryJson = { 1033cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1034029573d4SEd Tanous {"@odata.id", 1035897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 103695820184SJason M. Bills logEntryID}, 1037c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 103895820184SJason M. Bills {"Id", logEntryID}, 103995820184SJason M. Bills {"Message", std::move(msg)}, 104095820184SJason M. Bills {"MessageId", std::move(messageID)}, 1041c4bf6374SJason M. Bills {"MessageArgs", std::move(messageArgs)}, 1042c4bf6374SJason M. Bills {"EntryType", "Event"}, 104395820184SJason M. Bills {"Severity", std::move(severity)}, 104495820184SJason M. Bills {"Created", std::move(timestamp)}}; 1045c4bf6374SJason M. Bills return 0; 1046c4bf6374SJason M. Bills } 1047c4bf6374SJason M. Bills 104827062605SAnthony Wilson class JournalEventLogEntryCollection : public Node 1049c4bf6374SJason M. Bills { 1050c4bf6374SJason M. Bills public: 1051c4bf6374SJason M. Bills template <typename CrowApp> 105227062605SAnthony Wilson JournalEventLogEntryCollection(CrowApp& app) : 1053029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 1054c4bf6374SJason M. Bills { 1055c4bf6374SJason M. Bills entityPrivileges = { 1056c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1057c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1058c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1059c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1060c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1061c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1062c4bf6374SJason M. Bills } 1063c4bf6374SJason M. Bills 1064c4bf6374SJason M. Bills private: 1065c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1066c4bf6374SJason M. Bills const std::vector<std::string>& params) override 1067c4bf6374SJason M. Bills { 1068c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1069271584abSEd Tanous uint64_t skip = 0; 1070271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 1071c4bf6374SJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1072c4bf6374SJason M. Bills { 1073c4bf6374SJason M. Bills return; 1074c4bf6374SJason M. Bills } 1075c4bf6374SJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1076c4bf6374SJason M. Bills { 1077c4bf6374SJason M. Bills return; 1078c4bf6374SJason M. Bills } 1079c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 1080c4bf6374SJason M. Bills // it has a duplicate entry for members 1081c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1082c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 1083c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1084029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 1085c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 1086c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 1087c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 1088cb92c03bSAndrew Geissler 1089c4bf6374SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1090c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 109195820184SJason M. Bills // Go through the log files and create a unique ID for each entry 109295820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 109395820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 1094b01bf299SEd Tanous uint64_t entryCount = 0; 1095cd225da8SJason M. Bills std::string logEntry; 109695820184SJason M. Bills 109795820184SJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1098cd225da8SJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1099cd225da8SJason M. Bills it++) 1100c4bf6374SJason M. Bills { 1101cd225da8SJason M. Bills std::ifstream logStream(*it); 110295820184SJason M. Bills if (!logStream.is_open()) 1103c4bf6374SJason M. Bills { 1104c4bf6374SJason M. Bills continue; 1105c4bf6374SJason M. Bills } 1106c4bf6374SJason M. Bills 1107e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1108e85d6b16SJason M. Bills bool firstEntry = true; 110995820184SJason M. Bills while (std::getline(logStream, logEntry)) 111095820184SJason M. Bills { 1111c4bf6374SJason M. Bills entryCount++; 1112c4bf6374SJason M. Bills // Handle paging using skip (number of entries to skip from the 1113c4bf6374SJason M. Bills // start) and top (number of entries to display) 1114c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1115c4bf6374SJason M. Bills { 1116c4bf6374SJason M. Bills continue; 1117c4bf6374SJason M. Bills } 1118c4bf6374SJason M. Bills 1119c4bf6374SJason M. Bills std::string idStr; 1120e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1121c4bf6374SJason M. Bills { 1122c4bf6374SJason M. Bills continue; 1123c4bf6374SJason M. Bills } 1124c4bf6374SJason M. Bills 1125e85d6b16SJason M. Bills if (firstEntry) 1126e85d6b16SJason M. Bills { 1127e85d6b16SJason M. Bills firstEntry = false; 1128e85d6b16SJason M. Bills } 1129e85d6b16SJason M. Bills 1130c4bf6374SJason M. Bills logEntryArray.push_back({}); 1131c4bf6374SJason M. Bills nlohmann::json& bmcLogEntry = logEntryArray.back(); 113295820184SJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) 1133c4bf6374SJason M. Bills { 1134c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1135c4bf6374SJason M. Bills return; 1136c4bf6374SJason M. Bills } 1137c4bf6374SJason M. Bills } 113895820184SJason M. Bills } 1139c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1140c4bf6374SJason M. Bills if (skip + top < entryCount) 1141c4bf6374SJason M. Bills { 1142c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 114395820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 114495820184SJason M. Bills "Entries?$skip=" + 1145c4bf6374SJason M. Bills std::to_string(skip + top); 1146c4bf6374SJason M. Bills } 114708a4e4b5SAnthony Wilson } 114808a4e4b5SAnthony Wilson }; 114908a4e4b5SAnthony Wilson 1150897967deSJason M. Bills class JournalEventLogEntry : public Node 1151897967deSJason M. Bills { 1152897967deSJason M. Bills public: 1153897967deSJason M. Bills JournalEventLogEntry(CrowApp& app) : 1154897967deSJason M. Bills Node(app, 1155897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1156897967deSJason M. Bills std::string()) 1157897967deSJason M. Bills { 1158897967deSJason M. Bills entityPrivileges = { 1159897967deSJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1160897967deSJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1161897967deSJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1162897967deSJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1163897967deSJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1164897967deSJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1165897967deSJason M. Bills } 1166897967deSJason M. Bills 1167897967deSJason M. Bills private: 1168897967deSJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1169897967deSJason M. Bills const std::vector<std::string>& params) override 1170897967deSJason M. Bills { 1171897967deSJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1172897967deSJason M. Bills if (params.size() != 1) 1173897967deSJason M. Bills { 1174897967deSJason M. Bills messages::internalError(asyncResp->res); 1175897967deSJason M. Bills return; 1176897967deSJason M. Bills } 1177897967deSJason M. Bills const std::string& targetID = params[0]; 1178897967deSJason M. Bills 1179897967deSJason M. Bills // Go through the log files and check the unique ID for each entry to 1180897967deSJason M. Bills // find the target entry 1181897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 1182897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 1183897967deSJason M. Bills std::string logEntry; 1184897967deSJason M. Bills 1185897967deSJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 1186897967deSJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 1187897967deSJason M. Bills it++) 1188897967deSJason M. Bills { 1189897967deSJason M. Bills std::ifstream logStream(*it); 1190897967deSJason M. Bills if (!logStream.is_open()) 1191897967deSJason M. Bills { 1192897967deSJason M. Bills continue; 1193897967deSJason M. Bills } 1194897967deSJason M. Bills 1195897967deSJason M. Bills // Reset the unique ID on the first entry 1196897967deSJason M. Bills bool firstEntry = true; 1197897967deSJason M. Bills while (std::getline(logStream, logEntry)) 1198897967deSJason M. Bills { 1199897967deSJason M. Bills std::string idStr; 1200897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 1201897967deSJason M. Bills { 1202897967deSJason M. Bills continue; 1203897967deSJason M. Bills } 1204897967deSJason M. Bills 1205897967deSJason M. Bills if (firstEntry) 1206897967deSJason M. Bills { 1207897967deSJason M. Bills firstEntry = false; 1208897967deSJason M. Bills } 1209897967deSJason M. Bills 1210897967deSJason M. Bills if (idStr == targetID) 1211897967deSJason M. Bills { 1212897967deSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, 1213897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 1214897967deSJason M. Bills { 1215897967deSJason M. Bills messages::internalError(asyncResp->res); 1216897967deSJason M. Bills return; 1217897967deSJason M. Bills } 1218897967deSJason M. Bills return; 1219897967deSJason M. Bills } 1220897967deSJason M. Bills } 1221897967deSJason M. Bills } 1222897967deSJason M. Bills // Requested ID was not found 1223897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 1224897967deSJason M. Bills } 1225897967deSJason M. Bills }; 1226897967deSJason M. Bills 122708a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node 122808a4e4b5SAnthony Wilson { 122908a4e4b5SAnthony Wilson public: 123008a4e4b5SAnthony Wilson template <typename CrowApp> 123108a4e4b5SAnthony Wilson DBusEventLogEntryCollection(CrowApp& app) : 123208a4e4b5SAnthony Wilson Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 123308a4e4b5SAnthony Wilson { 123408a4e4b5SAnthony Wilson entityPrivileges = { 123508a4e4b5SAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 123608a4e4b5SAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 123708a4e4b5SAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 123808a4e4b5SAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 123908a4e4b5SAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 124008a4e4b5SAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 124108a4e4b5SAnthony Wilson } 124208a4e4b5SAnthony Wilson 124308a4e4b5SAnthony Wilson private: 124408a4e4b5SAnthony Wilson void doGet(crow::Response& res, const crow::Request& req, 124508a4e4b5SAnthony Wilson const std::vector<std::string>& params) override 124608a4e4b5SAnthony Wilson { 124708a4e4b5SAnthony Wilson std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 124808a4e4b5SAnthony Wilson 124908a4e4b5SAnthony Wilson // Collections don't include the static data added by SubRoute because 125008a4e4b5SAnthony Wilson // it has a duplicate entry for members 125108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 125208a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 125308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 125408a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 125508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 125608a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 125708a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 125808a4e4b5SAnthony Wilson 1259cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1260cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1261cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1262cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 1263cb92c03bSAndrew Geissler GetManagedObjectsType& resp) { 1264cb92c03bSAndrew Geissler if (ec) 1265cb92c03bSAndrew Geissler { 1266cb92c03bSAndrew Geissler // TODO Handle for specific error code 1267cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1268cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 1269cb92c03bSAndrew Geissler << ec; 1270cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1271cb92c03bSAndrew Geissler return; 1272cb92c03bSAndrew Geissler } 1273cb92c03bSAndrew Geissler nlohmann::json& entriesArray = 1274cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 1275cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 1276cb92c03bSAndrew Geissler for (auto& objectPath : resp) 1277cb92c03bSAndrew Geissler { 1278cb92c03bSAndrew Geissler for (auto& interfaceMap : objectPath.second) 1279cb92c03bSAndrew Geissler { 1280cb92c03bSAndrew Geissler if (interfaceMap.first != 1281cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry") 1282cb92c03bSAndrew Geissler { 1283cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Bailing early on " 1284cb92c03bSAndrew Geissler << interfaceMap.first; 1285cb92c03bSAndrew Geissler continue; 1286cb92c03bSAndrew Geissler } 1287cb92c03bSAndrew Geissler entriesArray.push_back({}); 1288cb92c03bSAndrew Geissler nlohmann::json& thisEntry = entriesArray.back(); 128966664f25SEd Tanous uint32_t* id = nullptr; 129066664f25SEd Tanous std::time_t timestamp{}; 129166664f25SEd Tanous std::string* severity = nullptr; 129266664f25SEd Tanous std::string* message = nullptr; 1293cb92c03bSAndrew Geissler for (auto& propertyMap : interfaceMap.second) 1294cb92c03bSAndrew Geissler { 1295cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1296cb92c03bSAndrew Geissler { 12978d78b7a9SPatrick Williams id = std::get_if<uint32_t>(&propertyMap.second); 1298cb92c03bSAndrew Geissler if (id == nullptr) 1299cb92c03bSAndrew Geissler { 1300cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1301cb92c03bSAndrew Geissler "Id"); 1302cb92c03bSAndrew Geissler } 1303cb92c03bSAndrew Geissler } 1304cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1305cb92c03bSAndrew Geissler { 1306cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1307cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1308cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1309cb92c03bSAndrew Geissler { 1310cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1311cb92c03bSAndrew Geissler "Timestamp"); 1312271584abSEd Tanous continue; 1313cb92c03bSAndrew Geissler } 1314cb92c03bSAndrew Geissler // Retrieve Created property with format: 1315cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 1316cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 1317cb92c03bSAndrew Geissler *millisTimeStamp); 1318271584abSEd Tanous timestamp = std::chrono::duration_cast< 1319271584abSEd Tanous std::chrono::duration<int>>( 1320271584abSEd Tanous chronoTimeStamp) 1321cb92c03bSAndrew Geissler .count(); 1322cb92c03bSAndrew Geissler } 1323cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1324cb92c03bSAndrew Geissler { 1325cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1326cb92c03bSAndrew Geissler &propertyMap.second); 1327cb92c03bSAndrew Geissler if (severity == nullptr) 1328cb92c03bSAndrew Geissler { 1329cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1330cb92c03bSAndrew Geissler "Severity"); 1331cb92c03bSAndrew Geissler } 1332cb92c03bSAndrew Geissler } 1333cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1334cb92c03bSAndrew Geissler { 1335cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1336cb92c03bSAndrew Geissler &propertyMap.second); 1337cb92c03bSAndrew Geissler if (message == nullptr) 1338cb92c03bSAndrew Geissler { 1339cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1340cb92c03bSAndrew Geissler "Message"); 1341cb92c03bSAndrew Geissler } 1342cb92c03bSAndrew Geissler } 1343cb92c03bSAndrew Geissler } 1344cb92c03bSAndrew Geissler thisEntry = { 1345cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1346cb92c03bSAndrew Geissler {"@odata.id", 1347cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1348cb92c03bSAndrew Geissler "Entries/" + 1349cb92c03bSAndrew Geissler std::to_string(*id)}, 135027062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1351cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1352cb92c03bSAndrew Geissler {"Message", *message}, 1353cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1354cb92c03bSAndrew Geissler {"Severity", 1355cb92c03bSAndrew Geissler translateSeverityDbusToRedfish(*severity)}, 1356cb92c03bSAndrew Geissler {"Created", crow::utility::getDateTime(timestamp)}}; 1357cb92c03bSAndrew Geissler } 1358cb92c03bSAndrew Geissler } 1359cb92c03bSAndrew Geissler std::sort(entriesArray.begin(), entriesArray.end(), 1360cb92c03bSAndrew Geissler [](const nlohmann::json& left, 1361cb92c03bSAndrew Geissler const nlohmann::json& right) { 1362cb92c03bSAndrew Geissler return (left["Id"] <= right["Id"]); 1363cb92c03bSAndrew Geissler }); 1364cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members@odata.count"] = 1365cb92c03bSAndrew Geissler entriesArray.size(); 1366cb92c03bSAndrew Geissler }, 1367cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 1368cb92c03bSAndrew Geissler "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1369c4bf6374SJason M. Bills } 1370c4bf6374SJason M. Bills }; 1371c4bf6374SJason M. Bills 137208a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node 1373c4bf6374SJason M. Bills { 1374c4bf6374SJason M. Bills public: 137508a4e4b5SAnthony Wilson DBusEventLogEntry(CrowApp& app) : 1376c4bf6374SJason M. Bills Node(app, 1377029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1378029573d4SEd Tanous std::string()) 1379c4bf6374SJason M. Bills { 1380c4bf6374SJason M. Bills entityPrivileges = { 1381c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1382c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1383c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1384c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1385c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1386c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1387c4bf6374SJason M. Bills } 1388c4bf6374SJason M. Bills 1389c4bf6374SJason M. Bills private: 1390c4bf6374SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1391c4bf6374SJason M. Bills const std::vector<std::string>& params) override 1392c4bf6374SJason M. Bills { 1393c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1394029573d4SEd Tanous if (params.size() != 1) 1395c4bf6374SJason M. Bills { 1396c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1397c4bf6374SJason M. Bills return; 1398c4bf6374SJason M. Bills } 1399029573d4SEd Tanous const std::string& entryID = params[0]; 1400cb92c03bSAndrew Geissler 1401cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1402cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1403cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1404cb92c03bSAndrew Geissler [asyncResp, entryID](const boost::system::error_code ec, 1405cb92c03bSAndrew Geissler GetManagedPropertyType& resp) { 1406cb92c03bSAndrew Geissler if (ec) 1407cb92c03bSAndrew Geissler { 1408cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1409cb92c03bSAndrew Geissler << "EventLogEntry (DBus) resp_handler got error " << ec; 1410cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1411cb92c03bSAndrew Geissler return; 1412cb92c03bSAndrew Geissler } 141366664f25SEd Tanous uint32_t* id = nullptr; 141466664f25SEd Tanous std::time_t timestamp{}; 141566664f25SEd Tanous std::string* severity = nullptr; 141666664f25SEd Tanous std::string* message = nullptr; 1417cb92c03bSAndrew Geissler for (auto& propertyMap : resp) 1418cb92c03bSAndrew Geissler { 1419cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1420cb92c03bSAndrew Geissler { 1421cb92c03bSAndrew Geissler id = std::get_if<uint32_t>(&propertyMap.second); 1422cb92c03bSAndrew Geissler if (id == nullptr) 1423cb92c03bSAndrew Geissler { 1424cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, "Id"); 1425cb92c03bSAndrew Geissler } 1426cb92c03bSAndrew Geissler } 1427cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1428cb92c03bSAndrew Geissler { 1429cb92c03bSAndrew Geissler const uint64_t* millisTimeStamp = 1430cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1431cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1432cb92c03bSAndrew Geissler { 1433cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1434cb92c03bSAndrew Geissler "Timestamp"); 1435271584abSEd Tanous continue; 1436cb92c03bSAndrew Geissler } 1437cb92c03bSAndrew Geissler // Retrieve Created property with format: 1438cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 1439cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 1440cb92c03bSAndrew Geissler *millisTimeStamp); 1441cb92c03bSAndrew Geissler timestamp = 1442271584abSEd Tanous std::chrono::duration_cast< 1443271584abSEd Tanous std::chrono::duration<int>>(chronoTimeStamp) 1444cb92c03bSAndrew Geissler .count(); 1445cb92c03bSAndrew Geissler } 1446cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1447cb92c03bSAndrew Geissler { 1448cb92c03bSAndrew Geissler severity = 1449cb92c03bSAndrew Geissler std::get_if<std::string>(&propertyMap.second); 1450cb92c03bSAndrew Geissler if (severity == nullptr) 1451cb92c03bSAndrew Geissler { 1452cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1453cb92c03bSAndrew Geissler "Severity"); 1454cb92c03bSAndrew Geissler } 1455cb92c03bSAndrew Geissler } 1456cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1457cb92c03bSAndrew Geissler { 1458cb92c03bSAndrew Geissler message = std::get_if<std::string>(&propertyMap.second); 1459cb92c03bSAndrew Geissler if (message == nullptr) 1460cb92c03bSAndrew Geissler { 1461cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1462cb92c03bSAndrew Geissler "Message"); 1463cb92c03bSAndrew Geissler } 1464cb92c03bSAndrew Geissler } 1465cb92c03bSAndrew Geissler } 1466271584abSEd Tanous if (id == nullptr || message == nullptr || severity == nullptr) 1467271584abSEd Tanous { 1468271584abSEd Tanous return; 1469271584abSEd Tanous } 1470cb92c03bSAndrew Geissler asyncResp->res.jsonValue = { 1471cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1472cb92c03bSAndrew Geissler {"@odata.id", 1473cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1474cb92c03bSAndrew Geissler "Entries/" + 1475cb92c03bSAndrew Geissler std::to_string(*id)}, 147627062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1477cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1478cb92c03bSAndrew Geissler {"Message", *message}, 1479cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1480cb92c03bSAndrew Geissler {"Severity", translateSeverityDbusToRedfish(*severity)}, 148108a4e4b5SAnthony Wilson {"Created", crow::utility::getDateTime(timestamp)}}; 1482cb92c03bSAndrew Geissler }, 1483cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1484cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1485cb92c03bSAndrew Geissler "org.freedesktop.DBus.Properties", "GetAll", 1486cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry"); 1487c4bf6374SJason M. Bills } 1488336e96c6SChicago Duan 1489336e96c6SChicago Duan void doDelete(crow::Response& res, const crow::Request& req, 1490336e96c6SChicago Duan const std::vector<std::string>& params) override 1491336e96c6SChicago Duan { 1492336e96c6SChicago Duan 1493336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1494336e96c6SChicago Duan 1495336e96c6SChicago Duan auto asyncResp = std::make_shared<AsyncResp>(res); 1496336e96c6SChicago Duan 1497336e96c6SChicago Duan if (params.size() != 1) 1498336e96c6SChicago Duan { 1499336e96c6SChicago Duan messages::internalError(asyncResp->res); 1500336e96c6SChicago Duan return; 1501336e96c6SChicago Duan } 1502336e96c6SChicago Duan std::string entryID = params[0]; 1503336e96c6SChicago Duan 1504336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1505336e96c6SChicago Duan 1506336e96c6SChicago Duan // Process response from Logging service. 1507336e96c6SChicago Duan auto respHandler = [asyncResp](const boost::system::error_code ec) { 1508336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1509336e96c6SChicago Duan if (ec) 1510336e96c6SChicago Duan { 1511336e96c6SChicago Duan // TODO Handle for specific error code 1512336e96c6SChicago Duan BMCWEB_LOG_ERROR 1513336e96c6SChicago Duan << "EventLogEntry (DBus) doDelete respHandler got error " 1514336e96c6SChicago Duan << ec; 1515336e96c6SChicago Duan asyncResp->res.result( 1516336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1517336e96c6SChicago Duan return; 1518336e96c6SChicago Duan } 1519336e96c6SChicago Duan 1520336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1521336e96c6SChicago Duan }; 1522336e96c6SChicago Duan 1523336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1524336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1525336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1526336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1527336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 1528336e96c6SChicago Duan } 1529c4bf6374SJason M. Bills }; 1530c4bf6374SJason M. Bills 1531c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node 1532c4bf6374SJason M. Bills { 1533c4bf6374SJason M. Bills public: 1534c4bf6374SJason M. Bills template <typename CrowApp> 1535c4bf6374SJason M. Bills BMCLogServiceCollection(CrowApp& app) : 15364ed77cd5SEd Tanous Node(app, "/redfish/v1/Managers/bmc/LogServices/") 15371da66f75SEd Tanous { 15381da66f75SEd Tanous entityPrivileges = { 1539e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1540e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1541e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1542e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1543e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1544e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 15451da66f75SEd Tanous } 15461da66f75SEd Tanous 15471da66f75SEd Tanous private: 15481da66f75SEd Tanous /** 15491da66f75SEd Tanous * Functions triggers appropriate requests on DBus 15501da66f75SEd Tanous */ 15511da66f75SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 15521da66f75SEd Tanous const std::vector<std::string>& params) override 15531da66f75SEd Tanous { 1554e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 15551da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 15561da66f75SEd Tanous // it has a duplicate entry for members 1557e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 15581da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1559e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1560e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 1561e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 1562e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 15631da66f75SEd Tanous "Collection of LogServices for this Manager"; 1564c4bf6374SJason M. Bills nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"]; 1565c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 1566*5cb1dd27SAsmitha Karunanithi #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG 1567*5cb1dd27SAsmitha Karunanithi logServiceArray.push_back( 1568*5cb1dd27SAsmitha Karunanithi {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}}); 1569*5cb1dd27SAsmitha Karunanithi #endif 1570c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1571c4bf6374SJason M. Bills logServiceArray.push_back( 157208a4e4b5SAnthony Wilson {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1573c4bf6374SJason M. Bills #endif 1574e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1575c4bf6374SJason M. Bills logServiceArray.size(); 15761da66f75SEd Tanous } 15771da66f75SEd Tanous }; 15781da66f75SEd Tanous 1579c4bf6374SJason M. Bills class BMCJournalLogService : public Node 15801da66f75SEd Tanous { 15811da66f75SEd Tanous public: 15821da66f75SEd Tanous template <typename CrowApp> 1583c4bf6374SJason M. Bills BMCJournalLogService(CrowApp& app) : 1584c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1585e1f26343SJason M. Bills { 1586e1f26343SJason M. Bills entityPrivileges = { 1587e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1588e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1589e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1590e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1591e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1592e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1593e1f26343SJason M. Bills } 1594e1f26343SJason M. Bills 1595e1f26343SJason M. Bills private: 1596e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1597e1f26343SJason M. Bills const std::vector<std::string>& params) override 1598e1f26343SJason M. Bills { 1599e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1600e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1601e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 16020f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 16030f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 1604c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 1605c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 1606c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1607e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1608cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1609cd50aa42SJason M. Bills {"@odata.id", 1610086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 1611e1f26343SJason M. Bills } 1612e1f26343SJason M. Bills }; 1613e1f26343SJason M. Bills 1614c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID, 1615e1f26343SJason M. Bills sd_journal* journal, 1616c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntryJson) 1617e1f26343SJason M. Bills { 1618e1f26343SJason M. Bills // Get the Log Entry contents 1619e1f26343SJason M. Bills int ret = 0; 1620e1f26343SJason M. Bills 162139e77504SEd Tanous std::string_view msg; 162216428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1623e1f26343SJason M. Bills if (ret < 0) 1624e1f26343SJason M. Bills { 1625e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1626e1f26343SJason M. Bills return 1; 1627e1f26343SJason M. Bills } 1628e1f26343SJason M. Bills 1629e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1630271584abSEd Tanous long int severity = 8; // Default to an invalid priority 163116428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1632e1f26343SJason M. Bills if (ret < 0) 1633e1f26343SJason M. Bills { 1634e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1635e1f26343SJason M. Bills } 1636e1f26343SJason M. Bills 1637e1f26343SJason M. Bills // Get the Created time from the timestamp 163816428a1aSJason M. Bills std::string entryTimeStr; 163916428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1640e1f26343SJason M. Bills { 164116428a1aSJason M. Bills return 1; 1642e1f26343SJason M. Bills } 1643e1f26343SJason M. Bills 1644e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1645c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1646cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1647c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1648c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1649e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1650c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 165116428a1aSJason M. Bills {"Message", msg}, 1652e1f26343SJason M. Bills {"EntryType", "Oem"}, 1653e1f26343SJason M. Bills {"Severity", 1654b6a61a5eSJason M. Bills severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"}, 1655086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1656e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1657e1f26343SJason M. Bills return 0; 1658e1f26343SJason M. Bills } 1659e1f26343SJason M. Bills 1660c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node 1661e1f26343SJason M. Bills { 1662e1f26343SJason M. Bills public: 1663e1f26343SJason M. Bills template <typename CrowApp> 1664c4bf6374SJason M. Bills BMCJournalLogEntryCollection(CrowApp& app) : 1665c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1666e1f26343SJason M. Bills { 1667e1f26343SJason M. Bills entityPrivileges = { 1668e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1669e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1670e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1671e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1672e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1673e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1674e1f26343SJason M. Bills } 1675e1f26343SJason M. Bills 1676e1f26343SJason M. Bills private: 1677e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1678e1f26343SJason M. Bills const std::vector<std::string>& params) override 1679e1f26343SJason M. Bills { 1680e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1681193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1682271584abSEd Tanous uint64_t skip = 0; 1683271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 168416428a1aSJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1685193ad2faSJason M. Bills { 1686193ad2faSJason M. Bills return; 1687193ad2faSJason M. Bills } 168816428a1aSJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1689193ad2faSJason M. Bills { 1690193ad2faSJason M. Bills return; 1691193ad2faSJason M. Bills } 1692e1f26343SJason M. Bills // Collections don't include the static data added by SubRoute because 1693e1f26343SJason M. Bills // it has a duplicate entry for members 1694e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1695e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 16960f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 16970f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1698e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1699c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1700e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1701e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1702e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 17030f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 17040f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries"; 1705e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 1706e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1707e1f26343SJason M. Bills 1708e1f26343SJason M. Bills // Go through the journal and use the timestamp to create a unique ID 1709e1f26343SJason M. Bills // for each entry 1710e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1711e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1712e1f26343SJason M. Bills if (ret < 0) 1713e1f26343SJason M. Bills { 1714e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1715f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1716e1f26343SJason M. Bills return; 1717e1f26343SJason M. Bills } 1718e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1719e1f26343SJason M. Bills journalTmp, sd_journal_close); 1720e1f26343SJason M. Bills journalTmp = nullptr; 1721b01bf299SEd Tanous uint64_t entryCount = 0; 1722e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1723e85d6b16SJason M. Bills bool firstEntry = true; 1724e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1725e1f26343SJason M. Bills { 1726193ad2faSJason M. Bills entryCount++; 1727193ad2faSJason M. Bills // Handle paging using skip (number of entries to skip from the 1728193ad2faSJason M. Bills // start) and top (number of entries to display) 1729193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1730193ad2faSJason M. Bills { 1731193ad2faSJason M. Bills continue; 1732193ad2faSJason M. Bills } 1733193ad2faSJason M. Bills 173416428a1aSJason M. Bills std::string idStr; 1735e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1736e1f26343SJason M. Bills { 1737e1f26343SJason M. Bills continue; 1738e1f26343SJason M. Bills } 1739e1f26343SJason M. Bills 1740e85d6b16SJason M. Bills if (firstEntry) 1741e85d6b16SJason M. Bills { 1742e85d6b16SJason M. Bills firstEntry = false; 1743e85d6b16SJason M. Bills } 1744e85d6b16SJason M. Bills 1745e1f26343SJason M. Bills logEntryArray.push_back({}); 1746c4bf6374SJason M. Bills nlohmann::json& bmcJournalLogEntry = logEntryArray.back(); 1747c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1748c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1749e1f26343SJason M. Bills { 1750f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1751e1f26343SJason M. Bills return; 1752e1f26343SJason M. Bills } 1753e1f26343SJason M. Bills } 1754193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1755193ad2faSJason M. Bills if (skip + top < entryCount) 1756193ad2faSJason M. Bills { 1757193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 1758c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 1759193ad2faSJason M. Bills std::to_string(skip + top); 1760193ad2faSJason M. Bills } 1761e1f26343SJason M. Bills } 1762e1f26343SJason M. Bills }; 1763e1f26343SJason M. Bills 1764c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node 1765e1f26343SJason M. Bills { 1766e1f26343SJason M. Bills public: 1767c4bf6374SJason M. Bills BMCJournalLogEntry(CrowApp& app) : 1768c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/", 1769e1f26343SJason M. Bills std::string()) 1770e1f26343SJason M. Bills { 1771e1f26343SJason M. Bills entityPrivileges = { 1772e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1773e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1774e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1775e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1776e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1777e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1778e1f26343SJason M. Bills } 1779e1f26343SJason M. Bills 1780e1f26343SJason M. Bills private: 1781e1f26343SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 1782e1f26343SJason M. Bills const std::vector<std::string>& params) override 1783e1f26343SJason M. Bills { 1784e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1785e1f26343SJason M. Bills if (params.size() != 1) 1786e1f26343SJason M. Bills { 1787f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1788e1f26343SJason M. Bills return; 1789e1f26343SJason M. Bills } 179016428a1aSJason M. Bills const std::string& entryID = params[0]; 1791e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1792e1f26343SJason M. Bills uint64_t ts = 0; 1793271584abSEd Tanous uint64_t index = 0; 179416428a1aSJason M. Bills if (!getTimestampFromID(asyncResp->res, entryID, ts, index)) 1795e1f26343SJason M. Bills { 179616428a1aSJason M. Bills return; 1797e1f26343SJason M. Bills } 1798e1f26343SJason M. Bills 1799e1f26343SJason M. Bills sd_journal* journalTmp = nullptr; 1800e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1801e1f26343SJason M. Bills if (ret < 0) 1802e1f26343SJason M. Bills { 1803e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1804f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1805e1f26343SJason M. Bills return; 1806e1f26343SJason M. Bills } 1807e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1808e1f26343SJason M. Bills journalTmp, sd_journal_close); 1809e1f26343SJason M. Bills journalTmp = nullptr; 1810e1f26343SJason M. Bills // Go to the timestamp in the log and move to the entry at the index 1811af07e3f5SJason M. Bills // tracking the unique ID 1812af07e3f5SJason M. Bills std::string idStr; 1813af07e3f5SJason M. Bills bool firstEntry = true; 1814e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 18152056b6d1SManojkiran Eda if (ret < 0) 18162056b6d1SManojkiran Eda { 18172056b6d1SManojkiran Eda BMCWEB_LOG_ERROR << "failed to seek to an entry in journal" 18182056b6d1SManojkiran Eda << strerror(-ret); 18192056b6d1SManojkiran Eda messages::internalError(asyncResp->res); 18202056b6d1SManojkiran Eda return; 18212056b6d1SManojkiran Eda } 1822271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 1823e1f26343SJason M. Bills { 1824e1f26343SJason M. Bills sd_journal_next(journal.get()); 1825af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1826af07e3f5SJason M. Bills { 1827af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 1828af07e3f5SJason M. Bills return; 1829af07e3f5SJason M. Bills } 1830af07e3f5SJason M. Bills if (firstEntry) 1831af07e3f5SJason M. Bills { 1832af07e3f5SJason M. Bills firstEntry = false; 1833af07e3f5SJason M. Bills } 1834e1f26343SJason M. Bills } 1835c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 1836af07e3f5SJason M. Bills if (idStr != entryID) 1837c4bf6374SJason M. Bills { 1838c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 1839c4bf6374SJason M. Bills return; 1840c4bf6374SJason M. Bills } 1841c4bf6374SJason M. Bills 1842c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 1843e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 1844e1f26343SJason M. Bills { 1845f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1846e1f26343SJason M. Bills return; 1847e1f26343SJason M. Bills } 1848e1f26343SJason M. Bills } 1849e1f26343SJason M. Bills }; 1850e1f26343SJason M. Bills 1851*5cb1dd27SAsmitha Karunanithi class BMCDumpService : public Node 1852c9bb6861Sraviteja-b { 1853c9bb6861Sraviteja-b public: 1854c9bb6861Sraviteja-b template <typename CrowApp> 1855*5cb1dd27SAsmitha Karunanithi BMCDumpService(CrowApp& app) : 1856*5cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/") 1857c9bb6861Sraviteja-b { 1858c9bb6861Sraviteja-b entityPrivileges = { 1859c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 1860c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 1861c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1862c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1863c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1864c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1865c9bb6861Sraviteja-b } 1866c9bb6861Sraviteja-b 1867c9bb6861Sraviteja-b private: 1868c9bb6861Sraviteja-b void doGet(crow::Response& res, const crow::Request& req, 1869c9bb6861Sraviteja-b const std::vector<std::string>& params) override 1870c9bb6861Sraviteja-b { 1871c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1872c9bb6861Sraviteja-b 1873c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 1874*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump"; 1875c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 1876c9bb6861Sraviteja-b "#LogService.v1_1_0.LogService"; 1877c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump LogService"; 1878*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "BMC Dump LogService"; 1879*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 1880c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1881c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 1882*5cb1dd27SAsmitha Karunanithi {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}}; 1883*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 1884*5cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 1885*5cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/" 1886*5cb1dd27SAsmitha Karunanithi "Actions/LogService.ClearLog"}}}, 1887*5cb1dd27SAsmitha Karunanithi {"Oem", 1888*5cb1dd27SAsmitha Karunanithi {{"#OemLogService.CollectDiagnosticData", 1889*5cb1dd27SAsmitha Karunanithi {{"target", 1890*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/" 1891*5cb1dd27SAsmitha Karunanithi "Actions/Oem/OemLogService.CollectDiagnosticData"}}}}}}; 1892c9bb6861Sraviteja-b } 1893c9bb6861Sraviteja-b }; 1894c9bb6861Sraviteja-b 1895*5cb1dd27SAsmitha Karunanithi class BMCDumpEntryCollection : public Node 1896c9bb6861Sraviteja-b { 1897c9bb6861Sraviteja-b public: 1898c9bb6861Sraviteja-b template <typename CrowApp> 1899*5cb1dd27SAsmitha Karunanithi BMCDumpEntryCollection(CrowApp& app) : 1900*5cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/") 1901c9bb6861Sraviteja-b { 1902c9bb6861Sraviteja-b entityPrivileges = { 1903c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 1904c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 1905c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1906c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1907c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1908c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1909c9bb6861Sraviteja-b } 1910c9bb6861Sraviteja-b 1911c9bb6861Sraviteja-b private: 1912c9bb6861Sraviteja-b /** 1913c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 1914c9bb6861Sraviteja-b */ 1915c9bb6861Sraviteja-b void doGet(crow::Response& res, const crow::Request& req, 1916c9bb6861Sraviteja-b const std::vector<std::string>& params) override 1917c9bb6861Sraviteja-b { 1918c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1919c9bb6861Sraviteja-b 1920c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 1921c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 1922c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 1923*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"; 1924*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "BMC Dump Entries"; 1925c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 1926*5cb1dd27SAsmitha Karunanithi "Collection of BMC Dump Entries"; 1927c9bb6861Sraviteja-b 1928*5cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "BMC"); 1929c9bb6861Sraviteja-b } 1930c9bb6861Sraviteja-b }; 1931c9bb6861Sraviteja-b 1932*5cb1dd27SAsmitha Karunanithi class BMCDumpEntry : public Node 1933c9bb6861Sraviteja-b { 1934c9bb6861Sraviteja-b public: 1935*5cb1dd27SAsmitha Karunanithi BMCDumpEntry(CrowApp& app) : 1936*5cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/", 1937c9bb6861Sraviteja-b std::string()) 1938c9bb6861Sraviteja-b { 1939c9bb6861Sraviteja-b entityPrivileges = { 1940c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 1941c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 1942c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1943c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1944c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1945c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1946c9bb6861Sraviteja-b } 1947c9bb6861Sraviteja-b 1948c9bb6861Sraviteja-b private: 1949c9bb6861Sraviteja-b void doGet(crow::Response& res, const crow::Request& req, 1950c9bb6861Sraviteja-b const std::vector<std::string>& params) override 1951c9bb6861Sraviteja-b { 1952c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1953c9bb6861Sraviteja-b if (params.size() != 1) 1954c9bb6861Sraviteja-b { 1955c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 1956c9bb6861Sraviteja-b return; 1957c9bb6861Sraviteja-b } 1958*5cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "BMC"); 1959c9bb6861Sraviteja-b } 1960c9bb6861Sraviteja-b 1961c9bb6861Sraviteja-b void doDelete(crow::Response& res, const crow::Request& req, 1962c9bb6861Sraviteja-b const std::vector<std::string>& params) override 1963c9bb6861Sraviteja-b { 1964*5cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1965c9bb6861Sraviteja-b if (params.size() != 1) 1966c9bb6861Sraviteja-b { 1967c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 1968c9bb6861Sraviteja-b return; 1969c9bb6861Sraviteja-b } 1970*5cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, params[0]); 1971*5cb1dd27SAsmitha Karunanithi } 1972*5cb1dd27SAsmitha Karunanithi }; 1973c9bb6861Sraviteja-b 1974*5cb1dd27SAsmitha Karunanithi class SystemDumpService : public Node 1975c9bb6861Sraviteja-b { 1976*5cb1dd27SAsmitha Karunanithi public: 1977*5cb1dd27SAsmitha Karunanithi template <typename CrowApp> 1978*5cb1dd27SAsmitha Karunanithi SystemDumpService(CrowApp& app) : 1979*5cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/") 1980*5cb1dd27SAsmitha Karunanithi { 1981*5cb1dd27SAsmitha Karunanithi entityPrivileges = { 1982*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 1983*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 1984*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1985*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1986*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1987*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1988*5cb1dd27SAsmitha Karunanithi } 1989*5cb1dd27SAsmitha Karunanithi 1990*5cb1dd27SAsmitha Karunanithi private: 1991*5cb1dd27SAsmitha Karunanithi void doGet(crow::Response& res, const crow::Request& req, 1992*5cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 1993*5cb1dd27SAsmitha Karunanithi { 1994*5cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1995*5cb1dd27SAsmitha Karunanithi 1996*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 1997*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump"; 1998*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 1999*5cb1dd27SAsmitha Karunanithi "#LogService.v1_1_0.LogService"; 2000*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "Dump LogService"; 2001*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = "System Dump LogService"; 2002*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Id"] = "Dump"; 2003*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2004*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Entries"] = { 2005*5cb1dd27SAsmitha Karunanithi {"@odata.id", 2006*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"}}; 2007*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Actions"] = { 2008*5cb1dd27SAsmitha Karunanithi {"#LogService.ClearLog", 2009*5cb1dd27SAsmitha Karunanithi {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/" 2010*5cb1dd27SAsmitha Karunanithi "LogService.ClearLog"}}}, 2011*5cb1dd27SAsmitha Karunanithi {"Oem", 2012*5cb1dd27SAsmitha Karunanithi {{"#OemLogService.CollectDiagnosticData", 2013*5cb1dd27SAsmitha Karunanithi {{"target", 2014*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Actions/Oem/" 2015*5cb1dd27SAsmitha Karunanithi "OemLogService.CollectDiagnosticData"}}}}}}; 2016*5cb1dd27SAsmitha Karunanithi } 2017*5cb1dd27SAsmitha Karunanithi }; 2018*5cb1dd27SAsmitha Karunanithi 2019*5cb1dd27SAsmitha Karunanithi class SystemDumpEntryCollection : public Node 2020*5cb1dd27SAsmitha Karunanithi { 2021*5cb1dd27SAsmitha Karunanithi public: 2022*5cb1dd27SAsmitha Karunanithi template <typename CrowApp> 2023*5cb1dd27SAsmitha Karunanithi SystemDumpEntryCollection(CrowApp& app) : 2024*5cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/") 2025*5cb1dd27SAsmitha Karunanithi { 2026*5cb1dd27SAsmitha Karunanithi entityPrivileges = { 2027*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2028*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2029*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2030*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2031*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2032*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2033*5cb1dd27SAsmitha Karunanithi } 2034*5cb1dd27SAsmitha Karunanithi 2035*5cb1dd27SAsmitha Karunanithi private: 2036*5cb1dd27SAsmitha Karunanithi /** 2037*5cb1dd27SAsmitha Karunanithi * Functions triggers appropriate requests on DBus 2038*5cb1dd27SAsmitha Karunanithi */ 2039*5cb1dd27SAsmitha Karunanithi void doGet(crow::Response& res, const crow::Request& req, 2040*5cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 2041*5cb1dd27SAsmitha Karunanithi { 2042*5cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2043*5cb1dd27SAsmitha Karunanithi 2044*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.type"] = 2045*5cb1dd27SAsmitha Karunanithi "#LogEntryCollection.LogEntryCollection"; 2046*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["@odata.id"] = 2047*5cb1dd27SAsmitha Karunanithi "/redfish/v1/Systems/system/LogServices/Dump/Entries"; 2048*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 2049*5cb1dd27SAsmitha Karunanithi asyncResp->res.jsonValue["Description"] = 2050*5cb1dd27SAsmitha Karunanithi "Collection of System Dump Entries"; 2051*5cb1dd27SAsmitha Karunanithi 2052*5cb1dd27SAsmitha Karunanithi getDumpEntryCollection(asyncResp, "System"); 2053*5cb1dd27SAsmitha Karunanithi } 2054*5cb1dd27SAsmitha Karunanithi }; 2055*5cb1dd27SAsmitha Karunanithi 2056*5cb1dd27SAsmitha Karunanithi class SystemDumpEntry : public Node 2057*5cb1dd27SAsmitha Karunanithi { 2058*5cb1dd27SAsmitha Karunanithi public: 2059*5cb1dd27SAsmitha Karunanithi SystemDumpEntry(CrowApp& app) : 2060*5cb1dd27SAsmitha Karunanithi Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/", 2061*5cb1dd27SAsmitha Karunanithi std::string()) 2062*5cb1dd27SAsmitha Karunanithi { 2063*5cb1dd27SAsmitha Karunanithi entityPrivileges = { 2064*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::get, {{"Login"}}}, 2065*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::head, {{"Login"}}}, 2066*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2067*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2068*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2069*5cb1dd27SAsmitha Karunanithi {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2070*5cb1dd27SAsmitha Karunanithi } 2071*5cb1dd27SAsmitha Karunanithi 2072*5cb1dd27SAsmitha Karunanithi private: 2073*5cb1dd27SAsmitha Karunanithi void doGet(crow::Response& res, const crow::Request& req, 2074*5cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 2075*5cb1dd27SAsmitha Karunanithi { 2076*5cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2077*5cb1dd27SAsmitha Karunanithi if (params.size() != 1) 2078*5cb1dd27SAsmitha Karunanithi { 2079c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 2080c9bb6861Sraviteja-b return; 2081c9bb6861Sraviteja-b } 2082*5cb1dd27SAsmitha Karunanithi getDumpEntryById(asyncResp, params[0], "System"); 2083*5cb1dd27SAsmitha Karunanithi } 2084c9bb6861Sraviteja-b 2085*5cb1dd27SAsmitha Karunanithi void doDelete(crow::Response& res, const crow::Request& req, 2086*5cb1dd27SAsmitha Karunanithi const std::vector<std::string>& params) override 2087c9bb6861Sraviteja-b { 2088*5cb1dd27SAsmitha Karunanithi std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2089*5cb1dd27SAsmitha Karunanithi if (params.size() != 1) 2090c9bb6861Sraviteja-b { 2091*5cb1dd27SAsmitha Karunanithi messages::internalError(asyncResp->res); 2092c9bb6861Sraviteja-b return; 2093c9bb6861Sraviteja-b } 2094*5cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, params[0]); 2095c9bb6861Sraviteja-b } 2096c9bb6861Sraviteja-b }; 2097c9bb6861Sraviteja-b 20980657843aSraviteja-b class SystemDumpEntryDownload : public Node 20990657843aSraviteja-b { 21000657843aSraviteja-b public: 21010657843aSraviteja-b SystemDumpEntryDownload(CrowApp& app) : 21020657843aSraviteja-b Node(app, 21030657843aSraviteja-b "/redfish/v1/Systems/system/LogServices/System/Entries/<str>/" 21040657843aSraviteja-b "Actions/" 21050657843aSraviteja-b "LogEntry.DownloadLog/", 21060657843aSraviteja-b std::string()) 21070657843aSraviteja-b { 21080657843aSraviteja-b entityPrivileges = { 21090657843aSraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 21100657843aSraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 21110657843aSraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 21120657843aSraviteja-b } 21130657843aSraviteja-b 21140657843aSraviteja-b private: 21150657843aSraviteja-b void doPost(crow::Response& res, const crow::Request& req, 21160657843aSraviteja-b const std::vector<std::string>& params) override 21170657843aSraviteja-b { 21180657843aSraviteja-b if (params.size() != 1) 21190657843aSraviteja-b { 21200657843aSraviteja-b messages::internalError(res); 21210657843aSraviteja-b return; 21220657843aSraviteja-b } 21230657843aSraviteja-b const std::string& entryID = params[0]; 21240657843aSraviteja-b crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID); 21250657843aSraviteja-b } 21260657843aSraviteja-b }; 21270657843aSraviteja-b 2128013487e5Sraviteja-b class SystemDumpClear : public Node 2129013487e5Sraviteja-b { 2130013487e5Sraviteja-b public: 2131013487e5Sraviteja-b SystemDumpClear(CrowApp& app) : 2132013487e5Sraviteja-b Node(app, "/redfish/v1/Systems/system/LogServices/System/" 2133013487e5Sraviteja-b "Actions/" 2134013487e5Sraviteja-b "LogService.ClearLog/") 2135013487e5Sraviteja-b { 2136013487e5Sraviteja-b entityPrivileges = { 2137013487e5Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 2138013487e5Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 2139013487e5Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2140013487e5Sraviteja-b } 2141013487e5Sraviteja-b 2142013487e5Sraviteja-b private: 2143013487e5Sraviteja-b void doPost(crow::Response& res, const crow::Request& req, 2144013487e5Sraviteja-b const std::vector<std::string>& params) override 2145013487e5Sraviteja-b { 2146013487e5Sraviteja-b 2147013487e5Sraviteja-b auto asyncResp = std::make_shared<AsyncResp>(res); 2148013487e5Sraviteja-b crow::connections::systemBus->async_method_call( 2149013487e5Sraviteja-b [asyncResp](const boost::system::error_code ec, 2150013487e5Sraviteja-b const std::vector<std::string>& dumpList) { 2151013487e5Sraviteja-b if (ec) 2152013487e5Sraviteja-b { 2153013487e5Sraviteja-b messages::internalError(asyncResp->res); 2154013487e5Sraviteja-b return; 2155013487e5Sraviteja-b } 2156013487e5Sraviteja-b 2157013487e5Sraviteja-b for (const std::string& objectPath : dumpList) 2158013487e5Sraviteja-b { 2159013487e5Sraviteja-b std::size_t pos = objectPath.rfind("/"); 2160013487e5Sraviteja-b if (pos != std::string::npos) 2161013487e5Sraviteja-b { 2162013487e5Sraviteja-b std::string logID = objectPath.substr(pos + 1); 2163*5cb1dd27SAsmitha Karunanithi deleteDumpEntry(asyncResp->res, logID); 2164013487e5Sraviteja-b } 2165013487e5Sraviteja-b } 2166013487e5Sraviteja-b }, 2167013487e5Sraviteja-b "xyz.openbmc_project.ObjectMapper", 2168013487e5Sraviteja-b "/xyz/openbmc_project/object_mapper", 2169013487e5Sraviteja-b "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 2170013487e5Sraviteja-b "/xyz/openbmc_project/dump", 0, 2171013487e5Sraviteja-b std::array<const char*, 1>{ 2172013487e5Sraviteja-b "xyz.openbmc_project.Dump.Entry.System"}); 2173013487e5Sraviteja-b } 2174013487e5Sraviteja-b }; 2175013487e5Sraviteja-b 2176424c4176SJason M. Bills class CrashdumpService : public Node 2177e1f26343SJason M. Bills { 2178e1f26343SJason M. Bills public: 2179e1f26343SJason M. Bills template <typename CrowApp> 2180424c4176SJason M. Bills CrashdumpService(CrowApp& app) : 2181424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 21821da66f75SEd Tanous { 21833946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 21843946028dSAppaRao Puli // method for security reasons. 21851da66f75SEd Tanous entityPrivileges = { 21863946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 21873946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2188e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2189e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2190e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2191e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 21921da66f75SEd Tanous } 21931da66f75SEd Tanous 21941da66f75SEd Tanous private: 21951da66f75SEd Tanous /** 21961da66f75SEd Tanous * Functions triggers appropriate requests on DBus 21971da66f75SEd Tanous */ 21981da66f75SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 21991da66f75SEd Tanous const std::vector<std::string>& params) override 22001da66f75SEd Tanous { 2201e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22021da66f75SEd Tanous // Copy over the static data to include the entries added by SubRoute 22030f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2204424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 2205e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 2206e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 22074f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 22084f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 22094f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 2210e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 2211e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 2212cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 2213cd50aa42SJason M. Bills {"@odata.id", 2214424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 2215e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 22165b61b5e8SJason M. Bills {"#LogService.ClearLog", 22175b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 22185b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 22191da66f75SEd Tanous {"Oem", 2220424c4176SJason M. Bills {{"#Crashdump.OnDemand", 2221424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 22226eda7685SKenny L. Ku "Actions/Oem/Crashdump.OnDemand"}}}, 22236eda7685SKenny L. Ku {"#Crashdump.Telemetry", 22246eda7685SKenny L. Ku {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 22256eda7685SKenny L. Ku "Actions/Oem/Crashdump.Telemetry"}}}}}}; 22261da66f75SEd Tanous 22271da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI 2228e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"]["Oem"].push_back( 2229424c4176SJason M. Bills {"#Crashdump.SendRawPeci", 223008a4e4b5SAnthony Wilson {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 2231424c4176SJason M. Bills "Actions/Oem/Crashdump.SendRawPeci"}}}); 22321da66f75SEd Tanous #endif 22331da66f75SEd Tanous } 22341da66f75SEd Tanous }; 22351da66f75SEd Tanous 22365b61b5e8SJason M. Bills class CrashdumpClear : public Node 22375b61b5e8SJason M. Bills { 22385b61b5e8SJason M. Bills public: 22395b61b5e8SJason M. Bills CrashdumpClear(CrowApp& app) : 22405b61b5e8SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 22415b61b5e8SJason M. Bills "LogService.ClearLog/") 22425b61b5e8SJason M. Bills { 22433946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 22443946028dSAppaRao Puli // method for security reasons. 22455b61b5e8SJason M. Bills entityPrivileges = { 22463946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 22473946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 22485b61b5e8SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 22495b61b5e8SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 22505b61b5e8SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 22515b61b5e8SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 22525b61b5e8SJason M. Bills } 22535b61b5e8SJason M. Bills 22545b61b5e8SJason M. Bills private: 22555b61b5e8SJason M. Bills void doPost(crow::Response& res, const crow::Request& req, 22565b61b5e8SJason M. Bills const std::vector<std::string>& params) override 22575b61b5e8SJason M. Bills { 22585b61b5e8SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22595b61b5e8SJason M. Bills 22605b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 22615b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 22625b61b5e8SJason M. Bills const std::string& resp) { 22635b61b5e8SJason M. Bills if (ec) 22645b61b5e8SJason M. Bills { 22655b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 22665b61b5e8SJason M. Bills return; 22675b61b5e8SJason M. Bills } 22685b61b5e8SJason M. Bills messages::success(asyncResp->res); 22695b61b5e8SJason M. Bills }, 22705b61b5e8SJason M. Bills crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 22715b61b5e8SJason M. Bills } 22725b61b5e8SJason M. Bills }; 22735b61b5e8SJason M. Bills 2274e855dd28SJason M. Bills static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp, 2275e855dd28SJason M. Bills const std::string& logID, 2276e855dd28SJason M. Bills nlohmann::json& logEntryJson) 2277e855dd28SJason M. Bills { 2278043a0536SJohnathan Mantey auto getStoredLogCallback = 2279043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 2280e855dd28SJason M. Bills const boost::system::error_code ec, 2281043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& params) { 2282e855dd28SJason M. Bills if (ec) 2283e855dd28SJason M. Bills { 2284e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 22851ddcf01aSJason M. Bills if (ec.value() == 22861ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 22871ddcf01aSJason M. Bills { 2288043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 2289043a0536SJohnathan Mantey logID); 22901ddcf01aSJason M. Bills } 22911ddcf01aSJason M. Bills else 22921ddcf01aSJason M. Bills { 2293e855dd28SJason M. Bills messages::internalError(asyncResp->res); 22941ddcf01aSJason M. Bills } 2295e855dd28SJason M. Bills return; 2296e855dd28SJason M. Bills } 2297043a0536SJohnathan Mantey 2298043a0536SJohnathan Mantey std::string timestamp{}; 2299043a0536SJohnathan Mantey std::string filename{}; 2300043a0536SJohnathan Mantey std::string logfile{}; 2301043a0536SJohnathan Mantey ParseCrashdumpParameters(params, filename, timestamp, logfile); 2302043a0536SJohnathan Mantey 2303043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 2304e855dd28SJason M. Bills { 2305043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 2306e855dd28SJason M. Bills return; 2307e855dd28SJason M. Bills } 2308e855dd28SJason M. Bills 2309043a0536SJohnathan Mantey std::string crashdumpURI = 2310e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 2311043a0536SJohnathan Mantey logID + "/" + filename; 2312043a0536SJohnathan Mantey logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 2313043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 2314043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 2315e855dd28SJason M. Bills logID}, 2316e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 2317e855dd28SJason M. Bills {"Id", logID}, 2318e855dd28SJason M. Bills {"EntryType", "Oem"}, 2319e855dd28SJason M. Bills {"OemRecordFormat", "Crashdump URI"}, 2320043a0536SJohnathan Mantey {"Message", std::move(crashdumpURI)}, 2321043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2322e855dd28SJason M. Bills }; 2323e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 23245b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 23255b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2326043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2327e855dd28SJason M. Bills } 2328e855dd28SJason M. Bills 2329424c4176SJason M. Bills class CrashdumpEntryCollection : public Node 23301da66f75SEd Tanous { 23311da66f75SEd Tanous public: 23321da66f75SEd Tanous template <typename CrowApp> 2333424c4176SJason M. Bills CrashdumpEntryCollection(CrowApp& app) : 2334424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 23351da66f75SEd Tanous { 23363946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 23373946028dSAppaRao Puli // method for security reasons. 23381da66f75SEd Tanous entityPrivileges = { 23393946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 23403946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2341e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2342e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2343e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2344e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 23451da66f75SEd Tanous } 23461da66f75SEd Tanous 23471da66f75SEd Tanous private: 23481da66f75SEd Tanous /** 23491da66f75SEd Tanous * Functions triggers appropriate requests on DBus 23501da66f75SEd Tanous */ 23511da66f75SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 23521da66f75SEd Tanous const std::vector<std::string>& params) override 23531da66f75SEd Tanous { 2354e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 23551da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 23561da66f75SEd Tanous // it has a duplicate entry for members 2357e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2358e1f26343SJason M. Bills const boost::system::error_code ec, 23591da66f75SEd Tanous const std::vector<std::string>& resp) { 23601da66f75SEd Tanous if (ec) 23611da66f75SEd Tanous { 23621da66f75SEd Tanous if (ec.value() != 23631da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 23641da66f75SEd Tanous { 23651da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 23661da66f75SEd Tanous << ec.message(); 2367f12894f8SJason M. Bills messages::internalError(asyncResp->res); 23681da66f75SEd Tanous return; 23691da66f75SEd Tanous } 23701da66f75SEd Tanous } 2371e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 23721da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 23730f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2374424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2375424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2376e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2377424c4176SJason M. Bills "Collection of Crashdump Entries"; 2378e1f26343SJason M. Bills nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"]; 2379e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2380e855dd28SJason M. Bills std::vector<std::string> logIDs; 2381e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2382e855dd28SJason M. Bills // enough to hold them 23831da66f75SEd Tanous for (const std::string& objpath : resp) 23841da66f75SEd Tanous { 2385e855dd28SJason M. Bills // Get the log ID 23864ed77cd5SEd Tanous std::size_t lastPos = objpath.rfind("/"); 2387e855dd28SJason M. Bills if (lastPos == std::string::npos) 23881da66f75SEd Tanous { 2389e855dd28SJason M. Bills continue; 23901da66f75SEd Tanous } 2391e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2392e855dd28SJason M. Bills 2393e855dd28SJason M. Bills // Add a space for the log entry to the array 2394e855dd28SJason M. Bills logEntryArray.push_back({}); 2395e855dd28SJason M. Bills } 2396e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2397e855dd28SJason M. Bills size_t index = 0; 2398e855dd28SJason M. Bills for (const std::string& logID : logIDs) 2399e855dd28SJason M. Bills { 2400e855dd28SJason M. Bills // Add the log entry to the array 2401e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 24021da66f75SEd Tanous } 2403e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2404e1f26343SJason M. Bills logEntryArray.size(); 24051da66f75SEd Tanous }; 24061da66f75SEd Tanous crow::connections::systemBus->async_method_call( 24071da66f75SEd Tanous std::move(getLogEntriesCallback), 24081da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 24091da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 24101da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 24115b61b5e8SJason M. Bills std::array<const char*, 1>{crashdumpInterface}); 24121da66f75SEd Tanous } 24131da66f75SEd Tanous }; 24141da66f75SEd Tanous 2415424c4176SJason M. Bills class CrashdumpEntry : public Node 24161da66f75SEd Tanous { 24171da66f75SEd Tanous public: 2418424c4176SJason M. Bills CrashdumpEntry(CrowApp& app) : 2419d53dd41fSJason M. Bills Node(app, 2420424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/", 24211da66f75SEd Tanous std::string()) 24221da66f75SEd Tanous { 24233946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24243946028dSAppaRao Puli // method for security reasons. 24251da66f75SEd Tanous entityPrivileges = { 24263946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 24273946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2428e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2429e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2430e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2431e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 24321da66f75SEd Tanous } 24331da66f75SEd Tanous 24341da66f75SEd Tanous private: 24351da66f75SEd Tanous void doGet(crow::Response& res, const crow::Request& req, 24361da66f75SEd Tanous const std::vector<std::string>& params) override 24371da66f75SEd Tanous { 2438e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 24391da66f75SEd Tanous if (params.size() != 1) 24401da66f75SEd Tanous { 2441f12894f8SJason M. Bills messages::internalError(asyncResp->res); 24421da66f75SEd Tanous return; 24431da66f75SEd Tanous } 2444e855dd28SJason M. Bills const std::string& logID = params[0]; 2445e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 2446e855dd28SJason M. Bills } 2447e855dd28SJason M. Bills }; 2448e855dd28SJason M. Bills 2449e855dd28SJason M. Bills class CrashdumpFile : public Node 2450e855dd28SJason M. Bills { 2451e855dd28SJason M. Bills public: 2452e855dd28SJason M. Bills CrashdumpFile(CrowApp& app) : 2453e855dd28SJason M. Bills Node(app, 2454e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/" 2455e855dd28SJason M. Bills "<str>/", 2456e855dd28SJason M. Bills std::string(), std::string()) 2457e855dd28SJason M. Bills { 24583946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 24593946028dSAppaRao Puli // method for security reasons. 2460e855dd28SJason M. Bills entityPrivileges = { 24613946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 24623946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2463e855dd28SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2464e855dd28SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2465e855dd28SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2466e855dd28SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2467e855dd28SJason M. Bills } 2468e855dd28SJason M. Bills 2469e855dd28SJason M. Bills private: 2470e855dd28SJason M. Bills void doGet(crow::Response& res, const crow::Request& req, 2471e855dd28SJason M. Bills const std::vector<std::string>& params) override 2472e855dd28SJason M. Bills { 2473e855dd28SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2474e855dd28SJason M. Bills if (params.size() != 2) 2475e855dd28SJason M. Bills { 2476e855dd28SJason M. Bills messages::internalError(asyncResp->res); 2477e855dd28SJason M. Bills return; 2478e855dd28SJason M. Bills } 2479e855dd28SJason M. Bills const std::string& logID = params[0]; 2480e855dd28SJason M. Bills const std::string& fileName = params[1]; 2481e855dd28SJason M. Bills 2482043a0536SJohnathan Mantey auto getStoredLogCallback = 2483043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2484abf2add6SEd Tanous const boost::system::error_code ec, 2485043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>>& resp) { 24861da66f75SEd Tanous if (ec) 24871da66f75SEd Tanous { 2488043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2489043a0536SJohnathan Mantey << ec.message(); 2490f12894f8SJason M. Bills messages::internalError(asyncResp->res); 24911da66f75SEd Tanous return; 24921da66f75SEd Tanous } 2493e855dd28SJason M. Bills 2494043a0536SJohnathan Mantey std::string dbusFilename{}; 2495043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2496043a0536SJohnathan Mantey std::string dbusFilepath{}; 2497043a0536SJohnathan Mantey 2498043a0536SJohnathan Mantey ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 2499043a0536SJohnathan Mantey dbusFilepath); 2500043a0536SJohnathan Mantey 2501043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2502043a0536SJohnathan Mantey dbusFilepath.empty()) 25031da66f75SEd Tanous { 2504e855dd28SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, fileName); 25051da66f75SEd Tanous return; 25061da66f75SEd Tanous } 2507e855dd28SJason M. Bills 2508043a0536SJohnathan Mantey // Verify the file name parameter is correct 2509043a0536SJohnathan Mantey if (fileName != dbusFilename) 2510043a0536SJohnathan Mantey { 2511043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2512043a0536SJohnathan Mantey return; 2513043a0536SJohnathan Mantey } 2514043a0536SJohnathan Mantey 2515043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2516043a0536SJohnathan Mantey { 2517043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2518043a0536SJohnathan Mantey return; 2519043a0536SJohnathan Mantey } 2520043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2521043a0536SJohnathan Mantey std::ios::binary | 2522043a0536SJohnathan Mantey std::ios::ate); 2523043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2524043a0536SJohnathan Mantey if (fileSize < 0) 2525043a0536SJohnathan Mantey { 2526043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2527043a0536SJohnathan Mantey return; 2528043a0536SJohnathan Mantey } 2529043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2530043a0536SJohnathan Mantey 2531043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2532043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2533043a0536SJohnathan Mantey 2534043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2535043a0536SJohnathan Mantey 2536043a0536SJohnathan Mantey // The cast to std::string is intentional in order to use the 2537043a0536SJohnathan Mantey // assign() that applies move mechanics 2538043a0536SJohnathan Mantey asyncResp->res.body().assign( 2539043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2540043a0536SJohnathan Mantey 2541043a0536SJohnathan Mantey // Configure this to be a file download when accessed from 2542043a0536SJohnathan Mantey // a browser 2543e855dd28SJason M. Bills asyncResp->res.addHeader("Content-Disposition", "attachment"); 25441da66f75SEd Tanous }; 25451da66f75SEd Tanous crow::connections::systemBus->async_method_call( 25465b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 25475b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2548043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 25491da66f75SEd Tanous } 25501da66f75SEd Tanous }; 25511da66f75SEd Tanous 2552424c4176SJason M. Bills class OnDemandCrashdump : public Node 25531da66f75SEd Tanous { 25541da66f75SEd Tanous public: 2555424c4176SJason M. Bills OnDemandCrashdump(CrowApp& app) : 2556424c4176SJason M. Bills Node(app, 2557424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2558424c4176SJason M. Bills "Crashdump.OnDemand/") 25591da66f75SEd Tanous { 25603946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 25613946028dSAppaRao Puli // method for security reasons. 25621da66f75SEd Tanous entityPrivileges = { 25633946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 25643946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 25653946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 25663946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 25673946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 25683946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 25691da66f75SEd Tanous } 25701da66f75SEd Tanous 25711da66f75SEd Tanous private: 25721da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 25731da66f75SEd Tanous const std::vector<std::string>& params) override 25741da66f75SEd Tanous { 2575e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 25761da66f75SEd Tanous 2577fe306728SJames Feist auto generateonDemandLogCallback = [asyncResp, 2578fe306728SJames Feist req](const boost::system::error_code 257946229577SJames Feist ec, 25801da66f75SEd Tanous const std::string& resp) { 25811da66f75SEd Tanous if (ec) 25821da66f75SEd Tanous { 258346229577SJames Feist if (ec.value() == boost::system::errc::operation_not_supported) 25841da66f75SEd Tanous { 2585f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 25861da66f75SEd Tanous } 25874363d3b2SJason M. Bills else if (ec.value() == 25884363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 25894363d3b2SJason M. Bills { 25904363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 25914363d3b2SJason M. Bills "60"); 25924363d3b2SJason M. Bills } 25931da66f75SEd Tanous else 25941da66f75SEd Tanous { 2595f12894f8SJason M. Bills messages::internalError(asyncResp->res); 25961da66f75SEd Tanous } 25971da66f75SEd Tanous return; 25981da66f75SEd Tanous } 259946229577SJames Feist std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 260066afe4faSJames Feist [](boost::system::error_code err, sdbusplus::message::message&, 260166afe4faSJames Feist const std::shared_ptr<task::TaskData>& taskData) { 260266afe4faSJames Feist if (!err) 260366afe4faSJames Feist { 2604e5d5006bSJames Feist taskData->messages.emplace_back( 2605e5d5006bSJames Feist messages::taskCompletedOK( 2606e5d5006bSJames Feist std::to_string(taskData->index))); 2607831d6b09SJames Feist taskData->state = "Completed"; 260866afe4faSJames Feist } 260932898ceaSJames Feist return task::completed; 261066afe4faSJames Feist }, 261146229577SJames Feist "type='signal',interface='org.freedesktop.DBus.Properties'," 261246229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 261346229577SJames Feist "crashdump'"); 261446229577SJames Feist task->startTimer(std::chrono::minutes(5)); 261546229577SJames Feist task->populateResp(asyncResp->res); 2616fe306728SJames Feist task->payload.emplace(req); 26171da66f75SEd Tanous }; 26181da66f75SEd Tanous crow::connections::systemBus->async_method_call( 26195b61b5e8SJason M. Bills std::move(generateonDemandLogCallback), crashdumpObject, 26205b61b5e8SJason M. Bills crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog"); 26211da66f75SEd Tanous } 26221da66f75SEd Tanous }; 26231da66f75SEd Tanous 26246eda7685SKenny L. Ku class TelemetryCrashdump : public Node 26256eda7685SKenny L. Ku { 26266eda7685SKenny L. Ku public: 26276eda7685SKenny L. Ku TelemetryCrashdump(CrowApp& app) : 26286eda7685SKenny L. Ku Node(app, 26296eda7685SKenny L. Ku "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 26306eda7685SKenny L. Ku "Crashdump.Telemetry/") 26316eda7685SKenny L. Ku { 26326eda7685SKenny L. Ku // Note: Deviated from redfish privilege registry for GET & HEAD 26336eda7685SKenny L. Ku // method for security reasons. 26346eda7685SKenny L. Ku entityPrivileges = { 26356eda7685SKenny L. Ku {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 26366eda7685SKenny L. Ku {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 26376eda7685SKenny L. Ku {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 26386eda7685SKenny L. Ku {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 26396eda7685SKenny L. Ku {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 26406eda7685SKenny L. Ku {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 26416eda7685SKenny L. Ku } 26426eda7685SKenny L. Ku 26436eda7685SKenny L. Ku private: 26446eda7685SKenny L. Ku void doPost(crow::Response& res, const crow::Request& req, 26456eda7685SKenny L. Ku const std::vector<std::string>& params) override 26466eda7685SKenny L. Ku { 26476eda7685SKenny L. Ku std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 26486eda7685SKenny L. Ku 26496eda7685SKenny L. Ku auto generateTelemetryLogCallback = [asyncResp, req]( 26506eda7685SKenny L. Ku const boost::system::error_code 26516eda7685SKenny L. Ku ec, 26526eda7685SKenny L. Ku const std::string& resp) { 26536eda7685SKenny L. Ku if (ec) 26546eda7685SKenny L. Ku { 26556eda7685SKenny L. Ku if (ec.value() == boost::system::errc::operation_not_supported) 26566eda7685SKenny L. Ku { 26576eda7685SKenny L. Ku messages::resourceInStandby(asyncResp->res); 26586eda7685SKenny L. Ku } 26596eda7685SKenny L. Ku else if (ec.value() == 26606eda7685SKenny L. Ku boost::system::errc::device_or_resource_busy) 26616eda7685SKenny L. Ku { 26626eda7685SKenny L. Ku messages::serviceTemporarilyUnavailable(asyncResp->res, 26636eda7685SKenny L. Ku "60"); 26646eda7685SKenny L. Ku } 26656eda7685SKenny L. Ku else 26666eda7685SKenny L. Ku { 26676eda7685SKenny L. Ku messages::internalError(asyncResp->res); 26686eda7685SKenny L. Ku } 26696eda7685SKenny L. Ku return; 26706eda7685SKenny L. Ku } 26716eda7685SKenny L. Ku std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 26726eda7685SKenny L. Ku [](boost::system::error_code err, sdbusplus::message::message&, 26736eda7685SKenny L. Ku const std::shared_ptr<task::TaskData>& taskData) { 26746eda7685SKenny L. Ku if (!err) 26756eda7685SKenny L. Ku { 26766eda7685SKenny L. Ku taskData->messages.emplace_back( 26776eda7685SKenny L. Ku messages::taskCompletedOK( 26786eda7685SKenny L. Ku std::to_string(taskData->index))); 26796eda7685SKenny L. Ku taskData->state = "Completed"; 26806eda7685SKenny L. Ku } 26816eda7685SKenny L. Ku return task::completed; 26826eda7685SKenny L. Ku }, 26836eda7685SKenny L. Ku "type='signal',interface='org.freedesktop.DBus.Properties'," 26846eda7685SKenny L. Ku "member='PropertiesChanged',arg0namespace='com.intel." 26856eda7685SKenny L. Ku "crashdump'"); 26866eda7685SKenny L. Ku task->startTimer(std::chrono::minutes(5)); 26876eda7685SKenny L. Ku task->populateResp(asyncResp->res); 26886eda7685SKenny L. Ku task->payload.emplace(req); 26896eda7685SKenny L. Ku }; 26906eda7685SKenny L. Ku crow::connections::systemBus->async_method_call( 26916eda7685SKenny L. Ku std::move(generateTelemetryLogCallback), crashdumpObject, 26926eda7685SKenny L. Ku crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog"); 26936eda7685SKenny L. Ku } 26946eda7685SKenny L. Ku }; 26956eda7685SKenny L. Ku 2696e1f26343SJason M. Bills class SendRawPECI : public Node 26971da66f75SEd Tanous { 26981da66f75SEd Tanous public: 2699e1f26343SJason M. Bills SendRawPECI(CrowApp& app) : 2700424c4176SJason M. Bills Node(app, 2701424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2702424c4176SJason M. Bills "Crashdump.SendRawPeci/") 27031da66f75SEd Tanous { 27043946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 27053946028dSAppaRao Puli // method for security reasons. 27061da66f75SEd Tanous entityPrivileges = { 27071da66f75SEd Tanous {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 27081da66f75SEd Tanous {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 27091da66f75SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 27101da66f75SEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 27111da66f75SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 27121da66f75SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 27131da66f75SEd Tanous } 27141da66f75SEd Tanous 27151da66f75SEd Tanous private: 27161da66f75SEd Tanous void doPost(crow::Response& res, const crow::Request& req, 27171da66f75SEd Tanous const std::vector<std::string>& params) override 27181da66f75SEd Tanous { 2719e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 27208724c297SKarthick Sundarrajan std::vector<std::vector<uint8_t>> peciCommands; 27218724c297SKarthick Sundarrajan 27228724c297SKarthick Sundarrajan nlohmann::json reqJson = 27238724c297SKarthick Sundarrajan nlohmann::json::parse(req.body, nullptr, false); 27248724c297SKarthick Sundarrajan if (reqJson.find("PECICommands") != reqJson.end()) 27258724c297SKarthick Sundarrajan { 27268724c297SKarthick Sundarrajan if (!json_util::readJson(req, res, "PECICommands", peciCommands)) 27278724c297SKarthick Sundarrajan { 27288724c297SKarthick Sundarrajan return; 27298724c297SKarthick Sundarrajan } 27308724c297SKarthick Sundarrajan uint32_t idx = 0; 27318724c297SKarthick Sundarrajan for (auto const& cmd : peciCommands) 27328724c297SKarthick Sundarrajan { 27338724c297SKarthick Sundarrajan if (cmd.size() < 3) 27348724c297SKarthick Sundarrajan { 27358724c297SKarthick Sundarrajan std::string s("["); 27368724c297SKarthick Sundarrajan for (auto const& val : cmd) 27378724c297SKarthick Sundarrajan { 27388724c297SKarthick Sundarrajan if (val != *cmd.begin()) 27398724c297SKarthick Sundarrajan { 27408724c297SKarthick Sundarrajan s += ","; 27418724c297SKarthick Sundarrajan } 27428724c297SKarthick Sundarrajan s += std::to_string(val); 27438724c297SKarthick Sundarrajan } 27448724c297SKarthick Sundarrajan s += "]"; 27458724c297SKarthick Sundarrajan messages::actionParameterValueFormatError( 27468724c297SKarthick Sundarrajan res, s, "PECICommands[" + std::to_string(idx) + "]", 27478724c297SKarthick Sundarrajan "SendRawPeci"); 27488724c297SKarthick Sundarrajan return; 27498724c297SKarthick Sundarrajan } 27508724c297SKarthick Sundarrajan idx++; 27518724c297SKarthick Sundarrajan } 27528724c297SKarthick Sundarrajan } 27538724c297SKarthick Sundarrajan else 27548724c297SKarthick Sundarrajan { 27558724c297SKarthick Sundarrajan /* This interface is deprecated */ 2756b1556427SEd Tanous uint8_t clientAddress = 0; 2757b1556427SEd Tanous uint8_t readLength = 0; 27581da66f75SEd Tanous std::vector<uint8_t> peciCommand; 2759b1556427SEd Tanous if (!json_util::readJson(req, res, "ClientAddress", clientAddress, 2760b1556427SEd Tanous "ReadLength", readLength, "PECICommand", 2761b1556427SEd Tanous peciCommand)) 27621da66f75SEd Tanous { 27631da66f75SEd Tanous return; 27641da66f75SEd Tanous } 27658724c297SKarthick Sundarrajan peciCommands.push_back({clientAddress, 0, readLength}); 27668724c297SKarthick Sundarrajan peciCommands[0].insert(peciCommands[0].end(), peciCommand.begin(), 27678724c297SKarthick Sundarrajan peciCommand.end()); 27688724c297SKarthick Sundarrajan } 27691da66f75SEd Tanous // Callback to return the Raw PECI response 2770e1f26343SJason M. Bills auto sendRawPECICallback = 2771e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 27728724c297SKarthick Sundarrajan const std::vector<std::vector<uint8_t>>& resp) { 27731da66f75SEd Tanous if (ec) 27741da66f75SEd Tanous { 27758724c297SKarthick Sundarrajan BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: " 27761da66f75SEd Tanous << ec.message(); 2777f12894f8SJason M. Bills messages::internalError(asyncResp->res); 27781da66f75SEd Tanous return; 27791da66f75SEd Tanous } 2780e1f26343SJason M. Bills asyncResp->res.jsonValue = {{"Name", "PECI Command Response"}, 27811da66f75SEd Tanous {"PECIResponse", resp}}; 27821da66f75SEd Tanous }; 27831da66f75SEd Tanous // Call the SendRawPECI command with the provided data 27841da66f75SEd Tanous crow::connections::systemBus->async_method_call( 27855b61b5e8SJason M. Bills std::move(sendRawPECICallback), crashdumpObject, crashdumpPath, 27868724c297SKarthick Sundarrajan crashdumpRawPECIInterface, "SendRawPeci", peciCommands); 27871da66f75SEd Tanous } 27881da66f75SEd Tanous }; 27891da66f75SEd Tanous 2790cb92c03bSAndrew Geissler /** 2791cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2792cb92c03bSAndrew Geissler */ 2793cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node 2794cb92c03bSAndrew Geissler { 2795cb92c03bSAndrew Geissler public: 2796cb92c03bSAndrew Geissler DBusLogServiceActionsClear(CrowApp& app) : 2797cb92c03bSAndrew Geissler Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 27987af91514SGunnar Mills "LogService.ClearLog/") 2799cb92c03bSAndrew Geissler { 2800cb92c03bSAndrew Geissler entityPrivileges = { 2801cb92c03bSAndrew Geissler {boost::beast::http::verb::get, {{"Login"}}}, 2802cb92c03bSAndrew Geissler {boost::beast::http::verb::head, {{"Login"}}}, 2803cb92c03bSAndrew Geissler {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2804cb92c03bSAndrew Geissler {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2805cb92c03bSAndrew Geissler {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2806cb92c03bSAndrew Geissler {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2807cb92c03bSAndrew Geissler } 2808cb92c03bSAndrew Geissler 2809cb92c03bSAndrew Geissler private: 2810cb92c03bSAndrew Geissler /** 2811cb92c03bSAndrew Geissler * Function handles POST method request. 2812cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2813cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2814cb92c03bSAndrew Geissler */ 2815cb92c03bSAndrew Geissler void doPost(crow::Response& res, const crow::Request& req, 2816cb92c03bSAndrew Geissler const std::vector<std::string>& params) override 2817cb92c03bSAndrew Geissler { 2818cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2819cb92c03bSAndrew Geissler 2820cb92c03bSAndrew Geissler auto asyncResp = std::make_shared<AsyncResp>(res); 2821cb92c03bSAndrew Geissler // Process response from Logging service. 2822cb92c03bSAndrew Geissler auto resp_handler = [asyncResp](const boost::system::error_code ec) { 2823cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 2824cb92c03bSAndrew Geissler if (ec) 2825cb92c03bSAndrew Geissler { 2826cb92c03bSAndrew Geissler // TODO Handle for specific error code 2827cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 2828cb92c03bSAndrew Geissler asyncResp->res.result( 2829cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2830cb92c03bSAndrew Geissler return; 2831cb92c03bSAndrew Geissler } 2832cb92c03bSAndrew Geissler 2833cb92c03bSAndrew Geissler asyncResp->res.result(boost::beast::http::status::no_content); 2834cb92c03bSAndrew Geissler }; 2835cb92c03bSAndrew Geissler 2836cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2837cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 2838cb92c03bSAndrew Geissler resp_handler, "xyz.openbmc_project.Logging", 2839cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2840cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 2841cb92c03bSAndrew Geissler } 2842cb92c03bSAndrew Geissler }; 2843a3316fc6SZhikuiRen 2844a3316fc6SZhikuiRen /**************************************************** 2845a3316fc6SZhikuiRen * Redfish PostCode interfaces 2846a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2847a3316fc6SZhikuiRen ******************************************************/ 2848a3316fc6SZhikuiRen class PostCodesLogService : public Node 2849a3316fc6SZhikuiRen { 2850a3316fc6SZhikuiRen public: 2851a3316fc6SZhikuiRen PostCodesLogService(CrowApp& app) : 2852a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2853a3316fc6SZhikuiRen { 2854a3316fc6SZhikuiRen entityPrivileges = { 2855a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2856a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2857a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2858a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2859a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2860a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2861a3316fc6SZhikuiRen } 2862a3316fc6SZhikuiRen 2863a3316fc6SZhikuiRen private: 2864a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 2865a3316fc6SZhikuiRen const std::vector<std::string>& params) override 2866a3316fc6SZhikuiRen { 2867a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2868a3316fc6SZhikuiRen 2869a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 2870a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"}, 2871a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 2872a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"}, 2873a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 2874a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 2875a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 2876a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 2877a3316fc6SZhikuiRen {"Entries", 2878a3316fc6SZhikuiRen {{"@odata.id", 2879a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}}; 2880a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 2881a3316fc6SZhikuiRen {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/" 2882a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 2883a3316fc6SZhikuiRen } 2884a3316fc6SZhikuiRen }; 2885a3316fc6SZhikuiRen 2886a3316fc6SZhikuiRen class PostCodesClear : public Node 2887a3316fc6SZhikuiRen { 2888a3316fc6SZhikuiRen public: 2889a3316fc6SZhikuiRen PostCodesClear(CrowApp& app) : 2890a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 2891a3316fc6SZhikuiRen "LogService.ClearLog/") 2892a3316fc6SZhikuiRen { 2893a3316fc6SZhikuiRen entityPrivileges = { 2894a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2895a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 28963946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 28973946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 28983946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 28993946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 2900a3316fc6SZhikuiRen } 2901a3316fc6SZhikuiRen 2902a3316fc6SZhikuiRen private: 2903a3316fc6SZhikuiRen void doPost(crow::Response& res, const crow::Request& req, 2904a3316fc6SZhikuiRen const std::vector<std::string>& params) override 2905a3316fc6SZhikuiRen { 2906a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 2907a3316fc6SZhikuiRen 2908a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2909a3316fc6SZhikuiRen // Make call to post-code service to request clear all 2910a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2911a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 2912a3316fc6SZhikuiRen if (ec) 2913a3316fc6SZhikuiRen { 2914a3316fc6SZhikuiRen // TODO Handle for specific error code 2915a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 2916a3316fc6SZhikuiRen << "doClearPostCodes resp_handler got error " << ec; 2917a3316fc6SZhikuiRen asyncResp->res.result( 2918a3316fc6SZhikuiRen boost::beast::http::status::internal_server_error); 2919a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 2920a3316fc6SZhikuiRen return; 2921a3316fc6SZhikuiRen } 2922a3316fc6SZhikuiRen }, 2923a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2924a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2925a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 2926a3316fc6SZhikuiRen } 2927a3316fc6SZhikuiRen }; 2928a3316fc6SZhikuiRen 2929a3316fc6SZhikuiRen static void fillPostCodeEntry( 2930a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> aResp, 2931a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode, 2932a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 2933a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 2934a3316fc6SZhikuiRen { 2935a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 2936a3316fc6SZhikuiRen const message_registries::Message* message = 2937a3316fc6SZhikuiRen message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode"); 2938a3316fc6SZhikuiRen 2939a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 2940a3316fc6SZhikuiRen nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"]; 2941a3316fc6SZhikuiRen 2942a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 2943a3316fc6SZhikuiRen for (const std::pair<uint64_t, uint64_t>& code : postcode) 2944a3316fc6SZhikuiRen { 2945a3316fc6SZhikuiRen currentCodeIndex++; 2946a3316fc6SZhikuiRen std::string postcodeEntryID = 2947a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 2948a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 2949a3316fc6SZhikuiRen 2950a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 2951a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 2952a3316fc6SZhikuiRen 2953a3316fc6SZhikuiRen if (1 == currentCodeIndex) 2954a3316fc6SZhikuiRen { // already incremented 2955a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 2956a3316fc6SZhikuiRen } 2957a3316fc6SZhikuiRen else 2958a3316fc6SZhikuiRen { 2959a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 2960a3316fc6SZhikuiRen } 2961a3316fc6SZhikuiRen 2962a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 2963a3316fc6SZhikuiRen // not fall between top and skip 2964a3316fc6SZhikuiRen if ((codeIndex == 0) && 2965a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 2966a3316fc6SZhikuiRen { 2967a3316fc6SZhikuiRen continue; 2968a3316fc6SZhikuiRen } 2969a3316fc6SZhikuiRen 29704e0453b1SGunnar Mills // skip if a specific codeIndex is specified and does not match the 2971a3316fc6SZhikuiRen // currentIndex 2972a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 2973a3316fc6SZhikuiRen { 2974a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 2975a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 2976a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 2977a3316fc6SZhikuiRen continue; 2978a3316fc6SZhikuiRen } 2979a3316fc6SZhikuiRen 2980a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 2981a3316fc6SZhikuiRen // index 2982a3316fc6SZhikuiRen 2983a3316fc6SZhikuiRen // Get the Created time from the timestamp 2984a3316fc6SZhikuiRen std::string entryTimeStr; 2985a3316fc6SZhikuiRen if (!getTimestampStr(usecSinceEpoch, entryTimeStr)) 2986a3316fc6SZhikuiRen { 2987a3316fc6SZhikuiRen continue; 2988a3316fc6SZhikuiRen } 2989a3316fc6SZhikuiRen 2990a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 2991a3316fc6SZhikuiRen std::ostringstream hexCode; 2992a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 2993a3316fc6SZhikuiRen << code.second; 2994a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 2995a3316fc6SZhikuiRen // Set Fixed -Point Notation 2996a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 2997a3316fc6SZhikuiRen // Set precision to 4 digits 2998a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 2999a3316fc6SZhikuiRen // Add double to stream 3000a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 3001a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 3002a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 3003a3316fc6SZhikuiRen 3004a3316fc6SZhikuiRen // Get MessageArgs template from message registry 3005a3316fc6SZhikuiRen std::string msg; 3006a3316fc6SZhikuiRen if (message != nullptr) 3007a3316fc6SZhikuiRen { 3008a3316fc6SZhikuiRen msg = message->message; 3009a3316fc6SZhikuiRen 3010a3316fc6SZhikuiRen // fill in this post code value 3011a3316fc6SZhikuiRen int i = 0; 3012a3316fc6SZhikuiRen for (const std::string& messageArg : messageArgs) 3013a3316fc6SZhikuiRen { 3014a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 3015a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 3016a3316fc6SZhikuiRen if (argPos != std::string::npos) 3017a3316fc6SZhikuiRen { 3018a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 3019a3316fc6SZhikuiRen } 3020a3316fc6SZhikuiRen } 3021a3316fc6SZhikuiRen } 3022a3316fc6SZhikuiRen 3023d4342a92STim Lee // Get Severity template from message registry 3024d4342a92STim Lee std::string severity; 3025d4342a92STim Lee if (message != nullptr) 3026d4342a92STim Lee { 3027d4342a92STim Lee severity = message->severity; 3028d4342a92STim Lee } 3029d4342a92STim Lee 3030a3316fc6SZhikuiRen // add to AsyncResp 3031a3316fc6SZhikuiRen logEntryArray.push_back({}); 3032a3316fc6SZhikuiRen nlohmann::json& bmcLogEntry = logEntryArray.back(); 3033a3316fc6SZhikuiRen bmcLogEntry = { 3034a3316fc6SZhikuiRen {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 3035a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 3036a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 3037a3316fc6SZhikuiRen "PostCodes/Entries/" + 3038a3316fc6SZhikuiRen postcodeEntryID}, 3039a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 3040a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 3041a3316fc6SZhikuiRen {"Message", std::move(msg)}, 3042a3316fc6SZhikuiRen {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"}, 3043a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 3044a3316fc6SZhikuiRen {"EntryType", "Event"}, 3045a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 3046a3316fc6SZhikuiRen {"Created", std::move(entryTimeStr)}}; 3047a3316fc6SZhikuiRen } 3048a3316fc6SZhikuiRen } 3049a3316fc6SZhikuiRen 3050a3316fc6SZhikuiRen static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp, 3051a3316fc6SZhikuiRen const uint16_t bootIndex, 3052a3316fc6SZhikuiRen const uint64_t codeIndex) 3053a3316fc6SZhikuiRen { 3054a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3055a3316fc6SZhikuiRen [aResp, bootIndex, codeIndex]( 3056a3316fc6SZhikuiRen const boost::system::error_code ec, 3057a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3058a3316fc6SZhikuiRen if (ec) 3059a3316fc6SZhikuiRen { 3060a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3061a3316fc6SZhikuiRen messages::internalError(aResp->res); 3062a3316fc6SZhikuiRen return; 3063a3316fc6SZhikuiRen } 3064a3316fc6SZhikuiRen 3065a3316fc6SZhikuiRen // skip the empty postcode boots 3066a3316fc6SZhikuiRen if (postcode.empty()) 3067a3316fc6SZhikuiRen { 3068a3316fc6SZhikuiRen return; 3069a3316fc6SZhikuiRen } 3070a3316fc6SZhikuiRen 3071a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 3072a3316fc6SZhikuiRen 3073a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 3074a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 3075a3316fc6SZhikuiRen }, 3076a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3077a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3078a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3079a3316fc6SZhikuiRen bootIndex); 3080a3316fc6SZhikuiRen } 3081a3316fc6SZhikuiRen 3082a3316fc6SZhikuiRen static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp, 3083a3316fc6SZhikuiRen const uint16_t bootIndex, 3084a3316fc6SZhikuiRen const uint16_t bootCount, 3085a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 3086a3316fc6SZhikuiRen const uint64_t top) 3087a3316fc6SZhikuiRen { 3088a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3089a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 3090a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3091a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t>& postcode) { 3092a3316fc6SZhikuiRen if (ec) 3093a3316fc6SZhikuiRen { 3094a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 3095a3316fc6SZhikuiRen messages::internalError(aResp->res); 3096a3316fc6SZhikuiRen return; 3097a3316fc6SZhikuiRen } 3098a3316fc6SZhikuiRen 3099a3316fc6SZhikuiRen uint64_t endCount = entryCount; 3100a3316fc6SZhikuiRen if (!postcode.empty()) 3101a3316fc6SZhikuiRen { 3102a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 3103a3316fc6SZhikuiRen 3104a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 3105a3316fc6SZhikuiRen { 3106a3316fc6SZhikuiRen uint64_t thisBootSkip = 3107a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 3108a3316fc6SZhikuiRen uint64_t thisBootTop = 3109a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 3110a3316fc6SZhikuiRen 3111a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 3112a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 3113a3316fc6SZhikuiRen } 3114a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 3115a3316fc6SZhikuiRen } 3116a3316fc6SZhikuiRen 3117a3316fc6SZhikuiRen // continue to previous bootIndex 3118a3316fc6SZhikuiRen if (bootIndex < bootCount) 3119a3316fc6SZhikuiRen { 3120a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 3121a3316fc6SZhikuiRen bootCount, endCount, skip, top); 3122a3316fc6SZhikuiRen } 3123a3316fc6SZhikuiRen else 3124a3316fc6SZhikuiRen { 3125a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 3126a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3127a3316fc6SZhikuiRen "Entries?$skip=" + 3128a3316fc6SZhikuiRen std::to_string(skip + top); 3129a3316fc6SZhikuiRen } 3130a3316fc6SZhikuiRen }, 3131a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3132a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3133a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 3134a3316fc6SZhikuiRen bootIndex); 3135a3316fc6SZhikuiRen } 3136a3316fc6SZhikuiRen 3137a3316fc6SZhikuiRen static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp, 3138a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 3139a3316fc6SZhikuiRen { 3140a3316fc6SZhikuiRen uint64_t entryCount = 0; 3141a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 3142a3316fc6SZhikuiRen [aResp, entryCount, skip, 3143a3316fc6SZhikuiRen top](const boost::system::error_code ec, 3144a3316fc6SZhikuiRen const std::variant<uint16_t>& bootCount) { 3145a3316fc6SZhikuiRen if (ec) 3146a3316fc6SZhikuiRen { 3147a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 3148a3316fc6SZhikuiRen messages::internalError(aResp->res); 3149a3316fc6SZhikuiRen return; 3150a3316fc6SZhikuiRen } 3151a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 3152a3316fc6SZhikuiRen if (pVal) 3153a3316fc6SZhikuiRen { 3154a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 3155a3316fc6SZhikuiRen } 3156a3316fc6SZhikuiRen else 3157a3316fc6SZhikuiRen { 3158a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 3159a3316fc6SZhikuiRen } 3160a3316fc6SZhikuiRen }, 3161a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 3162a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 3163a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 3164a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 3165a3316fc6SZhikuiRen } 3166a3316fc6SZhikuiRen 3167a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node 3168a3316fc6SZhikuiRen { 3169a3316fc6SZhikuiRen public: 3170a3316fc6SZhikuiRen template <typename CrowApp> 3171a3316fc6SZhikuiRen PostCodesEntryCollection(CrowApp& app) : 3172a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 3173a3316fc6SZhikuiRen { 3174a3316fc6SZhikuiRen entityPrivileges = { 3175a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3176a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3177a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3178a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3179a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3180a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3181a3316fc6SZhikuiRen } 3182a3316fc6SZhikuiRen 3183a3316fc6SZhikuiRen private: 3184a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 3185a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3186a3316fc6SZhikuiRen { 3187a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3188a3316fc6SZhikuiRen 3189a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 3190a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 3191a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 3192a3316fc6SZhikuiRen "/redfish/v1/" 3193a3316fc6SZhikuiRen "$metadata#LogEntryCollection.LogEntryCollection"; 3194a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3195a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 3196a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3197a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3198a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3199a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3200a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3201a3316fc6SZhikuiRen 3202a3316fc6SZhikuiRen uint64_t skip = 0; 3203a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 3204a3316fc6SZhikuiRen if (!getSkipParam(asyncResp->res, req, skip)) 3205a3316fc6SZhikuiRen { 3206a3316fc6SZhikuiRen return; 3207a3316fc6SZhikuiRen } 3208a3316fc6SZhikuiRen if (!getTopParam(asyncResp->res, req, top)) 3209a3316fc6SZhikuiRen { 3210a3316fc6SZhikuiRen return; 3211a3316fc6SZhikuiRen } 3212a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 3213a3316fc6SZhikuiRen } 3214a3316fc6SZhikuiRen }; 3215a3316fc6SZhikuiRen 3216a3316fc6SZhikuiRen class PostCodesEntry : public Node 3217a3316fc6SZhikuiRen { 3218a3316fc6SZhikuiRen public: 3219a3316fc6SZhikuiRen PostCodesEntry(CrowApp& app) : 3220a3316fc6SZhikuiRen Node(app, 3221a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/", 3222a3316fc6SZhikuiRen std::string()) 3223a3316fc6SZhikuiRen { 3224a3316fc6SZhikuiRen entityPrivileges = { 3225a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 3226a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 3227a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 3228a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 3229a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 3230a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 3231a3316fc6SZhikuiRen } 3232a3316fc6SZhikuiRen 3233a3316fc6SZhikuiRen private: 3234a3316fc6SZhikuiRen void doGet(crow::Response& res, const crow::Request& req, 3235a3316fc6SZhikuiRen const std::vector<std::string>& params) override 3236a3316fc6SZhikuiRen { 3237a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 3238a3316fc6SZhikuiRen if (params.size() != 1) 3239a3316fc6SZhikuiRen { 3240a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 3241a3316fc6SZhikuiRen return; 3242a3316fc6SZhikuiRen } 3243a3316fc6SZhikuiRen 3244a3316fc6SZhikuiRen const std::string& targetID = params[0]; 3245a3316fc6SZhikuiRen 3246a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 3247a3316fc6SZhikuiRen if (bootPos == std::string::npos) 3248a3316fc6SZhikuiRen { 3249a3316fc6SZhikuiRen // Requested ID was not found 3250a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 3251a3316fc6SZhikuiRen return; 3252a3316fc6SZhikuiRen } 3253a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 3254a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 3255a3316fc6SZhikuiRen uint16_t bootIndex = 0; 3256a3316fc6SZhikuiRen uint64_t codeIndex = 0; 3257a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 3258a3316fc6SZhikuiRen 3259a3316fc6SZhikuiRen if (dashPos == std::string::npos) 3260a3316fc6SZhikuiRen { 3261a3316fc6SZhikuiRen return; 3262a3316fc6SZhikuiRen } 3263a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 3264a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 3265a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 3266a3316fc6SZhikuiRen 3267a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 3268a3316fc6SZhikuiRen strtoul(std::string(bootIndexStr).c_str(), NULL, 0)); 3269a3316fc6SZhikuiRen codeIndex = strtoul(std::string(codeIndexStr).c_str(), NULL, 0); 3270a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 3271a3316fc6SZhikuiRen { 3272a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 3273a3316fc6SZhikuiRen << params[0]; 3274a3316fc6SZhikuiRen } 3275a3316fc6SZhikuiRen 3276a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 3277a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 3278a3316fc6SZhikuiRen "/redfish/v1/$metadata#LogEntry.LogEntry"; 3279a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 3280a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 3281a3316fc6SZhikuiRen "Entries"; 3282a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 3283a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 3284a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 3285a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 3286a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 3287a3316fc6SZhikuiRen 3288a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 3289a3316fc6SZhikuiRen } 3290a3316fc6SZhikuiRen }; 3291a3316fc6SZhikuiRen 32921da66f75SEd Tanous } // namespace redfish 3293