11da66f75SEd Tanous /* 21da66f75SEd Tanous // Copyright (c) 2018 Intel Corporation 31da66f75SEd Tanous // 41da66f75SEd Tanous // Licensed under the Apache License, Version 2.0 (the "License"); 51da66f75SEd Tanous // you may not use this file except in compliance with the License. 61da66f75SEd Tanous // You may obtain a copy of the License at 71da66f75SEd Tanous // 81da66f75SEd Tanous // http://www.apache.org/licenses/LICENSE-2.0 91da66f75SEd Tanous // 101da66f75SEd Tanous // Unless required by applicable law or agreed to in writing, software 111da66f75SEd Tanous // distributed under the License is distributed on an "AS IS" BASIS, 121da66f75SEd Tanous // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131da66f75SEd Tanous // See the License for the specific language governing permissions and 141da66f75SEd Tanous // limitations under the License. 151da66f75SEd Tanous */ 161da66f75SEd Tanous #pragma once 171da66f75SEd Tanous 181da66f75SEd Tanous #include "node.hpp" 194851d45dSJason M. Bills #include "registries.hpp" 204851d45dSJason M. Bills #include "registries/base_message_registry.hpp" 214851d45dSJason M. Bills #include "registries/openbmc_message_registry.hpp" 2246229577SJames Feist #include "task.hpp" 231da66f75SEd Tanous 24e1f26343SJason M. Bills #include <systemd/sd-journal.h> 25e1f26343SJason M. Bills 264851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 274851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 281da66f75SEd Tanous #include <boost/container/flat_map.hpp> 291ddcf01aSJason M. Bills #include <boost/system/linux_error.hpp> 30cb92c03bSAndrew Geissler #include <error_messages.hpp> 314418c7f0SJames Feist #include <filesystem> 32cd225da8SJason M. Bills #include <string_view> 33abf2add6SEd Tanous #include <variant> 341da66f75SEd Tanous 351da66f75SEd Tanous namespace redfish 361da66f75SEd Tanous { 371da66f75SEd Tanous 385b61b5e8SJason M. Bills constexpr char const *crashdumpObject = "com.intel.crashdump"; 395b61b5e8SJason M. Bills constexpr char const *crashdumpPath = "/com/intel/crashdump"; 405b61b5e8SJason M. Bills constexpr char const *crashdumpOnDemandPath = "/com/intel/crashdump/OnDemand"; 415b61b5e8SJason M. Bills constexpr char const *crashdumpInterface = "com.intel.crashdump"; 425b61b5e8SJason M. Bills constexpr char const *deleteAllInterface = 435b61b5e8SJason M. Bills "xyz.openbmc_project.Collection.DeleteAll"; 445b61b5e8SJason M. Bills constexpr char const *crashdumpOnDemandInterface = 45424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 465b61b5e8SJason M. Bills constexpr char const *crashdumpRawPECIInterface = 47424c4176SJason M. Bills "com.intel.crashdump.SendRawPeci"; 481da66f75SEd Tanous 494851d45dSJason M. Bills namespace message_registries 504851d45dSJason M. Bills { 514851d45dSJason M. Bills static const Message *getMessageFromRegistry( 524851d45dSJason M. Bills const std::string &messageKey, 534851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 544851d45dSJason M. Bills { 554851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 564851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 574851d45dSJason M. Bills [&messageKey](const MessageEntry &messageEntry) { 584851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 594851d45dSJason M. Bills messageKey.c_str()); 604851d45dSJason M. Bills }); 614851d45dSJason M. Bills if (messageIt != registry.cend()) 624851d45dSJason M. Bills { 634851d45dSJason M. Bills return &messageIt->second; 644851d45dSJason M. Bills } 654851d45dSJason M. Bills 664851d45dSJason M. Bills return nullptr; 674851d45dSJason M. Bills } 684851d45dSJason M. Bills 694851d45dSJason M. Bills static const Message *getMessage(const std::string_view &messageID) 704851d45dSJason M. Bills { 714851d45dSJason M. Bills // Redfish MessageIds are in the form 724851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 734851d45dSJason M. Bills // the right Message 744851d45dSJason M. Bills std::vector<std::string> fields; 754851d45dSJason M. Bills fields.reserve(4); 764851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 774851d45dSJason M. Bills std::string ®istryName = fields[0]; 784851d45dSJason M. Bills std::string &messageKey = fields[3]; 794851d45dSJason M. Bills 804851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 814851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 824851d45dSJason M. Bills { 834851d45dSJason M. Bills return getMessageFromRegistry( 844851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 854851d45dSJason M. Bills } 864851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 874851d45dSJason M. Bills { 884851d45dSJason M. Bills return getMessageFromRegistry( 894851d45dSJason M. Bills messageKey, 904851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 914851d45dSJason M. Bills } 924851d45dSJason M. Bills return nullptr; 934851d45dSJason M. Bills } 944851d45dSJason M. Bills } // namespace message_registries 954851d45dSJason M. Bills 96f6150403SJames Feist namespace fs = std::filesystem; 971da66f75SEd Tanous 98cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 99cb92c03bSAndrew Geissler std::string, 100cb92c03bSAndrew Geissler sdbusplus::message::variant<std::string, bool, uint8_t, int16_t, uint16_t, 101cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 102cb92c03bSAndrew Geissler 103cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 104cb92c03bSAndrew Geissler sdbusplus::message::object_path, 105cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 106cb92c03bSAndrew Geissler 107cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string &s) 108cb92c03bSAndrew Geissler { 109cb92c03bSAndrew Geissler if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert") 110cb92c03bSAndrew Geissler { 111cb92c03bSAndrew Geissler return "Critical"; 112cb92c03bSAndrew Geissler } 113cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") 114cb92c03bSAndrew Geissler { 115cb92c03bSAndrew Geissler return "Critical"; 116cb92c03bSAndrew Geissler } 117cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug") 118cb92c03bSAndrew Geissler { 119cb92c03bSAndrew Geissler return "OK"; 120cb92c03bSAndrew Geissler } 121cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") 122cb92c03bSAndrew Geissler { 123cb92c03bSAndrew Geissler return "Critical"; 124cb92c03bSAndrew Geissler } 125cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error") 126cb92c03bSAndrew Geissler { 127cb92c03bSAndrew Geissler return "Critical"; 128cb92c03bSAndrew Geissler } 129cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") 130cb92c03bSAndrew Geissler { 131cb92c03bSAndrew Geissler return "OK"; 132cb92c03bSAndrew Geissler } 133cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice") 134cb92c03bSAndrew Geissler { 135cb92c03bSAndrew Geissler return "OK"; 136cb92c03bSAndrew Geissler } 137cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 138cb92c03bSAndrew Geissler { 139cb92c03bSAndrew Geissler return "Warning"; 140cb92c03bSAndrew Geissler } 141cb92c03bSAndrew Geissler return ""; 142cb92c03bSAndrew Geissler } 143cb92c03bSAndrew Geissler 14416428a1aSJason M. Bills static int getJournalMetadata(sd_journal *journal, 14539e77504SEd Tanous const std::string_view &field, 14639e77504SEd Tanous std::string_view &contents) 14716428a1aSJason M. Bills { 14816428a1aSJason M. Bills const char *data = nullptr; 14916428a1aSJason M. Bills size_t length = 0; 15016428a1aSJason M. Bills int ret = 0; 15116428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 152271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 153271584abSEd Tanous reinterpret_cast<const void **>(&data), &length); 15416428a1aSJason M. Bills if (ret < 0) 15516428a1aSJason M. Bills { 15616428a1aSJason M. Bills return ret; 15716428a1aSJason M. Bills } 15839e77504SEd Tanous contents = std::string_view(data, length); 15916428a1aSJason M. Bills // Only use the content after the "=" character. 16016428a1aSJason M. Bills contents.remove_prefix(std::min(contents.find("=") + 1, contents.size())); 16116428a1aSJason M. Bills return ret; 16216428a1aSJason M. Bills } 16316428a1aSJason M. Bills 16416428a1aSJason M. Bills static int getJournalMetadata(sd_journal *journal, 16539e77504SEd Tanous const std::string_view &field, const int &base, 166271584abSEd Tanous long int &contents) 16716428a1aSJason M. Bills { 16816428a1aSJason M. Bills int ret = 0; 16939e77504SEd Tanous std::string_view metadata; 17016428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 17116428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 17216428a1aSJason M. Bills if (ret < 0) 17316428a1aSJason M. Bills { 17416428a1aSJason M. Bills return ret; 17516428a1aSJason M. Bills } 176b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 17716428a1aSJason M. Bills return ret; 17816428a1aSJason M. Bills } 17916428a1aSJason M. Bills 180a3316fc6SZhikuiRen static bool getTimestampStr(const uint64_t usecSinceEpoch, 181a3316fc6SZhikuiRen std::string &entryTimestamp) 18216428a1aSJason M. Bills { 183a3316fc6SZhikuiRen time_t t = static_cast<time_t>(usecSinceEpoch / 1000 / 1000); 18416428a1aSJason M. Bills struct tm *loctime = localtime(&t); 18516428a1aSJason M. Bills char entryTime[64] = {}; 18699131cd0SEd Tanous if (nullptr != loctime) 18716428a1aSJason M. Bills { 18816428a1aSJason M. Bills strftime(entryTime, sizeof(entryTime), "%FT%T%z", loctime); 18916428a1aSJason M. Bills } 19016428a1aSJason M. Bills // Insert the ':' into the timezone 19139e77504SEd Tanous std::string_view t1(entryTime); 19239e77504SEd Tanous std::string_view t2(entryTime); 19316428a1aSJason M. Bills if (t1.size() > 2 && t2.size() > 2) 19416428a1aSJason M. Bills { 19516428a1aSJason M. Bills t1.remove_suffix(2); 19616428a1aSJason M. Bills t2.remove_prefix(t2.size() - 2); 19716428a1aSJason M. Bills } 19839e77504SEd Tanous entryTimestamp = std::string(t1) + ":" + std::string(t2); 19916428a1aSJason M. Bills return true; 20016428a1aSJason M. Bills } 20116428a1aSJason M. Bills 202a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal *journal, std::string &entryTimestamp) 203a3316fc6SZhikuiRen { 204a3316fc6SZhikuiRen int ret = 0; 205a3316fc6SZhikuiRen uint64_t timestamp = 0; 206a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 207a3316fc6SZhikuiRen if (ret < 0) 208a3316fc6SZhikuiRen { 209a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 210a3316fc6SZhikuiRen << strerror(-ret); 211a3316fc6SZhikuiRen return false; 212a3316fc6SZhikuiRen } 213a3316fc6SZhikuiRen return getTimestampStr(timestamp, entryTimestamp); 214a3316fc6SZhikuiRen } 215a3316fc6SZhikuiRen 21616428a1aSJason M. Bills static bool getSkipParam(crow::Response &res, const crow::Request &req, 217271584abSEd Tanous uint64_t &skip) 21816428a1aSJason M. Bills { 21916428a1aSJason M. Bills char *skipParam = req.urlParams.get("$skip"); 22016428a1aSJason M. Bills if (skipParam != nullptr) 22116428a1aSJason M. Bills { 22216428a1aSJason M. Bills char *ptr = nullptr; 223271584abSEd Tanous skip = std::strtoul(skipParam, &ptr, 10); 22416428a1aSJason M. Bills if (*skipParam == '\0' || *ptr != '\0') 22516428a1aSJason M. Bills { 22616428a1aSJason M. Bills 22716428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(skipParam), 22816428a1aSJason M. Bills "$skip"); 22916428a1aSJason M. Bills return false; 23016428a1aSJason M. Bills } 23116428a1aSJason M. Bills } 23216428a1aSJason M. Bills return true; 23316428a1aSJason M. Bills } 23416428a1aSJason M. Bills 235271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 23616428a1aSJason M. Bills static bool getTopParam(crow::Response &res, const crow::Request &req, 237271584abSEd Tanous uint64_t &top) 23816428a1aSJason M. Bills { 23916428a1aSJason M. Bills char *topParam = req.urlParams.get("$top"); 24016428a1aSJason M. Bills if (topParam != nullptr) 24116428a1aSJason M. Bills { 24216428a1aSJason M. Bills char *ptr = nullptr; 243271584abSEd Tanous top = std::strtoul(topParam, &ptr, 10); 24416428a1aSJason M. Bills if (*topParam == '\0' || *ptr != '\0') 24516428a1aSJason M. Bills { 24616428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(topParam), 24716428a1aSJason M. Bills "$top"); 24816428a1aSJason M. Bills return false; 24916428a1aSJason M. Bills } 250271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 25116428a1aSJason M. Bills { 25216428a1aSJason M. Bills 25316428a1aSJason M. Bills messages::queryParameterOutOfRange( 25416428a1aSJason M. Bills res, std::to_string(top), "$top", 25516428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 25616428a1aSJason M. Bills return false; 25716428a1aSJason M. Bills } 25816428a1aSJason M. Bills } 25916428a1aSJason M. Bills return true; 26016428a1aSJason M. Bills } 26116428a1aSJason M. Bills 262e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal *journal, std::string &entryID, 263e85d6b16SJason M. Bills const bool firstEntry = true) 26416428a1aSJason M. Bills { 26516428a1aSJason M. Bills int ret = 0; 26616428a1aSJason M. Bills static uint64_t prevTs = 0; 26716428a1aSJason M. Bills static int index = 0; 268e85d6b16SJason M. Bills if (firstEntry) 269e85d6b16SJason M. Bills { 270e85d6b16SJason M. Bills prevTs = 0; 271e85d6b16SJason M. Bills } 272e85d6b16SJason M. Bills 27316428a1aSJason M. Bills // Get the entry timestamp 27416428a1aSJason M. Bills uint64_t curTs = 0; 27516428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 27616428a1aSJason M. Bills if (ret < 0) 27716428a1aSJason M. Bills { 27816428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 27916428a1aSJason M. Bills << strerror(-ret); 28016428a1aSJason M. Bills return false; 28116428a1aSJason M. Bills } 28216428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 28316428a1aSJason M. Bills if (curTs == prevTs) 28416428a1aSJason M. Bills { 28516428a1aSJason M. Bills index++; 28616428a1aSJason M. Bills } 28716428a1aSJason M. Bills else 28816428a1aSJason M. Bills { 28916428a1aSJason M. Bills // Otherwise, reset it 29016428a1aSJason M. Bills index = 0; 29116428a1aSJason M. Bills } 29216428a1aSJason M. Bills // Save the timestamp 29316428a1aSJason M. Bills prevTs = curTs; 29416428a1aSJason M. Bills 29516428a1aSJason M. Bills entryID = std::to_string(curTs); 29616428a1aSJason M. Bills if (index > 0) 29716428a1aSJason M. Bills { 29816428a1aSJason M. Bills entryID += "_" + std::to_string(index); 29916428a1aSJason M. Bills } 30016428a1aSJason M. Bills return true; 30116428a1aSJason M. Bills } 30216428a1aSJason M. Bills 303e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string &logEntry, std::string &entryID, 304e85d6b16SJason M. Bills const bool firstEntry = true) 30595820184SJason M. Bills { 306271584abSEd Tanous static time_t prevTs = 0; 30795820184SJason M. Bills static int index = 0; 308e85d6b16SJason M. Bills if (firstEntry) 309e85d6b16SJason M. Bills { 310e85d6b16SJason M. Bills prevTs = 0; 311e85d6b16SJason M. Bills } 312e85d6b16SJason M. Bills 31395820184SJason M. Bills // Get the entry timestamp 314271584abSEd Tanous std::time_t curTs = 0; 31595820184SJason M. Bills std::tm timeStruct = {}; 31695820184SJason M. Bills std::istringstream entryStream(logEntry); 31795820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 31895820184SJason M. Bills { 31995820184SJason M. Bills curTs = std::mktime(&timeStruct); 32095820184SJason M. Bills } 32195820184SJason M. Bills // If the timestamp isn't unique, increment the index 32295820184SJason M. Bills if (curTs == prevTs) 32395820184SJason M. Bills { 32495820184SJason M. Bills index++; 32595820184SJason M. Bills } 32695820184SJason M. Bills else 32795820184SJason M. Bills { 32895820184SJason M. Bills // Otherwise, reset it 32995820184SJason M. Bills index = 0; 33095820184SJason M. Bills } 33195820184SJason M. Bills // Save the timestamp 33295820184SJason M. Bills prevTs = curTs; 33395820184SJason M. Bills 33495820184SJason M. Bills entryID = std::to_string(curTs); 33595820184SJason M. Bills if (index > 0) 33695820184SJason M. Bills { 33795820184SJason M. Bills entryID += "_" + std::to_string(index); 33895820184SJason M. Bills } 33995820184SJason M. Bills return true; 34095820184SJason M. Bills } 34195820184SJason M. Bills 34216428a1aSJason M. Bills static bool getTimestampFromID(crow::Response &res, const std::string &entryID, 343271584abSEd Tanous uint64_t ×tamp, uint64_t &index) 34416428a1aSJason M. Bills { 34516428a1aSJason M. Bills if (entryID.empty()) 34616428a1aSJason M. Bills { 34716428a1aSJason M. Bills return false; 34816428a1aSJason M. Bills } 34916428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 35039e77504SEd Tanous std::string_view tsStr(entryID); 35116428a1aSJason M. Bills 35216428a1aSJason M. Bills auto underscorePos = tsStr.find("_"); 35316428a1aSJason M. Bills if (underscorePos != tsStr.npos) 35416428a1aSJason M. Bills { 35516428a1aSJason M. Bills // Timestamp has an index 35616428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 35739e77504SEd Tanous std::string_view indexStr(entryID); 35816428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 35916428a1aSJason M. Bills std::size_t pos; 36016428a1aSJason M. Bills try 36116428a1aSJason M. Bills { 36239e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 36316428a1aSJason M. Bills } 364271584abSEd Tanous catch (std::invalid_argument &) 36516428a1aSJason M. Bills { 36616428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 36716428a1aSJason M. Bills return false; 36816428a1aSJason M. Bills } 369271584abSEd Tanous catch (std::out_of_range &) 37016428a1aSJason M. Bills { 37116428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37216428a1aSJason M. Bills return false; 37316428a1aSJason M. Bills } 37416428a1aSJason M. Bills if (pos != indexStr.size()) 37516428a1aSJason M. Bills { 37616428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37716428a1aSJason M. Bills return false; 37816428a1aSJason M. Bills } 37916428a1aSJason M. Bills } 38016428a1aSJason M. Bills // Timestamp has no index 38116428a1aSJason M. Bills std::size_t pos; 38216428a1aSJason M. Bills try 38316428a1aSJason M. Bills { 38439e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 38516428a1aSJason M. Bills } 386271584abSEd Tanous catch (std::invalid_argument &) 38716428a1aSJason M. Bills { 38816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 38916428a1aSJason M. Bills return false; 39016428a1aSJason M. Bills } 391271584abSEd Tanous catch (std::out_of_range &) 39216428a1aSJason M. Bills { 39316428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 39416428a1aSJason M. Bills return false; 39516428a1aSJason M. Bills } 39616428a1aSJason M. Bills if (pos != tsStr.size()) 39716428a1aSJason M. Bills { 39816428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 39916428a1aSJason M. Bills return false; 40016428a1aSJason M. Bills } 40116428a1aSJason M. Bills return true; 40216428a1aSJason M. Bills } 40316428a1aSJason M. Bills 40495820184SJason M. Bills static bool 40595820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path> &redfishLogFiles) 40695820184SJason M. Bills { 40795820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 40895820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 40995820184SJason M. Bills 41095820184SJason M. Bills // Loop through the directory looking for redfish log files 41195820184SJason M. Bills for (const std::filesystem::directory_entry &dirEnt : 41295820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 41395820184SJason M. Bills { 41495820184SJason M. Bills // If we find a redfish log file, save the path 41595820184SJason M. Bills std::string filename = dirEnt.path().filename(); 41695820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 41795820184SJason M. Bills { 41895820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 41995820184SJason M. Bills } 42095820184SJason M. Bills } 42195820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 42295820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 42395820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 42495820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 42595820184SJason M. Bills 42695820184SJason M. Bills return !redfishLogFiles.empty(); 42795820184SJason M. Bills } 42895820184SJason M. Bills 429043a0536SJohnathan Mantey static void ParseCrashdumpParameters( 430043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>> ¶ms, 431043a0536SJohnathan Mantey std::string &filename, std::string ×tamp, std::string &logfile) 432043a0536SJohnathan Mantey { 433043a0536SJohnathan Mantey for (auto property : params) 434043a0536SJohnathan Mantey { 435043a0536SJohnathan Mantey if (property.first == "Timestamp") 436043a0536SJohnathan Mantey { 437043a0536SJohnathan Mantey const std::string *value = 438043a0536SJohnathan Mantey sdbusplus::message::variant_ns::get_if<std::string>( 439043a0536SJohnathan Mantey &property.second); 440043a0536SJohnathan Mantey if (value != nullptr) 441043a0536SJohnathan Mantey { 442043a0536SJohnathan Mantey timestamp = *value; 443043a0536SJohnathan Mantey } 444043a0536SJohnathan Mantey } 445043a0536SJohnathan Mantey else if (property.first == "Filename") 446043a0536SJohnathan Mantey { 447043a0536SJohnathan Mantey const std::string *value = 448043a0536SJohnathan Mantey sdbusplus::message::variant_ns::get_if<std::string>( 449043a0536SJohnathan Mantey &property.second); 450043a0536SJohnathan Mantey if (value != nullptr) 451043a0536SJohnathan Mantey { 452043a0536SJohnathan Mantey filename = *value; 453043a0536SJohnathan Mantey } 454043a0536SJohnathan Mantey } 455043a0536SJohnathan Mantey else if (property.first == "Log") 456043a0536SJohnathan Mantey { 457043a0536SJohnathan Mantey const std::string *value = 458043a0536SJohnathan Mantey sdbusplus::message::variant_ns::get_if<std::string>( 459043a0536SJohnathan Mantey &property.second); 460043a0536SJohnathan Mantey if (value != nullptr) 461043a0536SJohnathan Mantey { 462043a0536SJohnathan Mantey logfile = *value; 463043a0536SJohnathan Mantey } 464043a0536SJohnathan Mantey } 465043a0536SJohnathan Mantey } 466043a0536SJohnathan Mantey } 467043a0536SJohnathan Mantey 468a3316fc6SZhikuiRen constexpr char const *postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 469c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node 4701da66f75SEd Tanous { 4711da66f75SEd Tanous public: 4721da66f75SEd Tanous template <typename CrowApp> 473c4bf6374SJason M. Bills SystemLogServiceCollection(CrowApp &app) : 474029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/") 475c4bf6374SJason M. Bills { 476c4bf6374SJason M. Bills entityPrivileges = { 477c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 478c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 479c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 480c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 481c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 482c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 483c4bf6374SJason M. Bills } 484c4bf6374SJason M. Bills 485c4bf6374SJason M. Bills private: 486c4bf6374SJason M. Bills /** 487c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 488c4bf6374SJason M. Bills */ 489c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 490c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 491c4bf6374SJason M. Bills { 492c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 493c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 494c4bf6374SJason M. Bills // it has a duplicate entry for members 495c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 496c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 497c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 498029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 499c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 500c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 501c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 502c4bf6374SJason M. Bills nlohmann::json &logServiceArray = asyncResp->res.jsonValue["Members"]; 503c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 504029573d4SEd Tanous logServiceArray.push_back( 505029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}}); 506d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 507d53dd41fSJason M. Bills logServiceArray.push_back( 508cb92c03bSAndrew Geissler {{"@odata.id", 509424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 510d53dd41fSJason M. Bills #endif 511c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 512c4bf6374SJason M. Bills logServiceArray.size(); 513a3316fc6SZhikuiRen 514a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 515a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 516a3316fc6SZhikuiRen const std::vector<std::string> &subtreePath) { 517a3316fc6SZhikuiRen if (ec) 518a3316fc6SZhikuiRen { 519a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 520a3316fc6SZhikuiRen return; 521a3316fc6SZhikuiRen } 522a3316fc6SZhikuiRen 523a3316fc6SZhikuiRen for (auto &pathStr : subtreePath) 524a3316fc6SZhikuiRen { 525a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 526a3316fc6SZhikuiRen { 527a3316fc6SZhikuiRen nlohmann::json &logServiceArray = 528a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 529a3316fc6SZhikuiRen logServiceArray.push_back( 530a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 531a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 532a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 533a3316fc6SZhikuiRen logServiceArray.size(); 534a3316fc6SZhikuiRen return; 535a3316fc6SZhikuiRen } 536a3316fc6SZhikuiRen } 537a3316fc6SZhikuiRen }, 538a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 539a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 540a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 541a3316fc6SZhikuiRen std::array<const char *, 1>{postCodeIface}); 542c4bf6374SJason M. Bills } 543c4bf6374SJason M. Bills }; 544c4bf6374SJason M. Bills 545c4bf6374SJason M. Bills class EventLogService : public Node 546c4bf6374SJason M. Bills { 547c4bf6374SJason M. Bills public: 548c4bf6374SJason M. Bills template <typename CrowApp> 549c4bf6374SJason M. Bills EventLogService(CrowApp &app) : 550029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 551c4bf6374SJason M. Bills { 552c4bf6374SJason M. Bills entityPrivileges = { 553c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 554c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 555c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 556c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 557c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 558c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 559c4bf6374SJason M. Bills } 560c4bf6374SJason M. Bills 561c4bf6374SJason M. Bills private: 562c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 563c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 564c4bf6374SJason M. Bills { 565c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 566c4bf6374SJason M. Bills 567c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 568029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 569c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 570c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 571c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 572c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 573c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 574c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 575c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 576c4bf6374SJason M. Bills {"@odata.id", 577029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 578e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 579e7d6c8b2SGunnar Mills 580e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 581e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 582489640c6SJason M. Bills } 583489640c6SJason M. Bills }; 584489640c6SJason M. Bills 5851f56a3a6STim Lee class JournalEventLogClear : public Node 586489640c6SJason M. Bills { 587489640c6SJason M. Bills public: 5881f56a3a6STim Lee JournalEventLogClear(CrowApp &app) : 589489640c6SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 590489640c6SJason M. Bills "LogService.ClearLog/") 591489640c6SJason M. Bills { 592489640c6SJason M. Bills entityPrivileges = { 593489640c6SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 594489640c6SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 595489640c6SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 596489640c6SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 597489640c6SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 598489640c6SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 599489640c6SJason M. Bills } 600489640c6SJason M. Bills 601489640c6SJason M. Bills private: 602489640c6SJason M. Bills void doPost(crow::Response &res, const crow::Request &req, 603489640c6SJason M. Bills const std::vector<std::string> ¶ms) override 604489640c6SJason M. Bills { 605489640c6SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 606489640c6SJason M. Bills 607489640c6SJason M. Bills // Clear the EventLog by deleting the log files 608489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 609489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 610489640c6SJason M. Bills { 611489640c6SJason M. Bills for (const std::filesystem::path &file : redfishLogFiles) 612489640c6SJason M. Bills { 613489640c6SJason M. Bills std::error_code ec; 614489640c6SJason M. Bills std::filesystem::remove(file, ec); 615489640c6SJason M. Bills } 616489640c6SJason M. Bills } 617489640c6SJason M. Bills 618489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 619489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 620489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 621489640c6SJason M. Bills if (ec) 622489640c6SJason M. Bills { 623489640c6SJason M. Bills BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 624489640c6SJason M. Bills messages::internalError(asyncResp->res); 625489640c6SJason M. Bills return; 626489640c6SJason M. Bills } 627489640c6SJason M. Bills 628489640c6SJason M. Bills messages::success(asyncResp->res); 629489640c6SJason M. Bills }, 630489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 631489640c6SJason M. Bills "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 632489640c6SJason M. Bills "replace"); 633c4bf6374SJason M. Bills } 634c4bf6374SJason M. Bills }; 635c4bf6374SJason M. Bills 63695820184SJason M. Bills static int fillEventLogEntryJson(const std::string &logEntryID, 63795820184SJason M. Bills const std::string logEntry, 63895820184SJason M. Bills nlohmann::json &logEntryJson) 639c4bf6374SJason M. Bills { 64095820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 641cd225da8SJason M. Bills // First get the Timestamp 642cd225da8SJason M. Bills size_t space = logEntry.find_first_of(" "); 643cd225da8SJason M. Bills if (space == std::string::npos) 64495820184SJason M. Bills { 64595820184SJason M. Bills return 1; 64695820184SJason M. Bills } 647cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 648cd225da8SJason M. Bills // Then get the log contents 649cd225da8SJason M. Bills size_t entryStart = logEntry.find_first_not_of(" ", space); 650cd225da8SJason M. Bills if (entryStart == std::string::npos) 651cd225da8SJason M. Bills { 652cd225da8SJason M. Bills return 1; 653cd225da8SJason M. Bills } 654cd225da8SJason M. Bills std::string_view entry(logEntry); 655cd225da8SJason M. Bills entry.remove_prefix(entryStart); 656cd225da8SJason M. Bills // Use split to separate the entry into its fields 657cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 658cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 659cd225da8SJason M. Bills boost::token_compress_on); 660cd225da8SJason M. Bills // We need at least a MessageId to be valid 661cd225da8SJason M. Bills if (logEntryFields.size() < 1) 662cd225da8SJason M. Bills { 663cd225da8SJason M. Bills return 1; 664cd225da8SJason M. Bills } 665cd225da8SJason M. Bills std::string &messageID = logEntryFields[0]; 66695820184SJason M. Bills 6674851d45dSJason M. Bills // Get the Message from the MessageRegistry 6684851d45dSJason M. Bills const message_registries::Message *message = 6694851d45dSJason M. Bills message_registries::getMessage(messageID); 670c4bf6374SJason M. Bills 6714851d45dSJason M. Bills std::string msg; 6724851d45dSJason M. Bills std::string severity; 6734851d45dSJason M. Bills if (message != nullptr) 674c4bf6374SJason M. Bills { 6754851d45dSJason M. Bills msg = message->message; 6764851d45dSJason M. Bills severity = message->severity; 677c4bf6374SJason M. Bills } 678c4bf6374SJason M. Bills 67915a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 68015a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 68115a86ff6SJason M. Bills if (logEntryFields.size() > 1) 68215a86ff6SJason M. Bills { 68315a86ff6SJason M. Bills std::string &messageArgsStart = logEntryFields[1]; 68415a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 68515a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 68615a86ff6SJason M. Bills if (!messageArgsStart.empty()) 68715a86ff6SJason M. Bills { 68815a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 68915a86ff6SJason M. Bills } 69015a86ff6SJason M. Bills 69115a86ff6SJason M. Bills messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize); 692c4bf6374SJason M. Bills 6934851d45dSJason M. Bills // Fill the MessageArgs into the Message 69495820184SJason M. Bills int i = 0; 69595820184SJason M. Bills for (const std::string &messageArg : messageArgs) 6964851d45dSJason M. Bills { 69795820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 6984851d45dSJason M. Bills size_t argPos = msg.find(argStr); 6994851d45dSJason M. Bills if (argPos != std::string::npos) 7004851d45dSJason M. Bills { 70195820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 7024851d45dSJason M. Bills } 7034851d45dSJason M. Bills } 70415a86ff6SJason M. Bills } 7054851d45dSJason M. Bills 70695820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 70795820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 70895820184SJason M. Bills // between the '.' and the '+', so just remove them. 70995820184SJason M. Bills std::size_t dot = timestamp.find_first_of("."); 71095820184SJason M. Bills std::size_t plus = timestamp.find_first_of("+"); 71195820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 712c4bf6374SJason M. Bills { 71395820184SJason M. Bills timestamp.erase(dot, plus - dot); 714c4bf6374SJason M. Bills } 715c4bf6374SJason M. Bills 716c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 71795820184SJason M. Bills logEntryJson = { 718cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 719029573d4SEd Tanous {"@odata.id", 720897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 72195820184SJason M. Bills logEntryID}, 722c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 72395820184SJason M. Bills {"Id", logEntryID}, 72495820184SJason M. Bills {"Message", std::move(msg)}, 72595820184SJason M. Bills {"MessageId", std::move(messageID)}, 726c4bf6374SJason M. Bills {"MessageArgs", std::move(messageArgs)}, 727c4bf6374SJason M. Bills {"EntryType", "Event"}, 72895820184SJason M. Bills {"Severity", std::move(severity)}, 72995820184SJason M. Bills {"Created", std::move(timestamp)}}; 730c4bf6374SJason M. Bills return 0; 731c4bf6374SJason M. Bills } 732c4bf6374SJason M. Bills 73327062605SAnthony Wilson class JournalEventLogEntryCollection : public Node 734c4bf6374SJason M. Bills { 735c4bf6374SJason M. Bills public: 736c4bf6374SJason M. Bills template <typename CrowApp> 73727062605SAnthony Wilson JournalEventLogEntryCollection(CrowApp &app) : 738029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 739c4bf6374SJason M. Bills { 740c4bf6374SJason M. Bills entityPrivileges = { 741c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 742c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 743c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 744c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 745c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 746c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 747c4bf6374SJason M. Bills } 748c4bf6374SJason M. Bills 749c4bf6374SJason M. Bills private: 750c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 751c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 752c4bf6374SJason M. Bills { 753c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 754271584abSEd Tanous uint64_t skip = 0; 755271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 756c4bf6374SJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 757c4bf6374SJason M. Bills { 758c4bf6374SJason M. Bills return; 759c4bf6374SJason M. Bills } 760c4bf6374SJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 761c4bf6374SJason M. Bills { 762c4bf6374SJason M. Bills return; 763c4bf6374SJason M. Bills } 764c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 765c4bf6374SJason M. Bills // it has a duplicate entry for members 766c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 767c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 768c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 769029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 770c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 771c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 772c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 773cb92c03bSAndrew Geissler 774c4bf6374SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 775c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 77695820184SJason M. Bills // Go through the log files and create a unique ID for each entry 77795820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 77895820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 779b01bf299SEd Tanous uint64_t entryCount = 0; 780cd225da8SJason M. Bills std::string logEntry; 78195820184SJason M. Bills 78295820184SJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 783cd225da8SJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 784cd225da8SJason M. Bills it++) 785c4bf6374SJason M. Bills { 786cd225da8SJason M. Bills std::ifstream logStream(*it); 78795820184SJason M. Bills if (!logStream.is_open()) 788c4bf6374SJason M. Bills { 789c4bf6374SJason M. Bills continue; 790c4bf6374SJason M. Bills } 791c4bf6374SJason M. Bills 792e85d6b16SJason M. Bills // Reset the unique ID on the first entry 793e85d6b16SJason M. Bills bool firstEntry = true; 79495820184SJason M. Bills while (std::getline(logStream, logEntry)) 79595820184SJason M. Bills { 796c4bf6374SJason M. Bills entryCount++; 797c4bf6374SJason M. Bills // Handle paging using skip (number of entries to skip from the 798c4bf6374SJason M. Bills // start) and top (number of entries to display) 799c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 800c4bf6374SJason M. Bills { 801c4bf6374SJason M. Bills continue; 802c4bf6374SJason M. Bills } 803c4bf6374SJason M. Bills 804c4bf6374SJason M. Bills std::string idStr; 805e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 806c4bf6374SJason M. Bills { 807c4bf6374SJason M. Bills continue; 808c4bf6374SJason M. Bills } 809c4bf6374SJason M. Bills 810e85d6b16SJason M. Bills if (firstEntry) 811e85d6b16SJason M. Bills { 812e85d6b16SJason M. Bills firstEntry = false; 813e85d6b16SJason M. Bills } 814e85d6b16SJason M. Bills 815c4bf6374SJason M. Bills logEntryArray.push_back({}); 816c4bf6374SJason M. Bills nlohmann::json &bmcLogEntry = logEntryArray.back(); 81795820184SJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) 818c4bf6374SJason M. Bills { 819c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 820c4bf6374SJason M. Bills return; 821c4bf6374SJason M. Bills } 822c4bf6374SJason M. Bills } 82395820184SJason M. Bills } 824c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 825c4bf6374SJason M. Bills if (skip + top < entryCount) 826c4bf6374SJason M. Bills { 827c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 82895820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 82995820184SJason M. Bills "Entries?$skip=" + 830c4bf6374SJason M. Bills std::to_string(skip + top); 831c4bf6374SJason M. Bills } 83208a4e4b5SAnthony Wilson } 83308a4e4b5SAnthony Wilson }; 83408a4e4b5SAnthony Wilson 835897967deSJason M. Bills class JournalEventLogEntry : public Node 836897967deSJason M. Bills { 837897967deSJason M. Bills public: 838897967deSJason M. Bills JournalEventLogEntry(CrowApp &app) : 839897967deSJason M. Bills Node(app, 840897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 841897967deSJason M. Bills std::string()) 842897967deSJason M. Bills { 843897967deSJason M. Bills entityPrivileges = { 844897967deSJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 845897967deSJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 846897967deSJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 847897967deSJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 848897967deSJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 849897967deSJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 850897967deSJason M. Bills } 851897967deSJason M. Bills 852897967deSJason M. Bills private: 853897967deSJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 854897967deSJason M. Bills const std::vector<std::string> ¶ms) override 855897967deSJason M. Bills { 856897967deSJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 857897967deSJason M. Bills if (params.size() != 1) 858897967deSJason M. Bills { 859897967deSJason M. Bills messages::internalError(asyncResp->res); 860897967deSJason M. Bills return; 861897967deSJason M. Bills } 862897967deSJason M. Bills const std::string &targetID = params[0]; 863897967deSJason M. Bills 864897967deSJason M. Bills // Go through the log files and check the unique ID for each entry to 865897967deSJason M. Bills // find the target entry 866897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 867897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 868897967deSJason M. Bills std::string logEntry; 869897967deSJason M. Bills 870897967deSJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 871897967deSJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 872897967deSJason M. Bills it++) 873897967deSJason M. Bills { 874897967deSJason M. Bills std::ifstream logStream(*it); 875897967deSJason M. Bills if (!logStream.is_open()) 876897967deSJason M. Bills { 877897967deSJason M. Bills continue; 878897967deSJason M. Bills } 879897967deSJason M. Bills 880897967deSJason M. Bills // Reset the unique ID on the first entry 881897967deSJason M. Bills bool firstEntry = true; 882897967deSJason M. Bills while (std::getline(logStream, logEntry)) 883897967deSJason M. Bills { 884897967deSJason M. Bills std::string idStr; 885897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 886897967deSJason M. Bills { 887897967deSJason M. Bills continue; 888897967deSJason M. Bills } 889897967deSJason M. Bills 890897967deSJason M. Bills if (firstEntry) 891897967deSJason M. Bills { 892897967deSJason M. Bills firstEntry = false; 893897967deSJason M. Bills } 894897967deSJason M. Bills 895897967deSJason M. Bills if (idStr == targetID) 896897967deSJason M. Bills { 897897967deSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, 898897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 899897967deSJason M. Bills { 900897967deSJason M. Bills messages::internalError(asyncResp->res); 901897967deSJason M. Bills return; 902897967deSJason M. Bills } 903897967deSJason M. Bills return; 904897967deSJason M. Bills } 905897967deSJason M. Bills } 906897967deSJason M. Bills } 907897967deSJason M. Bills // Requested ID was not found 908897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 909897967deSJason M. Bills } 910897967deSJason M. Bills }; 911897967deSJason M. Bills 91208a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node 91308a4e4b5SAnthony Wilson { 91408a4e4b5SAnthony Wilson public: 91508a4e4b5SAnthony Wilson template <typename CrowApp> 91608a4e4b5SAnthony Wilson DBusEventLogEntryCollection(CrowApp &app) : 91708a4e4b5SAnthony Wilson Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 91808a4e4b5SAnthony Wilson { 91908a4e4b5SAnthony Wilson entityPrivileges = { 92008a4e4b5SAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 92108a4e4b5SAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 92208a4e4b5SAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 92308a4e4b5SAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 92408a4e4b5SAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 92508a4e4b5SAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 92608a4e4b5SAnthony Wilson } 92708a4e4b5SAnthony Wilson 92808a4e4b5SAnthony Wilson private: 92908a4e4b5SAnthony Wilson void doGet(crow::Response &res, const crow::Request &req, 93008a4e4b5SAnthony Wilson const std::vector<std::string> ¶ms) override 93108a4e4b5SAnthony Wilson { 93208a4e4b5SAnthony Wilson std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 93308a4e4b5SAnthony Wilson 93408a4e4b5SAnthony Wilson // Collections don't include the static data added by SubRoute because 93508a4e4b5SAnthony Wilson // it has a duplicate entry for members 93608a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 93708a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 93808a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 93908a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 94008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 94108a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 94208a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 94308a4e4b5SAnthony Wilson 944cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 945cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 946cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 947cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 948cb92c03bSAndrew Geissler GetManagedObjectsType &resp) { 949cb92c03bSAndrew Geissler if (ec) 950cb92c03bSAndrew Geissler { 951cb92c03bSAndrew Geissler // TODO Handle for specific error code 952cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 953cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 954cb92c03bSAndrew Geissler << ec; 955cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 956cb92c03bSAndrew Geissler return; 957cb92c03bSAndrew Geissler } 958cb92c03bSAndrew Geissler nlohmann::json &entriesArray = 959cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 960cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 961cb92c03bSAndrew Geissler for (auto &objectPath : resp) 962cb92c03bSAndrew Geissler { 963cb92c03bSAndrew Geissler for (auto &interfaceMap : objectPath.second) 964cb92c03bSAndrew Geissler { 965cb92c03bSAndrew Geissler if (interfaceMap.first != 966cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry") 967cb92c03bSAndrew Geissler { 968cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Bailing early on " 969cb92c03bSAndrew Geissler << interfaceMap.first; 970cb92c03bSAndrew Geissler continue; 971cb92c03bSAndrew Geissler } 972cb92c03bSAndrew Geissler entriesArray.push_back({}); 973cb92c03bSAndrew Geissler nlohmann::json &thisEntry = entriesArray.back(); 97466664f25SEd Tanous uint32_t *id = nullptr; 97566664f25SEd Tanous std::time_t timestamp{}; 97666664f25SEd Tanous std::string *severity = nullptr; 97766664f25SEd Tanous std::string *message = nullptr; 978cb92c03bSAndrew Geissler for (auto &propertyMap : interfaceMap.second) 979cb92c03bSAndrew Geissler { 980cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 981cb92c03bSAndrew Geissler { 982cb92c03bSAndrew Geissler id = sdbusplus::message::variant_ns::get_if< 983cb92c03bSAndrew Geissler uint32_t>(&propertyMap.second); 984cb92c03bSAndrew Geissler if (id == nullptr) 985cb92c03bSAndrew Geissler { 986cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 987cb92c03bSAndrew Geissler "Id"); 988cb92c03bSAndrew Geissler } 989cb92c03bSAndrew Geissler } 990cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 991cb92c03bSAndrew Geissler { 992cb92c03bSAndrew Geissler const uint64_t *millisTimeStamp = 993cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 994cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 995cb92c03bSAndrew Geissler { 996cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 997cb92c03bSAndrew Geissler "Timestamp"); 998271584abSEd Tanous continue; 999cb92c03bSAndrew Geissler } 1000cb92c03bSAndrew Geissler // Retrieve Created property with format: 1001cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 1002cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 1003cb92c03bSAndrew Geissler *millisTimeStamp); 1004271584abSEd Tanous timestamp = std::chrono::duration_cast< 1005271584abSEd Tanous std::chrono::duration<int>>( 1006271584abSEd Tanous chronoTimeStamp) 1007cb92c03bSAndrew Geissler .count(); 1008cb92c03bSAndrew Geissler } 1009cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1010cb92c03bSAndrew Geissler { 1011cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1012cb92c03bSAndrew Geissler &propertyMap.second); 1013cb92c03bSAndrew Geissler if (severity == nullptr) 1014cb92c03bSAndrew Geissler { 1015cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1016cb92c03bSAndrew Geissler "Severity"); 1017cb92c03bSAndrew Geissler } 1018cb92c03bSAndrew Geissler } 1019cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1020cb92c03bSAndrew Geissler { 1021cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1022cb92c03bSAndrew Geissler &propertyMap.second); 1023cb92c03bSAndrew Geissler if (message == nullptr) 1024cb92c03bSAndrew Geissler { 1025cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1026cb92c03bSAndrew Geissler "Message"); 1027cb92c03bSAndrew Geissler } 1028cb92c03bSAndrew Geissler } 1029cb92c03bSAndrew Geissler } 1030cb92c03bSAndrew Geissler thisEntry = { 1031cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1032cb92c03bSAndrew Geissler {"@odata.id", 1033cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1034cb92c03bSAndrew Geissler "Entries/" + 1035cb92c03bSAndrew Geissler std::to_string(*id)}, 103627062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1037cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1038cb92c03bSAndrew Geissler {"Message", *message}, 1039cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1040cb92c03bSAndrew Geissler {"Severity", 1041cb92c03bSAndrew Geissler translateSeverityDbusToRedfish(*severity)}, 1042cb92c03bSAndrew Geissler {"Created", crow::utility::getDateTime(timestamp)}}; 1043cb92c03bSAndrew Geissler } 1044cb92c03bSAndrew Geissler } 1045cb92c03bSAndrew Geissler std::sort(entriesArray.begin(), entriesArray.end(), 1046cb92c03bSAndrew Geissler [](const nlohmann::json &left, 1047cb92c03bSAndrew Geissler const nlohmann::json &right) { 1048cb92c03bSAndrew Geissler return (left["Id"] <= right["Id"]); 1049cb92c03bSAndrew Geissler }); 1050cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members@odata.count"] = 1051cb92c03bSAndrew Geissler entriesArray.size(); 1052cb92c03bSAndrew Geissler }, 1053cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 1054cb92c03bSAndrew Geissler "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1055c4bf6374SJason M. Bills } 1056c4bf6374SJason M. Bills }; 1057c4bf6374SJason M. Bills 105808a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node 1059c4bf6374SJason M. Bills { 1060c4bf6374SJason M. Bills public: 106108a4e4b5SAnthony Wilson DBusEventLogEntry(CrowApp &app) : 1062c4bf6374SJason M. Bills Node(app, 1063029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1064029573d4SEd Tanous std::string()) 1065c4bf6374SJason M. Bills { 1066c4bf6374SJason M. Bills entityPrivileges = { 1067c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1068c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1069c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1070c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1071c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1072c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1073c4bf6374SJason M. Bills } 1074c4bf6374SJason M. Bills 1075c4bf6374SJason M. Bills private: 1076c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1077c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 1078c4bf6374SJason M. Bills { 1079c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1080029573d4SEd Tanous if (params.size() != 1) 1081c4bf6374SJason M. Bills { 1082c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1083c4bf6374SJason M. Bills return; 1084c4bf6374SJason M. Bills } 1085029573d4SEd Tanous const std::string &entryID = params[0]; 1086cb92c03bSAndrew Geissler 1087cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1088cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1089cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1090cb92c03bSAndrew Geissler [asyncResp, entryID](const boost::system::error_code ec, 1091cb92c03bSAndrew Geissler GetManagedPropertyType &resp) { 1092cb92c03bSAndrew Geissler if (ec) 1093cb92c03bSAndrew Geissler { 1094cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1095cb92c03bSAndrew Geissler << "EventLogEntry (DBus) resp_handler got error " << ec; 1096cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1097cb92c03bSAndrew Geissler return; 1098cb92c03bSAndrew Geissler } 109966664f25SEd Tanous uint32_t *id = nullptr; 110066664f25SEd Tanous std::time_t timestamp{}; 110166664f25SEd Tanous std::string *severity = nullptr; 110266664f25SEd Tanous std::string *message = nullptr; 1103cb92c03bSAndrew Geissler for (auto &propertyMap : resp) 1104cb92c03bSAndrew Geissler { 1105cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1106cb92c03bSAndrew Geissler { 1107cb92c03bSAndrew Geissler id = std::get_if<uint32_t>(&propertyMap.second); 1108cb92c03bSAndrew Geissler if (id == nullptr) 1109cb92c03bSAndrew Geissler { 1110cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, "Id"); 1111cb92c03bSAndrew Geissler } 1112cb92c03bSAndrew Geissler } 1113cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1114cb92c03bSAndrew Geissler { 1115cb92c03bSAndrew Geissler const uint64_t *millisTimeStamp = 1116cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1117cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1118cb92c03bSAndrew Geissler { 1119cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1120cb92c03bSAndrew Geissler "Timestamp"); 1121271584abSEd Tanous continue; 1122cb92c03bSAndrew Geissler } 1123cb92c03bSAndrew Geissler // Retrieve Created property with format: 1124cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 1125cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 1126cb92c03bSAndrew Geissler *millisTimeStamp); 1127cb92c03bSAndrew Geissler timestamp = 1128271584abSEd Tanous std::chrono::duration_cast< 1129271584abSEd Tanous std::chrono::duration<int>>(chronoTimeStamp) 1130cb92c03bSAndrew Geissler .count(); 1131cb92c03bSAndrew Geissler } 1132cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1133cb92c03bSAndrew Geissler { 1134cb92c03bSAndrew Geissler severity = 1135cb92c03bSAndrew Geissler std::get_if<std::string>(&propertyMap.second); 1136cb92c03bSAndrew Geissler if (severity == nullptr) 1137cb92c03bSAndrew Geissler { 1138cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1139cb92c03bSAndrew Geissler "Severity"); 1140cb92c03bSAndrew Geissler } 1141cb92c03bSAndrew Geissler } 1142cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1143cb92c03bSAndrew Geissler { 1144cb92c03bSAndrew Geissler message = std::get_if<std::string>(&propertyMap.second); 1145cb92c03bSAndrew Geissler if (message == nullptr) 1146cb92c03bSAndrew Geissler { 1147cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1148cb92c03bSAndrew Geissler "Message"); 1149cb92c03bSAndrew Geissler } 1150cb92c03bSAndrew Geissler } 1151cb92c03bSAndrew Geissler } 1152271584abSEd Tanous if (id == nullptr || message == nullptr || severity == nullptr) 1153271584abSEd Tanous { 1154271584abSEd Tanous return; 1155271584abSEd Tanous } 1156cb92c03bSAndrew Geissler asyncResp->res.jsonValue = { 1157cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1158cb92c03bSAndrew Geissler {"@odata.id", 1159cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1160cb92c03bSAndrew Geissler "Entries/" + 1161cb92c03bSAndrew Geissler std::to_string(*id)}, 116227062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1163cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1164cb92c03bSAndrew Geissler {"Message", *message}, 1165cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1166cb92c03bSAndrew Geissler {"Severity", translateSeverityDbusToRedfish(*severity)}, 116708a4e4b5SAnthony Wilson {"Created", crow::utility::getDateTime(timestamp)}}; 1168cb92c03bSAndrew Geissler }, 1169cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1170cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1171cb92c03bSAndrew Geissler "org.freedesktop.DBus.Properties", "GetAll", 1172cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry"); 1173c4bf6374SJason M. Bills } 1174336e96c6SChicago Duan 1175336e96c6SChicago Duan void doDelete(crow::Response &res, const crow::Request &req, 1176336e96c6SChicago Duan const std::vector<std::string> ¶ms) override 1177336e96c6SChicago Duan { 1178336e96c6SChicago Duan 1179336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1180336e96c6SChicago Duan 1181336e96c6SChicago Duan auto asyncResp = std::make_shared<AsyncResp>(res); 1182336e96c6SChicago Duan 1183336e96c6SChicago Duan if (params.size() != 1) 1184336e96c6SChicago Duan { 1185336e96c6SChicago Duan messages::internalError(asyncResp->res); 1186336e96c6SChicago Duan return; 1187336e96c6SChicago Duan } 1188336e96c6SChicago Duan std::string entryID = params[0]; 1189336e96c6SChicago Duan 1190336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1191336e96c6SChicago Duan 1192336e96c6SChicago Duan // Process response from Logging service. 1193336e96c6SChicago Duan auto respHandler = [asyncResp](const boost::system::error_code ec) { 1194336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1195336e96c6SChicago Duan if (ec) 1196336e96c6SChicago Duan { 1197336e96c6SChicago Duan // TODO Handle for specific error code 1198336e96c6SChicago Duan BMCWEB_LOG_ERROR 1199336e96c6SChicago Duan << "EventLogEntry (DBus) doDelete respHandler got error " 1200336e96c6SChicago Duan << ec; 1201336e96c6SChicago Duan asyncResp->res.result( 1202336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1203336e96c6SChicago Duan return; 1204336e96c6SChicago Duan } 1205336e96c6SChicago Duan 1206336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1207336e96c6SChicago Duan }; 1208336e96c6SChicago Duan 1209336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1210336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1211336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1212336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1213336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 1214336e96c6SChicago Duan } 1215c4bf6374SJason M. Bills }; 1216c4bf6374SJason M. Bills 1217c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node 1218c4bf6374SJason M. Bills { 1219c4bf6374SJason M. Bills public: 1220c4bf6374SJason M. Bills template <typename CrowApp> 1221c4bf6374SJason M. Bills BMCLogServiceCollection(CrowApp &app) : 12224ed77cd5SEd Tanous Node(app, "/redfish/v1/Managers/bmc/LogServices/") 12231da66f75SEd Tanous { 12241da66f75SEd Tanous entityPrivileges = { 1225e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1226e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1227e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1228e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1229e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1230e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 12311da66f75SEd Tanous } 12321da66f75SEd Tanous 12331da66f75SEd Tanous private: 12341da66f75SEd Tanous /** 12351da66f75SEd Tanous * Functions triggers appropriate requests on DBus 12361da66f75SEd Tanous */ 12371da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 12381da66f75SEd Tanous const std::vector<std::string> ¶ms) override 12391da66f75SEd Tanous { 1240e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 12411da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 12421da66f75SEd Tanous // it has a duplicate entry for members 1243e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 12441da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1245e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1246e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 1247e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 1248e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 12491da66f75SEd Tanous "Collection of LogServices for this Manager"; 1250c4bf6374SJason M. Bills nlohmann::json &logServiceArray = asyncResp->res.jsonValue["Members"]; 1251c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 1252c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1253c4bf6374SJason M. Bills logServiceArray.push_back( 125408a4e4b5SAnthony Wilson {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1255c4bf6374SJason M. Bills #endif 1256e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1257c4bf6374SJason M. Bills logServiceArray.size(); 12581da66f75SEd Tanous } 12591da66f75SEd Tanous }; 12601da66f75SEd Tanous 1261c4bf6374SJason M. Bills class BMCJournalLogService : public Node 12621da66f75SEd Tanous { 12631da66f75SEd Tanous public: 12641da66f75SEd Tanous template <typename CrowApp> 1265c4bf6374SJason M. Bills BMCJournalLogService(CrowApp &app) : 1266c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1267e1f26343SJason M. Bills { 1268e1f26343SJason M. Bills entityPrivileges = { 1269e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1270e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1271e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1272e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1273e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1274e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1275e1f26343SJason M. Bills } 1276e1f26343SJason M. Bills 1277e1f26343SJason M. Bills private: 1278e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1279e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1280e1f26343SJason M. Bills { 1281e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1282e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1283e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 12840f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 12850f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 1286c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 1287c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 1288c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1289e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1290cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1291cd50aa42SJason M. Bills {"@odata.id", 1292086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 1293e1f26343SJason M. Bills } 1294e1f26343SJason M. Bills }; 1295e1f26343SJason M. Bills 1296c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string &bmcJournalLogEntryID, 1297e1f26343SJason M. Bills sd_journal *journal, 1298c4bf6374SJason M. Bills nlohmann::json &bmcJournalLogEntryJson) 1299e1f26343SJason M. Bills { 1300e1f26343SJason M. Bills // Get the Log Entry contents 1301e1f26343SJason M. Bills int ret = 0; 1302e1f26343SJason M. Bills 130339e77504SEd Tanous std::string_view msg; 130416428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1305e1f26343SJason M. Bills if (ret < 0) 1306e1f26343SJason M. Bills { 1307e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1308e1f26343SJason M. Bills return 1; 1309e1f26343SJason M. Bills } 1310e1f26343SJason M. Bills 1311e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1312271584abSEd Tanous long int severity = 8; // Default to an invalid priority 131316428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1314e1f26343SJason M. Bills if (ret < 0) 1315e1f26343SJason M. Bills { 1316e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1317e1f26343SJason M. Bills } 1318e1f26343SJason M. Bills 1319e1f26343SJason M. Bills // Get the Created time from the timestamp 132016428a1aSJason M. Bills std::string entryTimeStr; 132116428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1322e1f26343SJason M. Bills { 132316428a1aSJason M. Bills return 1; 1324e1f26343SJason M. Bills } 1325e1f26343SJason M. Bills 1326e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1327c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1328cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1329c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1330c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1331e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1332c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 133316428a1aSJason M. Bills {"Message", msg}, 1334e1f26343SJason M. Bills {"EntryType", "Oem"}, 1335e1f26343SJason M. Bills {"Severity", 1336b6a61a5eSJason M. Bills severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"}, 1337086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1338e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1339e1f26343SJason M. Bills return 0; 1340e1f26343SJason M. Bills } 1341e1f26343SJason M. Bills 1342c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node 1343e1f26343SJason M. Bills { 1344e1f26343SJason M. Bills public: 1345e1f26343SJason M. Bills template <typename CrowApp> 1346c4bf6374SJason M. Bills BMCJournalLogEntryCollection(CrowApp &app) : 1347c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1348e1f26343SJason M. Bills { 1349e1f26343SJason M. Bills entityPrivileges = { 1350e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1351e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1352e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1353e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1354e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1355e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1356e1f26343SJason M. Bills } 1357e1f26343SJason M. Bills 1358e1f26343SJason M. Bills private: 1359e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1360e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1361e1f26343SJason M. Bills { 1362e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1363193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1364271584abSEd Tanous uint64_t skip = 0; 1365271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 136616428a1aSJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1367193ad2faSJason M. Bills { 1368193ad2faSJason M. Bills return; 1369193ad2faSJason M. Bills } 137016428a1aSJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1371193ad2faSJason M. Bills { 1372193ad2faSJason M. Bills return; 1373193ad2faSJason M. Bills } 1374e1f26343SJason M. Bills // Collections don't include the static data added by SubRoute because 1375e1f26343SJason M. Bills // it has a duplicate entry for members 1376e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1377e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 13780f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 13790f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1380e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1381c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1382e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1383e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1384e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 13850f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 13860f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries"; 1387e1f26343SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 1388e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1389e1f26343SJason M. Bills 1390e1f26343SJason M. Bills // Go through the journal and use the timestamp to create a unique ID 1391e1f26343SJason M. Bills // for each entry 1392e1f26343SJason M. Bills sd_journal *journalTmp = nullptr; 1393e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1394e1f26343SJason M. Bills if (ret < 0) 1395e1f26343SJason M. Bills { 1396e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1397f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1398e1f26343SJason M. Bills return; 1399e1f26343SJason M. Bills } 1400e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1401e1f26343SJason M. Bills journalTmp, sd_journal_close); 1402e1f26343SJason M. Bills journalTmp = nullptr; 1403b01bf299SEd Tanous uint64_t entryCount = 0; 1404e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1405e85d6b16SJason M. Bills bool firstEntry = true; 1406e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1407e1f26343SJason M. Bills { 1408193ad2faSJason M. Bills entryCount++; 1409193ad2faSJason M. Bills // Handle paging using skip (number of entries to skip from the 1410193ad2faSJason M. Bills // start) and top (number of entries to display) 1411193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1412193ad2faSJason M. Bills { 1413193ad2faSJason M. Bills continue; 1414193ad2faSJason M. Bills } 1415193ad2faSJason M. Bills 141616428a1aSJason M. Bills std::string idStr; 1417e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1418e1f26343SJason M. Bills { 1419e1f26343SJason M. Bills continue; 1420e1f26343SJason M. Bills } 1421e1f26343SJason M. Bills 1422e85d6b16SJason M. Bills if (firstEntry) 1423e85d6b16SJason M. Bills { 1424e85d6b16SJason M. Bills firstEntry = false; 1425e85d6b16SJason M. Bills } 1426e85d6b16SJason M. Bills 1427e1f26343SJason M. Bills logEntryArray.push_back({}); 1428c4bf6374SJason M. Bills nlohmann::json &bmcJournalLogEntry = logEntryArray.back(); 1429c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1430c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1431e1f26343SJason M. Bills { 1432f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1433e1f26343SJason M. Bills return; 1434e1f26343SJason M. Bills } 1435e1f26343SJason M. Bills } 1436193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1437193ad2faSJason M. Bills if (skip + top < entryCount) 1438193ad2faSJason M. Bills { 1439193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 1440c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 1441193ad2faSJason M. Bills std::to_string(skip + top); 1442193ad2faSJason M. Bills } 1443e1f26343SJason M. Bills } 1444e1f26343SJason M. Bills }; 1445e1f26343SJason M. Bills 1446c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node 1447e1f26343SJason M. Bills { 1448e1f26343SJason M. Bills public: 1449c4bf6374SJason M. Bills BMCJournalLogEntry(CrowApp &app) : 1450c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/", 1451e1f26343SJason M. Bills std::string()) 1452e1f26343SJason M. Bills { 1453e1f26343SJason M. Bills entityPrivileges = { 1454e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1455e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1456e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1457e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1458e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1459e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1460e1f26343SJason M. Bills } 1461e1f26343SJason M. Bills 1462e1f26343SJason M. Bills private: 1463e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1464e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1465e1f26343SJason M. Bills { 1466e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1467e1f26343SJason M. Bills if (params.size() != 1) 1468e1f26343SJason M. Bills { 1469f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1470e1f26343SJason M. Bills return; 1471e1f26343SJason M. Bills } 147216428a1aSJason M. Bills const std::string &entryID = params[0]; 1473e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1474e1f26343SJason M. Bills uint64_t ts = 0; 1475271584abSEd Tanous uint64_t index = 0; 147616428a1aSJason M. Bills if (!getTimestampFromID(asyncResp->res, entryID, ts, index)) 1477e1f26343SJason M. Bills { 147816428a1aSJason M. Bills return; 1479e1f26343SJason M. Bills } 1480e1f26343SJason M. Bills 1481e1f26343SJason M. Bills sd_journal *journalTmp = nullptr; 1482e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1483e1f26343SJason M. Bills if (ret < 0) 1484e1f26343SJason M. Bills { 1485e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1486f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1487e1f26343SJason M. Bills return; 1488e1f26343SJason M. Bills } 1489e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1490e1f26343SJason M. Bills journalTmp, sd_journal_close); 1491e1f26343SJason M. Bills journalTmp = nullptr; 1492e1f26343SJason M. Bills // Go to the timestamp in the log and move to the entry at the index 1493af07e3f5SJason M. Bills // tracking the unique ID 1494af07e3f5SJason M. Bills std::string idStr; 1495af07e3f5SJason M. Bills bool firstEntry = true; 1496e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 1497271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 1498e1f26343SJason M. Bills { 1499e1f26343SJason M. Bills sd_journal_next(journal.get()); 1500af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1501af07e3f5SJason M. Bills { 1502af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 1503af07e3f5SJason M. Bills return; 1504af07e3f5SJason M. Bills } 1505af07e3f5SJason M. Bills if (firstEntry) 1506af07e3f5SJason M. Bills { 1507af07e3f5SJason M. Bills firstEntry = false; 1508af07e3f5SJason M. Bills } 1509e1f26343SJason M. Bills } 1510c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 1511af07e3f5SJason M. Bills if (idStr != entryID) 1512c4bf6374SJason M. Bills { 1513c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 1514c4bf6374SJason M. Bills return; 1515c4bf6374SJason M. Bills } 1516c4bf6374SJason M. Bills 1517c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 1518e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 1519e1f26343SJason M. Bills { 1520f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1521e1f26343SJason M. Bills return; 1522e1f26343SJason M. Bills } 1523e1f26343SJason M. Bills } 1524e1f26343SJason M. Bills }; 1525e1f26343SJason M. Bills 1526424c4176SJason M. Bills class CrashdumpService : public Node 1527e1f26343SJason M. Bills { 1528e1f26343SJason M. Bills public: 1529e1f26343SJason M. Bills template <typename CrowApp> 1530424c4176SJason M. Bills CrashdumpService(CrowApp &app) : 1531424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 15321da66f75SEd Tanous { 1533*3946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 1534*3946028dSAppaRao Puli // method for security reasons. 15351da66f75SEd Tanous entityPrivileges = { 1536*3946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 1537*3946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 1538e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1539e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1540e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1541e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 15421da66f75SEd Tanous } 15431da66f75SEd Tanous 15441da66f75SEd Tanous private: 15451da66f75SEd Tanous /** 15461da66f75SEd Tanous * Functions triggers appropriate requests on DBus 15471da66f75SEd Tanous */ 15481da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 15491da66f75SEd Tanous const std::vector<std::string> ¶ms) override 15501da66f75SEd Tanous { 1551e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 15521da66f75SEd Tanous // Copy over the static data to include the entries added by SubRoute 15530f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1554424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 1555e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1556e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 15574f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 15584f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 15594f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 1560e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1561e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 1562cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1563cd50aa42SJason M. Bills {"@odata.id", 1564424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 1565e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 15665b61b5e8SJason M. Bills {"#LogService.ClearLog", 15675b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 15685b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 15691da66f75SEd Tanous {"Oem", 1570424c4176SJason M. Bills {{"#Crashdump.OnDemand", 1571424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 1572424c4176SJason M. Bills "Actions/Oem/Crashdump.OnDemand"}}}}}}; 15731da66f75SEd Tanous 15741da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI 1575e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"]["Oem"].push_back( 1576424c4176SJason M. Bills {"#Crashdump.SendRawPeci", 157708a4e4b5SAnthony Wilson {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 1578424c4176SJason M. Bills "Actions/Oem/Crashdump.SendRawPeci"}}}); 15791da66f75SEd Tanous #endif 15801da66f75SEd Tanous } 15811da66f75SEd Tanous }; 15821da66f75SEd Tanous 15835b61b5e8SJason M. Bills class CrashdumpClear : public Node 15845b61b5e8SJason M. Bills { 15855b61b5e8SJason M. Bills public: 15865b61b5e8SJason M. Bills CrashdumpClear(CrowApp &app) : 15875b61b5e8SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 15885b61b5e8SJason M. Bills "LogService.ClearLog/") 15895b61b5e8SJason M. Bills { 1590*3946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 1591*3946028dSAppaRao Puli // method for security reasons. 15925b61b5e8SJason M. Bills entityPrivileges = { 1593*3946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 1594*3946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 15955b61b5e8SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 15965b61b5e8SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 15975b61b5e8SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 15985b61b5e8SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 15995b61b5e8SJason M. Bills } 16005b61b5e8SJason M. Bills 16015b61b5e8SJason M. Bills private: 16025b61b5e8SJason M. Bills void doPost(crow::Response &res, const crow::Request &req, 16035b61b5e8SJason M. Bills const std::vector<std::string> ¶ms) override 16045b61b5e8SJason M. Bills { 16055b61b5e8SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 16065b61b5e8SJason M. Bills 16075b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 16085b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 16095b61b5e8SJason M. Bills const std::string &resp) { 16105b61b5e8SJason M. Bills if (ec) 16115b61b5e8SJason M. Bills { 16125b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 16135b61b5e8SJason M. Bills return; 16145b61b5e8SJason M. Bills } 16155b61b5e8SJason M. Bills messages::success(asyncResp->res); 16165b61b5e8SJason M. Bills }, 16175b61b5e8SJason M. Bills crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 16185b61b5e8SJason M. Bills } 16195b61b5e8SJason M. Bills }; 16205b61b5e8SJason M. Bills 1621e855dd28SJason M. Bills static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp, 1622e855dd28SJason M. Bills const std::string &logID, 1623e855dd28SJason M. Bills nlohmann::json &logEntryJson) 1624e855dd28SJason M. Bills { 1625043a0536SJohnathan Mantey auto getStoredLogCallback = 1626043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 1627e855dd28SJason M. Bills const boost::system::error_code ec, 1628043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>> ¶ms) { 1629e855dd28SJason M. Bills if (ec) 1630e855dd28SJason M. Bills { 1631e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 16321ddcf01aSJason M. Bills if (ec.value() == 16331ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 16341ddcf01aSJason M. Bills { 1635043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 1636043a0536SJohnathan Mantey logID); 16371ddcf01aSJason M. Bills } 16381ddcf01aSJason M. Bills else 16391ddcf01aSJason M. Bills { 1640e855dd28SJason M. Bills messages::internalError(asyncResp->res); 16411ddcf01aSJason M. Bills } 1642e855dd28SJason M. Bills return; 1643e855dd28SJason M. Bills } 1644043a0536SJohnathan Mantey 1645043a0536SJohnathan Mantey std::string timestamp{}; 1646043a0536SJohnathan Mantey std::string filename{}; 1647043a0536SJohnathan Mantey std::string logfile{}; 1648043a0536SJohnathan Mantey ParseCrashdumpParameters(params, filename, timestamp, logfile); 1649043a0536SJohnathan Mantey 1650043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 1651e855dd28SJason M. Bills { 1652043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 1653e855dd28SJason M. Bills return; 1654e855dd28SJason M. Bills } 1655e855dd28SJason M. Bills 1656043a0536SJohnathan Mantey std::string crashdumpURI = 1657e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 1658043a0536SJohnathan Mantey logID + "/" + filename; 1659043a0536SJohnathan Mantey logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1660043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 1661043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 1662e855dd28SJason M. Bills logID}, 1663e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 1664e855dd28SJason M. Bills {"Id", logID}, 1665e855dd28SJason M. Bills {"EntryType", "Oem"}, 1666e855dd28SJason M. Bills {"OemRecordFormat", "Crashdump URI"}, 1667043a0536SJohnathan Mantey {"Message", std::move(crashdumpURI)}, 1668043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 1669e855dd28SJason M. Bills }; 1670e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 16715b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 16725b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 1673043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 1674e855dd28SJason M. Bills } 1675e855dd28SJason M. Bills 1676424c4176SJason M. Bills class CrashdumpEntryCollection : public Node 16771da66f75SEd Tanous { 16781da66f75SEd Tanous public: 16791da66f75SEd Tanous template <typename CrowApp> 1680424c4176SJason M. Bills CrashdumpEntryCollection(CrowApp &app) : 1681424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 16821da66f75SEd Tanous { 1683*3946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 1684*3946028dSAppaRao Puli // method for security reasons. 16851da66f75SEd Tanous entityPrivileges = { 1686*3946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 1687*3946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 1688e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1689e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1690e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1691e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 16921da66f75SEd Tanous } 16931da66f75SEd Tanous 16941da66f75SEd Tanous private: 16951da66f75SEd Tanous /** 16961da66f75SEd Tanous * Functions triggers appropriate requests on DBus 16971da66f75SEd Tanous */ 16981da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 16991da66f75SEd Tanous const std::vector<std::string> ¶ms) override 17001da66f75SEd Tanous { 1701e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 17021da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 17031da66f75SEd Tanous // it has a duplicate entry for members 1704e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 1705e1f26343SJason M. Bills const boost::system::error_code ec, 17061da66f75SEd Tanous const std::vector<std::string> &resp) { 17071da66f75SEd Tanous if (ec) 17081da66f75SEd Tanous { 17091da66f75SEd Tanous if (ec.value() != 17101da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 17111da66f75SEd Tanous { 17121da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 17131da66f75SEd Tanous << ec.message(); 1714f12894f8SJason M. Bills messages::internalError(asyncResp->res); 17151da66f75SEd Tanous return; 17161da66f75SEd Tanous } 17171da66f75SEd Tanous } 1718e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 17191da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 17200f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1721424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 1722424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 1723e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1724424c4176SJason M. Bills "Collection of Crashdump Entries"; 1725e1f26343SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 1726e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1727e855dd28SJason M. Bills std::vector<std::string> logIDs; 1728e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 1729e855dd28SJason M. Bills // enough to hold them 17301da66f75SEd Tanous for (const std::string &objpath : resp) 17311da66f75SEd Tanous { 1732e855dd28SJason M. Bills // Get the log ID 17334ed77cd5SEd Tanous std::size_t lastPos = objpath.rfind("/"); 1734e855dd28SJason M. Bills if (lastPos == std::string::npos) 17351da66f75SEd Tanous { 1736e855dd28SJason M. Bills continue; 17371da66f75SEd Tanous } 1738e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 1739e855dd28SJason M. Bills 1740e855dd28SJason M. Bills // Add a space for the log entry to the array 1741e855dd28SJason M. Bills logEntryArray.push_back({}); 1742e855dd28SJason M. Bills } 1743e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 1744e855dd28SJason M. Bills size_t index = 0; 1745e855dd28SJason M. Bills for (const std::string &logID : logIDs) 1746e855dd28SJason M. Bills { 1747e855dd28SJason M. Bills // Add the log entry to the array 1748e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 17491da66f75SEd Tanous } 1750e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1751e1f26343SJason M. Bills logEntryArray.size(); 17521da66f75SEd Tanous }; 17531da66f75SEd Tanous crow::connections::systemBus->async_method_call( 17541da66f75SEd Tanous std::move(getLogEntriesCallback), 17551da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 17561da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 17571da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 17585b61b5e8SJason M. Bills std::array<const char *, 1>{crashdumpInterface}); 17591da66f75SEd Tanous } 17601da66f75SEd Tanous }; 17611da66f75SEd Tanous 1762424c4176SJason M. Bills class CrashdumpEntry : public Node 17631da66f75SEd Tanous { 17641da66f75SEd Tanous public: 1765424c4176SJason M. Bills CrashdumpEntry(CrowApp &app) : 1766d53dd41fSJason M. Bills Node(app, 1767424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/", 17681da66f75SEd Tanous std::string()) 17691da66f75SEd Tanous { 1770*3946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 1771*3946028dSAppaRao Puli // method for security reasons. 17721da66f75SEd Tanous entityPrivileges = { 1773*3946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 1774*3946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 1775e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1776e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1777e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1778e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 17791da66f75SEd Tanous } 17801da66f75SEd Tanous 17811da66f75SEd Tanous private: 17821da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 17831da66f75SEd Tanous const std::vector<std::string> ¶ms) override 17841da66f75SEd Tanous { 1785e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 17861da66f75SEd Tanous if (params.size() != 1) 17871da66f75SEd Tanous { 1788f12894f8SJason M. Bills messages::internalError(asyncResp->res); 17891da66f75SEd Tanous return; 17901da66f75SEd Tanous } 1791e855dd28SJason M. Bills const std::string &logID = params[0]; 1792e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 1793e855dd28SJason M. Bills } 1794e855dd28SJason M. Bills }; 1795e855dd28SJason M. Bills 1796e855dd28SJason M. Bills class CrashdumpFile : public Node 1797e855dd28SJason M. Bills { 1798e855dd28SJason M. Bills public: 1799e855dd28SJason M. Bills CrashdumpFile(CrowApp &app) : 1800e855dd28SJason M. Bills Node(app, 1801e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/" 1802e855dd28SJason M. Bills "<str>/", 1803e855dd28SJason M. Bills std::string(), std::string()) 1804e855dd28SJason M. Bills { 1805*3946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 1806*3946028dSAppaRao Puli // method for security reasons. 1807e855dd28SJason M. Bills entityPrivileges = { 1808*3946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 1809*3946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 1810e855dd28SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1811e855dd28SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1812e855dd28SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1813e855dd28SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1814e855dd28SJason M. Bills } 1815e855dd28SJason M. Bills 1816e855dd28SJason M. Bills private: 1817e855dd28SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1818e855dd28SJason M. Bills const std::vector<std::string> ¶ms) override 1819e855dd28SJason M. Bills { 1820e855dd28SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1821e855dd28SJason M. Bills if (params.size() != 2) 1822e855dd28SJason M. Bills { 1823e855dd28SJason M. Bills messages::internalError(asyncResp->res); 1824e855dd28SJason M. Bills return; 1825e855dd28SJason M. Bills } 1826e855dd28SJason M. Bills const std::string &logID = params[0]; 1827e855dd28SJason M. Bills const std::string &fileName = params[1]; 1828e855dd28SJason M. Bills 1829043a0536SJohnathan Mantey auto getStoredLogCallback = 1830043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 1831abf2add6SEd Tanous const boost::system::error_code ec, 1832043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>> &resp) { 18331da66f75SEd Tanous if (ec) 18341da66f75SEd Tanous { 1835043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 1836043a0536SJohnathan Mantey << ec.message(); 1837f12894f8SJason M. Bills messages::internalError(asyncResp->res); 18381da66f75SEd Tanous return; 18391da66f75SEd Tanous } 1840e855dd28SJason M. Bills 1841043a0536SJohnathan Mantey std::string dbusFilename{}; 1842043a0536SJohnathan Mantey std::string dbusTimestamp{}; 1843043a0536SJohnathan Mantey std::string dbusFilepath{}; 1844043a0536SJohnathan Mantey 1845043a0536SJohnathan Mantey ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 1846043a0536SJohnathan Mantey dbusFilepath); 1847043a0536SJohnathan Mantey 1848043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 1849043a0536SJohnathan Mantey dbusFilepath.empty()) 18501da66f75SEd Tanous { 1851e855dd28SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, fileName); 18521da66f75SEd Tanous return; 18531da66f75SEd Tanous } 1854e855dd28SJason M. Bills 1855043a0536SJohnathan Mantey // Verify the file name parameter is correct 1856043a0536SJohnathan Mantey if (fileName != dbusFilename) 1857043a0536SJohnathan Mantey { 1858043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 1859043a0536SJohnathan Mantey return; 1860043a0536SJohnathan Mantey } 1861043a0536SJohnathan Mantey 1862043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 1863043a0536SJohnathan Mantey { 1864043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 1865043a0536SJohnathan Mantey return; 1866043a0536SJohnathan Mantey } 1867043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 1868043a0536SJohnathan Mantey std::ios::binary | 1869043a0536SJohnathan Mantey std::ios::ate); 1870043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 1871043a0536SJohnathan Mantey if (fileSize < 0) 1872043a0536SJohnathan Mantey { 1873043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 1874043a0536SJohnathan Mantey return; 1875043a0536SJohnathan Mantey } 1876043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 1877043a0536SJohnathan Mantey 1878043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 1879043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 1880043a0536SJohnathan Mantey 1881043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 1882043a0536SJohnathan Mantey 1883043a0536SJohnathan Mantey // The cast to std::string is intentional in order to use the 1884043a0536SJohnathan Mantey // assign() that applies move mechanics 1885043a0536SJohnathan Mantey asyncResp->res.body().assign( 1886043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 1887043a0536SJohnathan Mantey 1888043a0536SJohnathan Mantey // Configure this to be a file download when accessed from 1889043a0536SJohnathan Mantey // a browser 1890e855dd28SJason M. Bills asyncResp->res.addHeader("Content-Disposition", "attachment"); 18911da66f75SEd Tanous }; 18921da66f75SEd Tanous crow::connections::systemBus->async_method_call( 18935b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 18945b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 1895043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 18961da66f75SEd Tanous } 18971da66f75SEd Tanous }; 18981da66f75SEd Tanous 1899424c4176SJason M. Bills class OnDemandCrashdump : public Node 19001da66f75SEd Tanous { 19011da66f75SEd Tanous public: 1902424c4176SJason M. Bills OnDemandCrashdump(CrowApp &app) : 1903424c4176SJason M. Bills Node(app, 1904424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 1905424c4176SJason M. Bills "Crashdump.OnDemand/") 19061da66f75SEd Tanous { 1907*3946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 1908*3946028dSAppaRao Puli // method for security reasons. 19091da66f75SEd Tanous entityPrivileges = { 1910*3946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 1911*3946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 1912*3946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 1913*3946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 1914*3946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 1915*3946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 19161da66f75SEd Tanous } 19171da66f75SEd Tanous 19181da66f75SEd Tanous private: 19191da66f75SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 19201da66f75SEd Tanous const std::vector<std::string> ¶ms) override 19211da66f75SEd Tanous { 1922e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 19231da66f75SEd Tanous 1924fe306728SJames Feist auto generateonDemandLogCallback = [asyncResp, 1925fe306728SJames Feist req](const boost::system::error_code 192646229577SJames Feist ec, 19271da66f75SEd Tanous const std::string &resp) { 19281da66f75SEd Tanous if (ec) 19291da66f75SEd Tanous { 193046229577SJames Feist if (ec.value() == boost::system::errc::operation_not_supported) 19311da66f75SEd Tanous { 1932f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 19331da66f75SEd Tanous } 19344363d3b2SJason M. Bills else if (ec.value() == 19354363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 19364363d3b2SJason M. Bills { 19374363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 19384363d3b2SJason M. Bills "60"); 19394363d3b2SJason M. Bills } 19401da66f75SEd Tanous else 19411da66f75SEd Tanous { 1942f12894f8SJason M. Bills messages::internalError(asyncResp->res); 19431da66f75SEd Tanous } 19441da66f75SEd Tanous return; 19451da66f75SEd Tanous } 194646229577SJames Feist std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 194766afe4faSJames Feist [](boost::system::error_code err, sdbusplus::message::message &, 194866afe4faSJames Feist const std::shared_ptr<task::TaskData> &taskData) { 194966afe4faSJames Feist if (!err) 195066afe4faSJames Feist { 195166afe4faSJames Feist taskData->messages.emplace_back(messages::success()); 1952831d6b09SJames Feist taskData->state = "Completed"; 195366afe4faSJames Feist } 195432898ceaSJames Feist return task::completed; 195566afe4faSJames Feist }, 195646229577SJames Feist "type='signal',interface='org.freedesktop.DBus.Properties'," 195746229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 195846229577SJames Feist "crashdump'"); 195946229577SJames Feist task->startTimer(std::chrono::minutes(5)); 196046229577SJames Feist task->populateResp(asyncResp->res); 1961fe306728SJames Feist task->payload.emplace(req); 19621da66f75SEd Tanous }; 19631da66f75SEd Tanous crow::connections::systemBus->async_method_call( 19645b61b5e8SJason M. Bills std::move(generateonDemandLogCallback), crashdumpObject, 19655b61b5e8SJason M. Bills crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog"); 19661da66f75SEd Tanous } 19671da66f75SEd Tanous }; 19681da66f75SEd Tanous 1969e1f26343SJason M. Bills class SendRawPECI : public Node 19701da66f75SEd Tanous { 19711da66f75SEd Tanous public: 1972e1f26343SJason M. Bills SendRawPECI(CrowApp &app) : 1973424c4176SJason M. Bills Node(app, 1974424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 1975424c4176SJason M. Bills "Crashdump.SendRawPeci/") 19761da66f75SEd Tanous { 1977*3946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 1978*3946028dSAppaRao Puli // method for security reasons. 19791da66f75SEd Tanous entityPrivileges = { 19801da66f75SEd Tanous {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 19811da66f75SEd Tanous {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 19821da66f75SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 19831da66f75SEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 19841da66f75SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 19851da66f75SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 19861da66f75SEd Tanous } 19871da66f75SEd Tanous 19881da66f75SEd Tanous private: 19891da66f75SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 19901da66f75SEd Tanous const std::vector<std::string> ¶ms) override 19911da66f75SEd Tanous { 1992e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 19938724c297SKarthick Sundarrajan std::vector<std::vector<uint8_t>> peciCommands; 19948724c297SKarthick Sundarrajan 19958724c297SKarthick Sundarrajan nlohmann::json reqJson = 19968724c297SKarthick Sundarrajan nlohmann::json::parse(req.body, nullptr, false); 19978724c297SKarthick Sundarrajan if (reqJson.find("PECICommands") != reqJson.end()) 19988724c297SKarthick Sundarrajan { 19998724c297SKarthick Sundarrajan if (!json_util::readJson(req, res, "PECICommands", peciCommands)) 20008724c297SKarthick Sundarrajan { 20018724c297SKarthick Sundarrajan return; 20028724c297SKarthick Sundarrajan } 20038724c297SKarthick Sundarrajan uint32_t idx = 0; 20048724c297SKarthick Sundarrajan for (auto const &cmd : peciCommands) 20058724c297SKarthick Sundarrajan { 20068724c297SKarthick Sundarrajan if (cmd.size() < 3) 20078724c297SKarthick Sundarrajan { 20088724c297SKarthick Sundarrajan std::string s("["); 20098724c297SKarthick Sundarrajan for (auto const &val : cmd) 20108724c297SKarthick Sundarrajan { 20118724c297SKarthick Sundarrajan if (val != *cmd.begin()) 20128724c297SKarthick Sundarrajan { 20138724c297SKarthick Sundarrajan s += ","; 20148724c297SKarthick Sundarrajan } 20158724c297SKarthick Sundarrajan s += std::to_string(val); 20168724c297SKarthick Sundarrajan } 20178724c297SKarthick Sundarrajan s += "]"; 20188724c297SKarthick Sundarrajan messages::actionParameterValueFormatError( 20198724c297SKarthick Sundarrajan res, s, "PECICommands[" + std::to_string(idx) + "]", 20208724c297SKarthick Sundarrajan "SendRawPeci"); 20218724c297SKarthick Sundarrajan return; 20228724c297SKarthick Sundarrajan } 20238724c297SKarthick Sundarrajan idx++; 20248724c297SKarthick Sundarrajan } 20258724c297SKarthick Sundarrajan } 20268724c297SKarthick Sundarrajan else 20278724c297SKarthick Sundarrajan { 20288724c297SKarthick Sundarrajan /* This interface is deprecated */ 2029b1556427SEd Tanous uint8_t clientAddress = 0; 2030b1556427SEd Tanous uint8_t readLength = 0; 20311da66f75SEd Tanous std::vector<uint8_t> peciCommand; 2032b1556427SEd Tanous if (!json_util::readJson(req, res, "ClientAddress", clientAddress, 2033b1556427SEd Tanous "ReadLength", readLength, "PECICommand", 2034b1556427SEd Tanous peciCommand)) 20351da66f75SEd Tanous { 20361da66f75SEd Tanous return; 20371da66f75SEd Tanous } 20388724c297SKarthick Sundarrajan peciCommands.push_back({clientAddress, 0, readLength}); 20398724c297SKarthick Sundarrajan peciCommands[0].insert(peciCommands[0].end(), peciCommand.begin(), 20408724c297SKarthick Sundarrajan peciCommand.end()); 20418724c297SKarthick Sundarrajan } 20421da66f75SEd Tanous // Callback to return the Raw PECI response 2043e1f26343SJason M. Bills auto sendRawPECICallback = 2044e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 20458724c297SKarthick Sundarrajan const std::vector<std::vector<uint8_t>> &resp) { 20461da66f75SEd Tanous if (ec) 20471da66f75SEd Tanous { 20488724c297SKarthick Sundarrajan BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: " 20491da66f75SEd Tanous << ec.message(); 2050f12894f8SJason M. Bills messages::internalError(asyncResp->res); 20511da66f75SEd Tanous return; 20521da66f75SEd Tanous } 2053e1f26343SJason M. Bills asyncResp->res.jsonValue = {{"Name", "PECI Command Response"}, 20541da66f75SEd Tanous {"PECIResponse", resp}}; 20551da66f75SEd Tanous }; 20561da66f75SEd Tanous // Call the SendRawPECI command with the provided data 20571da66f75SEd Tanous crow::connections::systemBus->async_method_call( 20585b61b5e8SJason M. Bills std::move(sendRawPECICallback), crashdumpObject, crashdumpPath, 20598724c297SKarthick Sundarrajan crashdumpRawPECIInterface, "SendRawPeci", peciCommands); 20601da66f75SEd Tanous } 20611da66f75SEd Tanous }; 20621da66f75SEd Tanous 2063cb92c03bSAndrew Geissler /** 2064cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2065cb92c03bSAndrew Geissler */ 2066cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node 2067cb92c03bSAndrew Geissler { 2068cb92c03bSAndrew Geissler public: 2069cb92c03bSAndrew Geissler DBusLogServiceActionsClear(CrowApp &app) : 2070cb92c03bSAndrew Geissler Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 20717af91514SGunnar Mills "LogService.ClearLog/") 2072cb92c03bSAndrew Geissler { 2073cb92c03bSAndrew Geissler entityPrivileges = { 2074cb92c03bSAndrew Geissler {boost::beast::http::verb::get, {{"Login"}}}, 2075cb92c03bSAndrew Geissler {boost::beast::http::verb::head, {{"Login"}}}, 2076cb92c03bSAndrew Geissler {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2077cb92c03bSAndrew Geissler {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2078cb92c03bSAndrew Geissler {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2079cb92c03bSAndrew Geissler {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2080cb92c03bSAndrew Geissler } 2081cb92c03bSAndrew Geissler 2082cb92c03bSAndrew Geissler private: 2083cb92c03bSAndrew Geissler /** 2084cb92c03bSAndrew Geissler * Function handles POST method request. 2085cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2086cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2087cb92c03bSAndrew Geissler */ 2088cb92c03bSAndrew Geissler void doPost(crow::Response &res, const crow::Request &req, 2089cb92c03bSAndrew Geissler const std::vector<std::string> ¶ms) override 2090cb92c03bSAndrew Geissler { 2091cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2092cb92c03bSAndrew Geissler 2093cb92c03bSAndrew Geissler auto asyncResp = std::make_shared<AsyncResp>(res); 2094cb92c03bSAndrew Geissler // Process response from Logging service. 2095cb92c03bSAndrew Geissler auto resp_handler = [asyncResp](const boost::system::error_code ec) { 2096cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 2097cb92c03bSAndrew Geissler if (ec) 2098cb92c03bSAndrew Geissler { 2099cb92c03bSAndrew Geissler // TODO Handle for specific error code 2100cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 2101cb92c03bSAndrew Geissler asyncResp->res.result( 2102cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2103cb92c03bSAndrew Geissler return; 2104cb92c03bSAndrew Geissler } 2105cb92c03bSAndrew Geissler 2106cb92c03bSAndrew Geissler asyncResp->res.result(boost::beast::http::status::no_content); 2107cb92c03bSAndrew Geissler }; 2108cb92c03bSAndrew Geissler 2109cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2110cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 2111cb92c03bSAndrew Geissler resp_handler, "xyz.openbmc_project.Logging", 2112cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2113cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 2114cb92c03bSAndrew Geissler } 2115cb92c03bSAndrew Geissler }; 2116a3316fc6SZhikuiRen 2117a3316fc6SZhikuiRen /**************************************************** 2118a3316fc6SZhikuiRen * Redfish PostCode interfaces 2119a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2120a3316fc6SZhikuiRen ******************************************************/ 2121a3316fc6SZhikuiRen class PostCodesLogService : public Node 2122a3316fc6SZhikuiRen { 2123a3316fc6SZhikuiRen public: 2124a3316fc6SZhikuiRen PostCodesLogService(CrowApp &app) : 2125a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2126a3316fc6SZhikuiRen { 2127a3316fc6SZhikuiRen entityPrivileges = { 2128a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2129a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2130a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2131a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2132a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2133a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2134a3316fc6SZhikuiRen } 2135a3316fc6SZhikuiRen 2136a3316fc6SZhikuiRen private: 2137a3316fc6SZhikuiRen void doGet(crow::Response &res, const crow::Request &req, 2138a3316fc6SZhikuiRen const std::vector<std::string> ¶ms) override 2139a3316fc6SZhikuiRen { 2140a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2141a3316fc6SZhikuiRen 2142a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 2143a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"}, 2144a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 2145a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"}, 2146a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 2147a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 2148a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 2149a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 2150a3316fc6SZhikuiRen {"Entries", 2151a3316fc6SZhikuiRen {{"@odata.id", 2152a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}}; 2153a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 2154a3316fc6SZhikuiRen {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/" 2155a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 2156a3316fc6SZhikuiRen } 2157a3316fc6SZhikuiRen }; 2158a3316fc6SZhikuiRen 2159a3316fc6SZhikuiRen class PostCodesClear : public Node 2160a3316fc6SZhikuiRen { 2161a3316fc6SZhikuiRen public: 2162a3316fc6SZhikuiRen PostCodesClear(CrowApp &app) : 2163a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 2164a3316fc6SZhikuiRen "LogService.ClearLog/") 2165a3316fc6SZhikuiRen { 2166a3316fc6SZhikuiRen entityPrivileges = { 2167a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2168a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2169*3946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 2170*3946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 2171*3946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 2172*3946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 2173a3316fc6SZhikuiRen } 2174a3316fc6SZhikuiRen 2175a3316fc6SZhikuiRen private: 2176a3316fc6SZhikuiRen void doPost(crow::Response &res, const crow::Request &req, 2177a3316fc6SZhikuiRen const std::vector<std::string> ¶ms) override 2178a3316fc6SZhikuiRen { 2179a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 2180a3316fc6SZhikuiRen 2181a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2182a3316fc6SZhikuiRen // Make call to post-code service to request clear all 2183a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2184a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 2185a3316fc6SZhikuiRen if (ec) 2186a3316fc6SZhikuiRen { 2187a3316fc6SZhikuiRen // TODO Handle for specific error code 2188a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 2189a3316fc6SZhikuiRen << "doClearPostCodes resp_handler got error " << ec; 2190a3316fc6SZhikuiRen asyncResp->res.result( 2191a3316fc6SZhikuiRen boost::beast::http::status::internal_server_error); 2192a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 2193a3316fc6SZhikuiRen return; 2194a3316fc6SZhikuiRen } 2195a3316fc6SZhikuiRen }, 2196a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2197a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2198a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 2199a3316fc6SZhikuiRen } 2200a3316fc6SZhikuiRen }; 2201a3316fc6SZhikuiRen 2202a3316fc6SZhikuiRen static void fillPostCodeEntry( 2203a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> aResp, 2204a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t> &postcode, 2205a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 2206a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 2207a3316fc6SZhikuiRen { 2208a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 2209a3316fc6SZhikuiRen const message_registries::Message *message = 2210a3316fc6SZhikuiRen message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode"); 2211a3316fc6SZhikuiRen std::string severity; 2212a3316fc6SZhikuiRen if (message != nullptr) 2213a3316fc6SZhikuiRen { 2214a3316fc6SZhikuiRen severity = message->severity; 2215a3316fc6SZhikuiRen } 2216a3316fc6SZhikuiRen 2217a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 2218a3316fc6SZhikuiRen nlohmann::json &logEntryArray = aResp->res.jsonValue["Members"]; 2219a3316fc6SZhikuiRen 2220a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 2221a3316fc6SZhikuiRen for (const std::pair<uint64_t, uint64_t> &code : postcode) 2222a3316fc6SZhikuiRen { 2223a3316fc6SZhikuiRen currentCodeIndex++; 2224a3316fc6SZhikuiRen std::string postcodeEntryID = 2225a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 2226a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 2227a3316fc6SZhikuiRen 2228a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 2229a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 2230a3316fc6SZhikuiRen 2231a3316fc6SZhikuiRen if (1 == currentCodeIndex) 2232a3316fc6SZhikuiRen { // already incremented 2233a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 2234a3316fc6SZhikuiRen } 2235a3316fc6SZhikuiRen else 2236a3316fc6SZhikuiRen { 2237a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 2238a3316fc6SZhikuiRen } 2239a3316fc6SZhikuiRen 2240a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 2241a3316fc6SZhikuiRen // not fall between top and skip 2242a3316fc6SZhikuiRen if ((codeIndex == 0) && 2243a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 2244a3316fc6SZhikuiRen { 2245a3316fc6SZhikuiRen continue; 2246a3316fc6SZhikuiRen } 2247a3316fc6SZhikuiRen 2248a3316fc6SZhikuiRen // skip if a sepcific codeIndex is specified and does not match the 2249a3316fc6SZhikuiRen // currentIndex 2250a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 2251a3316fc6SZhikuiRen { 2252a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 2253a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 2254a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 2255a3316fc6SZhikuiRen continue; 2256a3316fc6SZhikuiRen } 2257a3316fc6SZhikuiRen 2258a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 2259a3316fc6SZhikuiRen // index 2260a3316fc6SZhikuiRen 2261a3316fc6SZhikuiRen // Get the Created time from the timestamp 2262a3316fc6SZhikuiRen std::string entryTimeStr; 2263a3316fc6SZhikuiRen if (!getTimestampStr(usecSinceEpoch, entryTimeStr)) 2264a3316fc6SZhikuiRen { 2265a3316fc6SZhikuiRen continue; 2266a3316fc6SZhikuiRen } 2267a3316fc6SZhikuiRen 2268a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 2269a3316fc6SZhikuiRen std::ostringstream hexCode; 2270a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 2271a3316fc6SZhikuiRen << code.second; 2272a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 2273a3316fc6SZhikuiRen // Set Fixed -Point Notation 2274a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 2275a3316fc6SZhikuiRen // Set precision to 4 digits 2276a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 2277a3316fc6SZhikuiRen // Add double to stream 2278a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 2279a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 2280a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 2281a3316fc6SZhikuiRen 2282a3316fc6SZhikuiRen // Get MessageArgs template from message registry 2283a3316fc6SZhikuiRen std::string msg; 2284a3316fc6SZhikuiRen if (message != nullptr) 2285a3316fc6SZhikuiRen { 2286a3316fc6SZhikuiRen msg = message->message; 2287a3316fc6SZhikuiRen 2288a3316fc6SZhikuiRen // fill in this post code value 2289a3316fc6SZhikuiRen int i = 0; 2290a3316fc6SZhikuiRen for (const std::string &messageArg : messageArgs) 2291a3316fc6SZhikuiRen { 2292a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 2293a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 2294a3316fc6SZhikuiRen if (argPos != std::string::npos) 2295a3316fc6SZhikuiRen { 2296a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 2297a3316fc6SZhikuiRen } 2298a3316fc6SZhikuiRen } 2299a3316fc6SZhikuiRen } 2300a3316fc6SZhikuiRen 2301a3316fc6SZhikuiRen // add to AsyncResp 2302a3316fc6SZhikuiRen logEntryArray.push_back({}); 2303a3316fc6SZhikuiRen nlohmann::json &bmcLogEntry = logEntryArray.back(); 2304a3316fc6SZhikuiRen bmcLogEntry = { 2305a3316fc6SZhikuiRen {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 2306a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 2307a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 2308a3316fc6SZhikuiRen "PostCodes/Entries/" + 2309a3316fc6SZhikuiRen postcodeEntryID}, 2310a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 2311a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 2312a3316fc6SZhikuiRen {"Message", std::move(msg)}, 2313a3316fc6SZhikuiRen {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"}, 2314a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 2315a3316fc6SZhikuiRen {"EntryType", "Event"}, 2316a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 2317a3316fc6SZhikuiRen {"Created", std::move(entryTimeStr)}}; 2318a3316fc6SZhikuiRen } 2319a3316fc6SZhikuiRen } 2320a3316fc6SZhikuiRen 2321a3316fc6SZhikuiRen static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp, 2322a3316fc6SZhikuiRen const uint16_t bootIndex, 2323a3316fc6SZhikuiRen const uint64_t codeIndex) 2324a3316fc6SZhikuiRen { 2325a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2326a3316fc6SZhikuiRen [aResp, bootIndex, codeIndex]( 2327a3316fc6SZhikuiRen const boost::system::error_code ec, 2328a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t> &postcode) { 2329a3316fc6SZhikuiRen if (ec) 2330a3316fc6SZhikuiRen { 2331a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 2332a3316fc6SZhikuiRen messages::internalError(aResp->res); 2333a3316fc6SZhikuiRen return; 2334a3316fc6SZhikuiRen } 2335a3316fc6SZhikuiRen 2336a3316fc6SZhikuiRen // skip the empty postcode boots 2337a3316fc6SZhikuiRen if (postcode.empty()) 2338a3316fc6SZhikuiRen { 2339a3316fc6SZhikuiRen return; 2340a3316fc6SZhikuiRen } 2341a3316fc6SZhikuiRen 2342a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 2343a3316fc6SZhikuiRen 2344a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 2345a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 2346a3316fc6SZhikuiRen }, 2347a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2348a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2349a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 2350a3316fc6SZhikuiRen bootIndex); 2351a3316fc6SZhikuiRen } 2352a3316fc6SZhikuiRen 2353a3316fc6SZhikuiRen static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp, 2354a3316fc6SZhikuiRen const uint16_t bootIndex, 2355a3316fc6SZhikuiRen const uint16_t bootCount, 2356a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 2357a3316fc6SZhikuiRen const uint64_t top) 2358a3316fc6SZhikuiRen { 2359a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2360a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 2361a3316fc6SZhikuiRen top](const boost::system::error_code ec, 2362a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t> &postcode) { 2363a3316fc6SZhikuiRen if (ec) 2364a3316fc6SZhikuiRen { 2365a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 2366a3316fc6SZhikuiRen messages::internalError(aResp->res); 2367a3316fc6SZhikuiRen return; 2368a3316fc6SZhikuiRen } 2369a3316fc6SZhikuiRen 2370a3316fc6SZhikuiRen uint64_t endCount = entryCount; 2371a3316fc6SZhikuiRen if (!postcode.empty()) 2372a3316fc6SZhikuiRen { 2373a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 2374a3316fc6SZhikuiRen 2375a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 2376a3316fc6SZhikuiRen { 2377a3316fc6SZhikuiRen uint64_t thisBootSkip = 2378a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 2379a3316fc6SZhikuiRen uint64_t thisBootTop = 2380a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 2381a3316fc6SZhikuiRen 2382a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 2383a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 2384a3316fc6SZhikuiRen } 2385a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 2386a3316fc6SZhikuiRen } 2387a3316fc6SZhikuiRen 2388a3316fc6SZhikuiRen // continue to previous bootIndex 2389a3316fc6SZhikuiRen if (bootIndex < bootCount) 2390a3316fc6SZhikuiRen { 2391a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 2392a3316fc6SZhikuiRen bootCount, endCount, skip, top); 2393a3316fc6SZhikuiRen } 2394a3316fc6SZhikuiRen else 2395a3316fc6SZhikuiRen { 2396a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 2397a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 2398a3316fc6SZhikuiRen "Entries?$skip=" + 2399a3316fc6SZhikuiRen std::to_string(skip + top); 2400a3316fc6SZhikuiRen } 2401a3316fc6SZhikuiRen }, 2402a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2403a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2404a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 2405a3316fc6SZhikuiRen bootIndex); 2406a3316fc6SZhikuiRen } 2407a3316fc6SZhikuiRen 2408a3316fc6SZhikuiRen static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp, 2409a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 2410a3316fc6SZhikuiRen { 2411a3316fc6SZhikuiRen uint64_t entryCount = 0; 2412a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2413a3316fc6SZhikuiRen [aResp, entryCount, skip, 2414a3316fc6SZhikuiRen top](const boost::system::error_code ec, 2415a3316fc6SZhikuiRen const std::variant<uint16_t> &bootCount) { 2416a3316fc6SZhikuiRen if (ec) 2417a3316fc6SZhikuiRen { 2418a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2419a3316fc6SZhikuiRen messages::internalError(aResp->res); 2420a3316fc6SZhikuiRen return; 2421a3316fc6SZhikuiRen } 2422a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 2423a3316fc6SZhikuiRen if (pVal) 2424a3316fc6SZhikuiRen { 2425a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 2426a3316fc6SZhikuiRen } 2427a3316fc6SZhikuiRen else 2428a3316fc6SZhikuiRen { 2429a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 2430a3316fc6SZhikuiRen } 2431a3316fc6SZhikuiRen }, 2432a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2433a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2434a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 2435a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 2436a3316fc6SZhikuiRen } 2437a3316fc6SZhikuiRen 2438a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node 2439a3316fc6SZhikuiRen { 2440a3316fc6SZhikuiRen public: 2441a3316fc6SZhikuiRen template <typename CrowApp> 2442a3316fc6SZhikuiRen PostCodesEntryCollection(CrowApp &app) : 2443a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 2444a3316fc6SZhikuiRen { 2445a3316fc6SZhikuiRen entityPrivileges = { 2446a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2447a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2448a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2449a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2450a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2451a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2452a3316fc6SZhikuiRen } 2453a3316fc6SZhikuiRen 2454a3316fc6SZhikuiRen private: 2455a3316fc6SZhikuiRen void doGet(crow::Response &res, const crow::Request &req, 2456a3316fc6SZhikuiRen const std::vector<std::string> ¶ms) override 2457a3316fc6SZhikuiRen { 2458a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2459a3316fc6SZhikuiRen 2460a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 2461a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 2462a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 2463a3316fc6SZhikuiRen "/redfish/v1/" 2464a3316fc6SZhikuiRen "$metadata#LogEntryCollection.LogEntryCollection"; 2465a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 2466a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 2467a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 2468a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 2469a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 2470a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 2471a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 2472a3316fc6SZhikuiRen 2473a3316fc6SZhikuiRen uint64_t skip = 0; 2474a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 2475a3316fc6SZhikuiRen if (!getSkipParam(asyncResp->res, req, skip)) 2476a3316fc6SZhikuiRen { 2477a3316fc6SZhikuiRen return; 2478a3316fc6SZhikuiRen } 2479a3316fc6SZhikuiRen if (!getTopParam(asyncResp->res, req, top)) 2480a3316fc6SZhikuiRen { 2481a3316fc6SZhikuiRen return; 2482a3316fc6SZhikuiRen } 2483a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 2484a3316fc6SZhikuiRen } 2485a3316fc6SZhikuiRen }; 2486a3316fc6SZhikuiRen 2487a3316fc6SZhikuiRen class PostCodesEntry : public Node 2488a3316fc6SZhikuiRen { 2489a3316fc6SZhikuiRen public: 2490a3316fc6SZhikuiRen PostCodesEntry(CrowApp &app) : 2491a3316fc6SZhikuiRen Node(app, 2492a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/", 2493a3316fc6SZhikuiRen std::string()) 2494a3316fc6SZhikuiRen { 2495a3316fc6SZhikuiRen entityPrivileges = { 2496a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2497a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2498a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2499a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2500a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2501a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2502a3316fc6SZhikuiRen } 2503a3316fc6SZhikuiRen 2504a3316fc6SZhikuiRen private: 2505a3316fc6SZhikuiRen void doGet(crow::Response &res, const crow::Request &req, 2506a3316fc6SZhikuiRen const std::vector<std::string> ¶ms) override 2507a3316fc6SZhikuiRen { 2508a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2509a3316fc6SZhikuiRen if (params.size() != 1) 2510a3316fc6SZhikuiRen { 2511a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 2512a3316fc6SZhikuiRen return; 2513a3316fc6SZhikuiRen } 2514a3316fc6SZhikuiRen 2515a3316fc6SZhikuiRen const std::string &targetID = params[0]; 2516a3316fc6SZhikuiRen 2517a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 2518a3316fc6SZhikuiRen if (bootPos == std::string::npos) 2519a3316fc6SZhikuiRen { 2520a3316fc6SZhikuiRen // Requested ID was not found 2521a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 2522a3316fc6SZhikuiRen return; 2523a3316fc6SZhikuiRen } 2524a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 2525a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 2526a3316fc6SZhikuiRen uint16_t bootIndex = 0; 2527a3316fc6SZhikuiRen uint64_t codeIndex = 0; 2528a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 2529a3316fc6SZhikuiRen 2530a3316fc6SZhikuiRen if (dashPos == std::string::npos) 2531a3316fc6SZhikuiRen { 2532a3316fc6SZhikuiRen return; 2533a3316fc6SZhikuiRen } 2534a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 2535a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 2536a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 2537a3316fc6SZhikuiRen 2538a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 2539a3316fc6SZhikuiRen strtoul(std::string(bootIndexStr).c_str(), NULL, 0)); 2540a3316fc6SZhikuiRen codeIndex = strtoul(std::string(codeIndexStr).c_str(), NULL, 0); 2541a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 2542a3316fc6SZhikuiRen { 2543a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 2544a3316fc6SZhikuiRen << params[0]; 2545a3316fc6SZhikuiRen } 2546a3316fc6SZhikuiRen 2547a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 2548a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 2549a3316fc6SZhikuiRen "/redfish/v1/$metadata#LogEntry.LogEntry"; 2550a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 2551a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 2552a3316fc6SZhikuiRen "Entries"; 2553a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 2554a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 2555a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 2556a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 2557a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 2558a3316fc6SZhikuiRen 2559a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 2560a3316fc6SZhikuiRen } 2561a3316fc6SZhikuiRen }; 2562a3316fc6SZhikuiRen 25631da66f75SEd Tanous } // namespace redfish 2564