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 144*c9bb6861Sraviteja-b inline void deleteSystemDumpEntry(crow::Response &res, 145*c9bb6861Sraviteja-b const std::string &entryID) 146*c9bb6861Sraviteja-b { 147*c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 148*c9bb6861Sraviteja-b 149*c9bb6861Sraviteja-b auto respHandler = [asyncResp](const boost::system::error_code ec) { 150*c9bb6861Sraviteja-b BMCWEB_LOG_DEBUG << "System Dump Entry doDelete callback: Done"; 151*c9bb6861Sraviteja-b if (ec) 152*c9bb6861Sraviteja-b { 153*c9bb6861Sraviteja-b BMCWEB_LOG_ERROR 154*c9bb6861Sraviteja-b << "System Dump (DBus) doDelete respHandler got error " << ec; 155*c9bb6861Sraviteja-b asyncResp->res.result( 156*c9bb6861Sraviteja-b boost::beast::http::status::internal_server_error); 157*c9bb6861Sraviteja-b return; 158*c9bb6861Sraviteja-b } 159*c9bb6861Sraviteja-b 160*c9bb6861Sraviteja-b asyncResp->res.result(boost::beast::http::status::ok); 161*c9bb6861Sraviteja-b }; 162*c9bb6861Sraviteja-b crow::connections::systemBus->async_method_call( 163*c9bb6861Sraviteja-b respHandler, "xyz.openbmc_project.Dump.Manager", 164*c9bb6861Sraviteja-b "/xyz/openbmc_project/dump/entry/" + entryID, 165*c9bb6861Sraviteja-b "xyz.openbmc_project.Object.Delete", "Delete"); 166*c9bb6861Sraviteja-b } 167*c9bb6861Sraviteja-b 16816428a1aSJason M. Bills static int getJournalMetadata(sd_journal *journal, 16939e77504SEd Tanous const std::string_view &field, 17039e77504SEd Tanous std::string_view &contents) 17116428a1aSJason M. Bills { 17216428a1aSJason M. Bills const char *data = nullptr; 17316428a1aSJason M. Bills size_t length = 0; 17416428a1aSJason M. Bills int ret = 0; 17516428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 176271584abSEd Tanous ret = sd_journal_get_data(journal, field.data(), 177271584abSEd Tanous reinterpret_cast<const void **>(&data), &length); 17816428a1aSJason M. Bills if (ret < 0) 17916428a1aSJason M. Bills { 18016428a1aSJason M. Bills return ret; 18116428a1aSJason M. Bills } 18239e77504SEd Tanous contents = std::string_view(data, length); 18316428a1aSJason M. Bills // Only use the content after the "=" character. 18416428a1aSJason M. Bills contents.remove_prefix(std::min(contents.find("=") + 1, contents.size())); 18516428a1aSJason M. Bills return ret; 18616428a1aSJason M. Bills } 18716428a1aSJason M. Bills 18816428a1aSJason M. Bills static int getJournalMetadata(sd_journal *journal, 18939e77504SEd Tanous const std::string_view &field, const int &base, 190271584abSEd Tanous long int &contents) 19116428a1aSJason M. Bills { 19216428a1aSJason M. Bills int ret = 0; 19339e77504SEd Tanous std::string_view metadata; 19416428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 19516428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 19616428a1aSJason M. Bills if (ret < 0) 19716428a1aSJason M. Bills { 19816428a1aSJason M. Bills return ret; 19916428a1aSJason M. Bills } 200b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 20116428a1aSJason M. Bills return ret; 20216428a1aSJason M. Bills } 20316428a1aSJason M. Bills 204a3316fc6SZhikuiRen static bool getTimestampStr(const uint64_t usecSinceEpoch, 205a3316fc6SZhikuiRen std::string &entryTimestamp) 20616428a1aSJason M. Bills { 207a3316fc6SZhikuiRen time_t t = static_cast<time_t>(usecSinceEpoch / 1000 / 1000); 20816428a1aSJason M. Bills struct tm *loctime = localtime(&t); 20916428a1aSJason M. Bills char entryTime[64] = {}; 21099131cd0SEd Tanous if (nullptr != loctime) 21116428a1aSJason M. Bills { 21216428a1aSJason M. Bills strftime(entryTime, sizeof(entryTime), "%FT%T%z", loctime); 21316428a1aSJason M. Bills } 21416428a1aSJason M. Bills // Insert the ':' into the timezone 21539e77504SEd Tanous std::string_view t1(entryTime); 21639e77504SEd Tanous std::string_view t2(entryTime); 21716428a1aSJason M. Bills if (t1.size() > 2 && t2.size() > 2) 21816428a1aSJason M. Bills { 21916428a1aSJason M. Bills t1.remove_suffix(2); 22016428a1aSJason M. Bills t2.remove_prefix(t2.size() - 2); 22116428a1aSJason M. Bills } 22239e77504SEd Tanous entryTimestamp = std::string(t1) + ":" + std::string(t2); 22316428a1aSJason M. Bills return true; 22416428a1aSJason M. Bills } 22516428a1aSJason M. Bills 226a3316fc6SZhikuiRen static bool getEntryTimestamp(sd_journal *journal, std::string &entryTimestamp) 227a3316fc6SZhikuiRen { 228a3316fc6SZhikuiRen int ret = 0; 229a3316fc6SZhikuiRen uint64_t timestamp = 0; 230a3316fc6SZhikuiRen ret = sd_journal_get_realtime_usec(journal, ×tamp); 231a3316fc6SZhikuiRen if (ret < 0) 232a3316fc6SZhikuiRen { 233a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 234a3316fc6SZhikuiRen << strerror(-ret); 235a3316fc6SZhikuiRen return false; 236a3316fc6SZhikuiRen } 237a3316fc6SZhikuiRen return getTimestampStr(timestamp, entryTimestamp); 238a3316fc6SZhikuiRen } 239a3316fc6SZhikuiRen 24016428a1aSJason M. Bills static bool getSkipParam(crow::Response &res, const crow::Request &req, 241271584abSEd Tanous uint64_t &skip) 24216428a1aSJason M. Bills { 24316428a1aSJason M. Bills char *skipParam = req.urlParams.get("$skip"); 24416428a1aSJason M. Bills if (skipParam != nullptr) 24516428a1aSJason M. Bills { 24616428a1aSJason M. Bills char *ptr = nullptr; 247271584abSEd Tanous skip = std::strtoul(skipParam, &ptr, 10); 24816428a1aSJason M. Bills if (*skipParam == '\0' || *ptr != '\0') 24916428a1aSJason M. Bills { 25016428a1aSJason M. Bills 25116428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(skipParam), 25216428a1aSJason M. Bills "$skip"); 25316428a1aSJason M. Bills return false; 25416428a1aSJason M. Bills } 25516428a1aSJason M. Bills } 25616428a1aSJason M. Bills return true; 25716428a1aSJason M. Bills } 25816428a1aSJason M. Bills 259271584abSEd Tanous static constexpr const uint64_t maxEntriesPerPage = 1000; 26016428a1aSJason M. Bills static bool getTopParam(crow::Response &res, const crow::Request &req, 261271584abSEd Tanous uint64_t &top) 26216428a1aSJason M. Bills { 26316428a1aSJason M. Bills char *topParam = req.urlParams.get("$top"); 26416428a1aSJason M. Bills if (topParam != nullptr) 26516428a1aSJason M. Bills { 26616428a1aSJason M. Bills char *ptr = nullptr; 267271584abSEd Tanous top = std::strtoul(topParam, &ptr, 10); 26816428a1aSJason M. Bills if (*topParam == '\0' || *ptr != '\0') 26916428a1aSJason M. Bills { 27016428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(topParam), 27116428a1aSJason M. Bills "$top"); 27216428a1aSJason M. Bills return false; 27316428a1aSJason M. Bills } 274271584abSEd Tanous if (top < 1U || top > maxEntriesPerPage) 27516428a1aSJason M. Bills { 27616428a1aSJason M. Bills 27716428a1aSJason M. Bills messages::queryParameterOutOfRange( 27816428a1aSJason M. Bills res, std::to_string(top), "$top", 27916428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 28016428a1aSJason M. Bills return false; 28116428a1aSJason M. Bills } 28216428a1aSJason M. Bills } 28316428a1aSJason M. Bills return true; 28416428a1aSJason M. Bills } 28516428a1aSJason M. Bills 286e85d6b16SJason M. Bills static bool getUniqueEntryID(sd_journal *journal, std::string &entryID, 287e85d6b16SJason M. Bills const bool firstEntry = true) 28816428a1aSJason M. Bills { 28916428a1aSJason M. Bills int ret = 0; 29016428a1aSJason M. Bills static uint64_t prevTs = 0; 29116428a1aSJason M. Bills static int index = 0; 292e85d6b16SJason M. Bills if (firstEntry) 293e85d6b16SJason M. Bills { 294e85d6b16SJason M. Bills prevTs = 0; 295e85d6b16SJason M. Bills } 296e85d6b16SJason M. Bills 29716428a1aSJason M. Bills // Get the entry timestamp 29816428a1aSJason M. Bills uint64_t curTs = 0; 29916428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 30016428a1aSJason M. Bills if (ret < 0) 30116428a1aSJason M. Bills { 30216428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 30316428a1aSJason M. Bills << strerror(-ret); 30416428a1aSJason M. Bills return false; 30516428a1aSJason M. Bills } 30616428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 30716428a1aSJason M. Bills if (curTs == prevTs) 30816428a1aSJason M. Bills { 30916428a1aSJason M. Bills index++; 31016428a1aSJason M. Bills } 31116428a1aSJason M. Bills else 31216428a1aSJason M. Bills { 31316428a1aSJason M. Bills // Otherwise, reset it 31416428a1aSJason M. Bills index = 0; 31516428a1aSJason M. Bills } 31616428a1aSJason M. Bills // Save the timestamp 31716428a1aSJason M. Bills prevTs = curTs; 31816428a1aSJason M. Bills 31916428a1aSJason M. Bills entryID = std::to_string(curTs); 32016428a1aSJason M. Bills if (index > 0) 32116428a1aSJason M. Bills { 32216428a1aSJason M. Bills entryID += "_" + std::to_string(index); 32316428a1aSJason M. Bills } 32416428a1aSJason M. Bills return true; 32516428a1aSJason M. Bills } 32616428a1aSJason M. Bills 327e85d6b16SJason M. Bills static bool getUniqueEntryID(const std::string &logEntry, std::string &entryID, 328e85d6b16SJason M. Bills const bool firstEntry = true) 32995820184SJason M. Bills { 330271584abSEd Tanous static time_t prevTs = 0; 33195820184SJason M. Bills static int index = 0; 332e85d6b16SJason M. Bills if (firstEntry) 333e85d6b16SJason M. Bills { 334e85d6b16SJason M. Bills prevTs = 0; 335e85d6b16SJason M. Bills } 336e85d6b16SJason M. Bills 33795820184SJason M. Bills // Get the entry timestamp 338271584abSEd Tanous std::time_t curTs = 0; 33995820184SJason M. Bills std::tm timeStruct = {}; 34095820184SJason M. Bills std::istringstream entryStream(logEntry); 34195820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 34295820184SJason M. Bills { 34395820184SJason M. Bills curTs = std::mktime(&timeStruct); 34495820184SJason M. Bills } 34595820184SJason M. Bills // If the timestamp isn't unique, increment the index 34695820184SJason M. Bills if (curTs == prevTs) 34795820184SJason M. Bills { 34895820184SJason M. Bills index++; 34995820184SJason M. Bills } 35095820184SJason M. Bills else 35195820184SJason M. Bills { 35295820184SJason M. Bills // Otherwise, reset it 35395820184SJason M. Bills index = 0; 35495820184SJason M. Bills } 35595820184SJason M. Bills // Save the timestamp 35695820184SJason M. Bills prevTs = curTs; 35795820184SJason M. Bills 35895820184SJason M. Bills entryID = std::to_string(curTs); 35995820184SJason M. Bills if (index > 0) 36095820184SJason M. Bills { 36195820184SJason M. Bills entryID += "_" + std::to_string(index); 36295820184SJason M. Bills } 36395820184SJason M. Bills return true; 36495820184SJason M. Bills } 36595820184SJason M. Bills 36616428a1aSJason M. Bills static bool getTimestampFromID(crow::Response &res, const std::string &entryID, 367271584abSEd Tanous uint64_t ×tamp, uint64_t &index) 36816428a1aSJason M. Bills { 36916428a1aSJason M. Bills if (entryID.empty()) 37016428a1aSJason M. Bills { 37116428a1aSJason M. Bills return false; 37216428a1aSJason M. Bills } 37316428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 37439e77504SEd Tanous std::string_view tsStr(entryID); 37516428a1aSJason M. Bills 37616428a1aSJason M. Bills auto underscorePos = tsStr.find("_"); 37716428a1aSJason M. Bills if (underscorePos != tsStr.npos) 37816428a1aSJason M. Bills { 37916428a1aSJason M. Bills // Timestamp has an index 38016428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 38139e77504SEd Tanous std::string_view indexStr(entryID); 38216428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 38316428a1aSJason M. Bills std::size_t pos; 38416428a1aSJason M. Bills try 38516428a1aSJason M. Bills { 38639e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 38716428a1aSJason M. Bills } 388271584abSEd Tanous catch (std::invalid_argument &) 38916428a1aSJason M. Bills { 39016428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 39116428a1aSJason M. Bills return false; 39216428a1aSJason M. Bills } 393271584abSEd Tanous catch (std::out_of_range &) 39416428a1aSJason M. Bills { 39516428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 39616428a1aSJason M. Bills return false; 39716428a1aSJason M. Bills } 39816428a1aSJason M. Bills if (pos != indexStr.size()) 39916428a1aSJason M. Bills { 40016428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 40116428a1aSJason M. Bills return false; 40216428a1aSJason M. Bills } 40316428a1aSJason M. Bills } 40416428a1aSJason M. Bills // Timestamp has no index 40516428a1aSJason M. Bills std::size_t pos; 40616428a1aSJason M. Bills try 40716428a1aSJason M. Bills { 40839e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 40916428a1aSJason M. Bills } 410271584abSEd Tanous catch (std::invalid_argument &) 41116428a1aSJason M. Bills { 41216428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 41316428a1aSJason M. Bills return false; 41416428a1aSJason M. Bills } 415271584abSEd Tanous catch (std::out_of_range &) 41616428a1aSJason M. Bills { 41716428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 41816428a1aSJason M. Bills return false; 41916428a1aSJason M. Bills } 42016428a1aSJason M. Bills if (pos != tsStr.size()) 42116428a1aSJason M. Bills { 42216428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 42316428a1aSJason M. Bills return false; 42416428a1aSJason M. Bills } 42516428a1aSJason M. Bills return true; 42616428a1aSJason M. Bills } 42716428a1aSJason M. Bills 42895820184SJason M. Bills static bool 42995820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path> &redfishLogFiles) 43095820184SJason M. Bills { 43195820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 43295820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 43395820184SJason M. Bills 43495820184SJason M. Bills // Loop through the directory looking for redfish log files 43595820184SJason M. Bills for (const std::filesystem::directory_entry &dirEnt : 43695820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 43795820184SJason M. Bills { 43895820184SJason M. Bills // If we find a redfish log file, save the path 43995820184SJason M. Bills std::string filename = dirEnt.path().filename(); 44095820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 44195820184SJason M. Bills { 44295820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 44395820184SJason M. Bills } 44495820184SJason M. Bills } 44595820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 44695820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 44795820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 44895820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 44995820184SJason M. Bills 45095820184SJason M. Bills return !redfishLogFiles.empty(); 45195820184SJason M. Bills } 45295820184SJason M. Bills 453043a0536SJohnathan Mantey static void ParseCrashdumpParameters( 454043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>> ¶ms, 455043a0536SJohnathan Mantey std::string &filename, std::string ×tamp, std::string &logfile) 456043a0536SJohnathan Mantey { 457043a0536SJohnathan Mantey for (auto property : params) 458043a0536SJohnathan Mantey { 459043a0536SJohnathan Mantey if (property.first == "Timestamp") 460043a0536SJohnathan Mantey { 461043a0536SJohnathan Mantey const std::string *value = 462043a0536SJohnathan Mantey sdbusplus::message::variant_ns::get_if<std::string>( 463043a0536SJohnathan Mantey &property.second); 464043a0536SJohnathan Mantey if (value != nullptr) 465043a0536SJohnathan Mantey { 466043a0536SJohnathan Mantey timestamp = *value; 467043a0536SJohnathan Mantey } 468043a0536SJohnathan Mantey } 469043a0536SJohnathan Mantey else if (property.first == "Filename") 470043a0536SJohnathan Mantey { 471043a0536SJohnathan Mantey const std::string *value = 472043a0536SJohnathan Mantey sdbusplus::message::variant_ns::get_if<std::string>( 473043a0536SJohnathan Mantey &property.second); 474043a0536SJohnathan Mantey if (value != nullptr) 475043a0536SJohnathan Mantey { 476043a0536SJohnathan Mantey filename = *value; 477043a0536SJohnathan Mantey } 478043a0536SJohnathan Mantey } 479043a0536SJohnathan Mantey else if (property.first == "Log") 480043a0536SJohnathan Mantey { 481043a0536SJohnathan Mantey const std::string *value = 482043a0536SJohnathan Mantey sdbusplus::message::variant_ns::get_if<std::string>( 483043a0536SJohnathan Mantey &property.second); 484043a0536SJohnathan Mantey if (value != nullptr) 485043a0536SJohnathan Mantey { 486043a0536SJohnathan Mantey logfile = *value; 487043a0536SJohnathan Mantey } 488043a0536SJohnathan Mantey } 489043a0536SJohnathan Mantey } 490043a0536SJohnathan Mantey } 491043a0536SJohnathan Mantey 492a3316fc6SZhikuiRen constexpr char const *postCodeIface = "xyz.openbmc_project.State.Boot.PostCode"; 493c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node 4941da66f75SEd Tanous { 4951da66f75SEd Tanous public: 4961da66f75SEd Tanous template <typename CrowApp> 497c4bf6374SJason M. Bills SystemLogServiceCollection(CrowApp &app) : 498029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/") 499c4bf6374SJason M. Bills { 500c4bf6374SJason M. Bills entityPrivileges = { 501c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 502c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 503c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 504c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 505c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 506c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 507c4bf6374SJason M. Bills } 508c4bf6374SJason M. Bills 509c4bf6374SJason M. Bills private: 510c4bf6374SJason M. Bills /** 511c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 512c4bf6374SJason M. Bills */ 513c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 514c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 515c4bf6374SJason M. Bills { 516c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 517c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 518c4bf6374SJason M. Bills // it has a duplicate entry for members 519c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 520c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 521c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 522029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 523c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 524c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 525c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 526c4bf6374SJason M. Bills nlohmann::json &logServiceArray = asyncResp->res.jsonValue["Members"]; 527c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 528029573d4SEd Tanous logServiceArray.push_back( 529029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}}); 530*c9bb6861Sraviteja-b #ifdef BMCWEB_ENABLE_REDFISH_SYSTEMDUMP_LOG 531*c9bb6861Sraviteja-b logServiceArray.push_back( 532*c9bb6861Sraviteja-b {{"@odata.id", "/redfish/v1/Systems/system/LogServices/System"}}); 533*c9bb6861Sraviteja-b #endif 534*c9bb6861Sraviteja-b 535d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 536d53dd41fSJason M. Bills logServiceArray.push_back( 537cb92c03bSAndrew Geissler {{"@odata.id", 538424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 539d53dd41fSJason M. Bills #endif 540c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 541c4bf6374SJason M. Bills logServiceArray.size(); 542a3316fc6SZhikuiRen 543a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 544a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec, 545a3316fc6SZhikuiRen const std::vector<std::string> &subtreePath) { 546a3316fc6SZhikuiRen if (ec) 547a3316fc6SZhikuiRen { 548a3316fc6SZhikuiRen BMCWEB_LOG_ERROR << ec; 549a3316fc6SZhikuiRen return; 550a3316fc6SZhikuiRen } 551a3316fc6SZhikuiRen 552a3316fc6SZhikuiRen for (auto &pathStr : subtreePath) 553a3316fc6SZhikuiRen { 554a3316fc6SZhikuiRen if (pathStr.find("PostCode") != std::string::npos) 555a3316fc6SZhikuiRen { 556a3316fc6SZhikuiRen nlohmann::json &logServiceArray = 557a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"]; 558a3316fc6SZhikuiRen logServiceArray.push_back( 559a3316fc6SZhikuiRen {{"@odata.id", "/redfish/v1/Systems/system/" 560a3316fc6SZhikuiRen "LogServices/PostCodes"}}); 561a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 562a3316fc6SZhikuiRen logServiceArray.size(); 563a3316fc6SZhikuiRen return; 564a3316fc6SZhikuiRen } 565a3316fc6SZhikuiRen } 566a3316fc6SZhikuiRen }, 567a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", 568a3316fc6SZhikuiRen "/xyz/openbmc_project/object_mapper", 569a3316fc6SZhikuiRen "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0, 570a3316fc6SZhikuiRen std::array<const char *, 1>{postCodeIface}); 571c4bf6374SJason M. Bills } 572c4bf6374SJason M. Bills }; 573c4bf6374SJason M. Bills 574c4bf6374SJason M. Bills class EventLogService : public Node 575c4bf6374SJason M. Bills { 576c4bf6374SJason M. Bills public: 577c4bf6374SJason M. Bills template <typename CrowApp> 578c4bf6374SJason M. Bills EventLogService(CrowApp &app) : 579029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 580c4bf6374SJason M. Bills { 581c4bf6374SJason M. Bills entityPrivileges = { 582c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 583c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 584c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 585c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 586c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 587c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 588c4bf6374SJason M. Bills } 589c4bf6374SJason M. Bills 590c4bf6374SJason M. Bills private: 591c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 592c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 593c4bf6374SJason M. Bills { 594c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 595c4bf6374SJason M. Bills 596c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 597029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 598c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 599c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 600c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 601c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 602c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "EventLog"; 603c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 604c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 605c4bf6374SJason M. Bills {"@odata.id", 606029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 607e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 608e7d6c8b2SGunnar Mills 609e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 610e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 611489640c6SJason M. Bills } 612489640c6SJason M. Bills }; 613489640c6SJason M. Bills 6141f56a3a6STim Lee class JournalEventLogClear : public Node 615489640c6SJason M. Bills { 616489640c6SJason M. Bills public: 6171f56a3a6STim Lee JournalEventLogClear(CrowApp &app) : 618489640c6SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 619489640c6SJason M. Bills "LogService.ClearLog/") 620489640c6SJason M. Bills { 621489640c6SJason M. Bills entityPrivileges = { 622489640c6SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 623489640c6SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 624489640c6SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 625489640c6SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 626489640c6SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 627489640c6SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 628489640c6SJason M. Bills } 629489640c6SJason M. Bills 630489640c6SJason M. Bills private: 631489640c6SJason M. Bills void doPost(crow::Response &res, const crow::Request &req, 632489640c6SJason M. Bills const std::vector<std::string> ¶ms) override 633489640c6SJason M. Bills { 634489640c6SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 635489640c6SJason M. Bills 636489640c6SJason M. Bills // Clear the EventLog by deleting the log files 637489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 638489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 639489640c6SJason M. Bills { 640489640c6SJason M. Bills for (const std::filesystem::path &file : redfishLogFiles) 641489640c6SJason M. Bills { 642489640c6SJason M. Bills std::error_code ec; 643489640c6SJason M. Bills std::filesystem::remove(file, ec); 644489640c6SJason M. Bills } 645489640c6SJason M. Bills } 646489640c6SJason M. Bills 647489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 648489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 649489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 650489640c6SJason M. Bills if (ec) 651489640c6SJason M. Bills { 652489640c6SJason M. Bills BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 653489640c6SJason M. Bills messages::internalError(asyncResp->res); 654489640c6SJason M. Bills return; 655489640c6SJason M. Bills } 656489640c6SJason M. Bills 657489640c6SJason M. Bills messages::success(asyncResp->res); 658489640c6SJason M. Bills }, 659489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 660489640c6SJason M. Bills "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 661489640c6SJason M. Bills "replace"); 662c4bf6374SJason M. Bills } 663c4bf6374SJason M. Bills }; 664c4bf6374SJason M. Bills 66595820184SJason M. Bills static int fillEventLogEntryJson(const std::string &logEntryID, 66695820184SJason M. Bills const std::string logEntry, 66795820184SJason M. Bills nlohmann::json &logEntryJson) 668c4bf6374SJason M. Bills { 66995820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 670cd225da8SJason M. Bills // First get the Timestamp 671cd225da8SJason M. Bills size_t space = logEntry.find_first_of(" "); 672cd225da8SJason M. Bills if (space == std::string::npos) 67395820184SJason M. Bills { 67495820184SJason M. Bills return 1; 67595820184SJason M. Bills } 676cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 677cd225da8SJason M. Bills // Then get the log contents 678cd225da8SJason M. Bills size_t entryStart = logEntry.find_first_not_of(" ", space); 679cd225da8SJason M. Bills if (entryStart == std::string::npos) 680cd225da8SJason M. Bills { 681cd225da8SJason M. Bills return 1; 682cd225da8SJason M. Bills } 683cd225da8SJason M. Bills std::string_view entry(logEntry); 684cd225da8SJason M. Bills entry.remove_prefix(entryStart); 685cd225da8SJason M. Bills // Use split to separate the entry into its fields 686cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 687cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 688cd225da8SJason M. Bills boost::token_compress_on); 689cd225da8SJason M. Bills // We need at least a MessageId to be valid 690cd225da8SJason M. Bills if (logEntryFields.size() < 1) 691cd225da8SJason M. Bills { 692cd225da8SJason M. Bills return 1; 693cd225da8SJason M. Bills } 694cd225da8SJason M. Bills std::string &messageID = logEntryFields[0]; 69595820184SJason M. Bills 6964851d45dSJason M. Bills // Get the Message from the MessageRegistry 6974851d45dSJason M. Bills const message_registries::Message *message = 6984851d45dSJason M. Bills message_registries::getMessage(messageID); 699c4bf6374SJason M. Bills 7004851d45dSJason M. Bills std::string msg; 7014851d45dSJason M. Bills std::string severity; 7024851d45dSJason M. Bills if (message != nullptr) 703c4bf6374SJason M. Bills { 7044851d45dSJason M. Bills msg = message->message; 7054851d45dSJason M. Bills severity = message->severity; 706c4bf6374SJason M. Bills } 707c4bf6374SJason M. Bills 70815a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 70915a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 71015a86ff6SJason M. Bills if (logEntryFields.size() > 1) 71115a86ff6SJason M. Bills { 71215a86ff6SJason M. Bills std::string &messageArgsStart = logEntryFields[1]; 71315a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 71415a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 71515a86ff6SJason M. Bills if (!messageArgsStart.empty()) 71615a86ff6SJason M. Bills { 71715a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 71815a86ff6SJason M. Bills } 71915a86ff6SJason M. Bills 72015a86ff6SJason M. Bills messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize); 721c4bf6374SJason M. Bills 7224851d45dSJason M. Bills // Fill the MessageArgs into the Message 72395820184SJason M. Bills int i = 0; 72495820184SJason M. Bills for (const std::string &messageArg : messageArgs) 7254851d45dSJason M. Bills { 72695820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 7274851d45dSJason M. Bills size_t argPos = msg.find(argStr); 7284851d45dSJason M. Bills if (argPos != std::string::npos) 7294851d45dSJason M. Bills { 73095820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 7314851d45dSJason M. Bills } 7324851d45dSJason M. Bills } 73315a86ff6SJason M. Bills } 7344851d45dSJason M. Bills 73595820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 73695820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 73795820184SJason M. Bills // between the '.' and the '+', so just remove them. 73895820184SJason M. Bills std::size_t dot = timestamp.find_first_of("."); 73995820184SJason M. Bills std::size_t plus = timestamp.find_first_of("+"); 74095820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 741c4bf6374SJason M. Bills { 74295820184SJason M. Bills timestamp.erase(dot, plus - dot); 743c4bf6374SJason M. Bills } 744c4bf6374SJason M. Bills 745c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 74695820184SJason M. Bills logEntryJson = { 747cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 748029573d4SEd Tanous {"@odata.id", 749897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" + 75095820184SJason M. Bills logEntryID}, 751c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 75295820184SJason M. Bills {"Id", logEntryID}, 75395820184SJason M. Bills {"Message", std::move(msg)}, 75495820184SJason M. Bills {"MessageId", std::move(messageID)}, 755c4bf6374SJason M. Bills {"MessageArgs", std::move(messageArgs)}, 756c4bf6374SJason M. Bills {"EntryType", "Event"}, 75795820184SJason M. Bills {"Severity", std::move(severity)}, 75895820184SJason M. Bills {"Created", std::move(timestamp)}}; 759c4bf6374SJason M. Bills return 0; 760c4bf6374SJason M. Bills } 761c4bf6374SJason M. Bills 76227062605SAnthony Wilson class JournalEventLogEntryCollection : public Node 763c4bf6374SJason M. Bills { 764c4bf6374SJason M. Bills public: 765c4bf6374SJason M. Bills template <typename CrowApp> 76627062605SAnthony Wilson JournalEventLogEntryCollection(CrowApp &app) : 767029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 768c4bf6374SJason M. Bills { 769c4bf6374SJason M. Bills entityPrivileges = { 770c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 771c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 772c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 773c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 774c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 775c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 776c4bf6374SJason M. Bills } 777c4bf6374SJason M. Bills 778c4bf6374SJason M. Bills private: 779c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 780c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 781c4bf6374SJason M. Bills { 782c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 783271584abSEd Tanous uint64_t skip = 0; 784271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 785c4bf6374SJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 786c4bf6374SJason M. Bills { 787c4bf6374SJason M. Bills return; 788c4bf6374SJason M. Bills } 789c4bf6374SJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 790c4bf6374SJason M. Bills { 791c4bf6374SJason M. Bills return; 792c4bf6374SJason M. Bills } 793c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 794c4bf6374SJason M. Bills // it has a duplicate entry for members 795c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 796c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 797c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 798029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 799c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 800c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 801c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 802cb92c03bSAndrew Geissler 803c4bf6374SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 804c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 80595820184SJason M. Bills // Go through the log files and create a unique ID for each entry 80695820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 80795820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 808b01bf299SEd Tanous uint64_t entryCount = 0; 809cd225da8SJason M. Bills std::string logEntry; 81095820184SJason M. Bills 81195820184SJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 812cd225da8SJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 813cd225da8SJason M. Bills it++) 814c4bf6374SJason M. Bills { 815cd225da8SJason M. Bills std::ifstream logStream(*it); 81695820184SJason M. Bills if (!logStream.is_open()) 817c4bf6374SJason M. Bills { 818c4bf6374SJason M. Bills continue; 819c4bf6374SJason M. Bills } 820c4bf6374SJason M. Bills 821e85d6b16SJason M. Bills // Reset the unique ID on the first entry 822e85d6b16SJason M. Bills bool firstEntry = true; 82395820184SJason M. Bills while (std::getline(logStream, logEntry)) 82495820184SJason M. Bills { 825c4bf6374SJason M. Bills entryCount++; 826c4bf6374SJason M. Bills // Handle paging using skip (number of entries to skip from the 827c4bf6374SJason M. Bills // start) and top (number of entries to display) 828c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 829c4bf6374SJason M. Bills { 830c4bf6374SJason M. Bills continue; 831c4bf6374SJason M. Bills } 832c4bf6374SJason M. Bills 833c4bf6374SJason M. Bills std::string idStr; 834e85d6b16SJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 835c4bf6374SJason M. Bills { 836c4bf6374SJason M. Bills continue; 837c4bf6374SJason M. Bills } 838c4bf6374SJason M. Bills 839e85d6b16SJason M. Bills if (firstEntry) 840e85d6b16SJason M. Bills { 841e85d6b16SJason M. Bills firstEntry = false; 842e85d6b16SJason M. Bills } 843e85d6b16SJason M. Bills 844c4bf6374SJason M. Bills logEntryArray.push_back({}); 845c4bf6374SJason M. Bills nlohmann::json &bmcLogEntry = logEntryArray.back(); 84695820184SJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) 847c4bf6374SJason M. Bills { 848c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 849c4bf6374SJason M. Bills return; 850c4bf6374SJason M. Bills } 851c4bf6374SJason M. Bills } 85295820184SJason M. Bills } 853c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 854c4bf6374SJason M. Bills if (skip + top < entryCount) 855c4bf6374SJason M. Bills { 856c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 85795820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 85895820184SJason M. Bills "Entries?$skip=" + 859c4bf6374SJason M. Bills std::to_string(skip + top); 860c4bf6374SJason M. Bills } 86108a4e4b5SAnthony Wilson } 86208a4e4b5SAnthony Wilson }; 86308a4e4b5SAnthony Wilson 864897967deSJason M. Bills class JournalEventLogEntry : public Node 865897967deSJason M. Bills { 866897967deSJason M. Bills public: 867897967deSJason M. Bills JournalEventLogEntry(CrowApp &app) : 868897967deSJason M. Bills Node(app, 869897967deSJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 870897967deSJason M. Bills std::string()) 871897967deSJason M. Bills { 872897967deSJason M. Bills entityPrivileges = { 873897967deSJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 874897967deSJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 875897967deSJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 876897967deSJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 877897967deSJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 878897967deSJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 879897967deSJason M. Bills } 880897967deSJason M. Bills 881897967deSJason M. Bills private: 882897967deSJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 883897967deSJason M. Bills const std::vector<std::string> ¶ms) override 884897967deSJason M. Bills { 885897967deSJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 886897967deSJason M. Bills if (params.size() != 1) 887897967deSJason M. Bills { 888897967deSJason M. Bills messages::internalError(asyncResp->res); 889897967deSJason M. Bills return; 890897967deSJason M. Bills } 891897967deSJason M. Bills const std::string &targetID = params[0]; 892897967deSJason M. Bills 893897967deSJason M. Bills // Go through the log files and check the unique ID for each entry to 894897967deSJason M. Bills // find the target entry 895897967deSJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 896897967deSJason M. Bills getRedfishLogFiles(redfishLogFiles); 897897967deSJason M. Bills std::string logEntry; 898897967deSJason M. Bills 899897967deSJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 900897967deSJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 901897967deSJason M. Bills it++) 902897967deSJason M. Bills { 903897967deSJason M. Bills std::ifstream logStream(*it); 904897967deSJason M. Bills if (!logStream.is_open()) 905897967deSJason M. Bills { 906897967deSJason M. Bills continue; 907897967deSJason M. Bills } 908897967deSJason M. Bills 909897967deSJason M. Bills // Reset the unique ID on the first entry 910897967deSJason M. Bills bool firstEntry = true; 911897967deSJason M. Bills while (std::getline(logStream, logEntry)) 912897967deSJason M. Bills { 913897967deSJason M. Bills std::string idStr; 914897967deSJason M. Bills if (!getUniqueEntryID(logEntry, idStr, firstEntry)) 915897967deSJason M. Bills { 916897967deSJason M. Bills continue; 917897967deSJason M. Bills } 918897967deSJason M. Bills 919897967deSJason M. Bills if (firstEntry) 920897967deSJason M. Bills { 921897967deSJason M. Bills firstEntry = false; 922897967deSJason M. Bills } 923897967deSJason M. Bills 924897967deSJason M. Bills if (idStr == targetID) 925897967deSJason M. Bills { 926897967deSJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, 927897967deSJason M. Bills asyncResp->res.jsonValue) != 0) 928897967deSJason M. Bills { 929897967deSJason M. Bills messages::internalError(asyncResp->res); 930897967deSJason M. Bills return; 931897967deSJason M. Bills } 932897967deSJason M. Bills return; 933897967deSJason M. Bills } 934897967deSJason M. Bills } 935897967deSJason M. Bills } 936897967deSJason M. Bills // Requested ID was not found 937897967deSJason M. Bills messages::resourceMissingAtURI(asyncResp->res, targetID); 938897967deSJason M. Bills } 939897967deSJason M. Bills }; 940897967deSJason M. Bills 94108a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node 94208a4e4b5SAnthony Wilson { 94308a4e4b5SAnthony Wilson public: 94408a4e4b5SAnthony Wilson template <typename CrowApp> 94508a4e4b5SAnthony Wilson DBusEventLogEntryCollection(CrowApp &app) : 94608a4e4b5SAnthony Wilson Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 94708a4e4b5SAnthony Wilson { 94808a4e4b5SAnthony Wilson entityPrivileges = { 94908a4e4b5SAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 95008a4e4b5SAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 95108a4e4b5SAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 95208a4e4b5SAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 95308a4e4b5SAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 95408a4e4b5SAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 95508a4e4b5SAnthony Wilson } 95608a4e4b5SAnthony Wilson 95708a4e4b5SAnthony Wilson private: 95808a4e4b5SAnthony Wilson void doGet(crow::Response &res, const crow::Request &req, 95908a4e4b5SAnthony Wilson const std::vector<std::string> ¶ms) override 96008a4e4b5SAnthony Wilson { 96108a4e4b5SAnthony Wilson std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 96208a4e4b5SAnthony Wilson 96308a4e4b5SAnthony Wilson // Collections don't include the static data added by SubRoute because 96408a4e4b5SAnthony Wilson // it has a duplicate entry for members 96508a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 96608a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 96708a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 96808a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 96908a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 97008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 97108a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 97208a4e4b5SAnthony Wilson 973cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 974cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 975cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 976cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 977cb92c03bSAndrew Geissler GetManagedObjectsType &resp) { 978cb92c03bSAndrew Geissler if (ec) 979cb92c03bSAndrew Geissler { 980cb92c03bSAndrew Geissler // TODO Handle for specific error code 981cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 982cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 983cb92c03bSAndrew Geissler << ec; 984cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 985cb92c03bSAndrew Geissler return; 986cb92c03bSAndrew Geissler } 987cb92c03bSAndrew Geissler nlohmann::json &entriesArray = 988cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 989cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 990cb92c03bSAndrew Geissler for (auto &objectPath : resp) 991cb92c03bSAndrew Geissler { 992cb92c03bSAndrew Geissler for (auto &interfaceMap : objectPath.second) 993cb92c03bSAndrew Geissler { 994cb92c03bSAndrew Geissler if (interfaceMap.first != 995cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry") 996cb92c03bSAndrew Geissler { 997cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Bailing early on " 998cb92c03bSAndrew Geissler << interfaceMap.first; 999cb92c03bSAndrew Geissler continue; 1000cb92c03bSAndrew Geissler } 1001cb92c03bSAndrew Geissler entriesArray.push_back({}); 1002cb92c03bSAndrew Geissler nlohmann::json &thisEntry = entriesArray.back(); 100366664f25SEd Tanous uint32_t *id = nullptr; 100466664f25SEd Tanous std::time_t timestamp{}; 100566664f25SEd Tanous std::string *severity = nullptr; 100666664f25SEd Tanous std::string *message = nullptr; 1007cb92c03bSAndrew Geissler for (auto &propertyMap : interfaceMap.second) 1008cb92c03bSAndrew Geissler { 1009cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1010cb92c03bSAndrew Geissler { 1011cb92c03bSAndrew Geissler id = sdbusplus::message::variant_ns::get_if< 1012cb92c03bSAndrew Geissler uint32_t>(&propertyMap.second); 1013cb92c03bSAndrew Geissler if (id == nullptr) 1014cb92c03bSAndrew Geissler { 1015cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1016cb92c03bSAndrew Geissler "Id"); 1017cb92c03bSAndrew Geissler } 1018cb92c03bSAndrew Geissler } 1019cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1020cb92c03bSAndrew Geissler { 1021cb92c03bSAndrew Geissler const uint64_t *millisTimeStamp = 1022cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1023cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1024cb92c03bSAndrew Geissler { 1025cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1026cb92c03bSAndrew Geissler "Timestamp"); 1027271584abSEd Tanous continue; 1028cb92c03bSAndrew Geissler } 1029cb92c03bSAndrew Geissler // Retrieve Created property with format: 1030cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 1031cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 1032cb92c03bSAndrew Geissler *millisTimeStamp); 1033271584abSEd Tanous timestamp = std::chrono::duration_cast< 1034271584abSEd Tanous std::chrono::duration<int>>( 1035271584abSEd Tanous chronoTimeStamp) 1036cb92c03bSAndrew Geissler .count(); 1037cb92c03bSAndrew Geissler } 1038cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1039cb92c03bSAndrew Geissler { 1040cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 1041cb92c03bSAndrew Geissler &propertyMap.second); 1042cb92c03bSAndrew Geissler if (severity == nullptr) 1043cb92c03bSAndrew Geissler { 1044cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1045cb92c03bSAndrew Geissler "Severity"); 1046cb92c03bSAndrew Geissler } 1047cb92c03bSAndrew Geissler } 1048cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1049cb92c03bSAndrew Geissler { 1050cb92c03bSAndrew Geissler message = std::get_if<std::string>( 1051cb92c03bSAndrew Geissler &propertyMap.second); 1052cb92c03bSAndrew Geissler if (message == nullptr) 1053cb92c03bSAndrew Geissler { 1054cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1055cb92c03bSAndrew Geissler "Message"); 1056cb92c03bSAndrew Geissler } 1057cb92c03bSAndrew Geissler } 1058cb92c03bSAndrew Geissler } 1059cb92c03bSAndrew Geissler thisEntry = { 1060cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1061cb92c03bSAndrew Geissler {"@odata.id", 1062cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1063cb92c03bSAndrew Geissler "Entries/" + 1064cb92c03bSAndrew Geissler std::to_string(*id)}, 106527062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1066cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1067cb92c03bSAndrew Geissler {"Message", *message}, 1068cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1069cb92c03bSAndrew Geissler {"Severity", 1070cb92c03bSAndrew Geissler translateSeverityDbusToRedfish(*severity)}, 1071cb92c03bSAndrew Geissler {"Created", crow::utility::getDateTime(timestamp)}}; 1072cb92c03bSAndrew Geissler } 1073cb92c03bSAndrew Geissler } 1074cb92c03bSAndrew Geissler std::sort(entriesArray.begin(), entriesArray.end(), 1075cb92c03bSAndrew Geissler [](const nlohmann::json &left, 1076cb92c03bSAndrew Geissler const nlohmann::json &right) { 1077cb92c03bSAndrew Geissler return (left["Id"] <= right["Id"]); 1078cb92c03bSAndrew Geissler }); 1079cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members@odata.count"] = 1080cb92c03bSAndrew Geissler entriesArray.size(); 1081cb92c03bSAndrew Geissler }, 1082cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 1083cb92c03bSAndrew Geissler "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1084c4bf6374SJason M. Bills } 1085c4bf6374SJason M. Bills }; 1086c4bf6374SJason M. Bills 108708a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node 1088c4bf6374SJason M. Bills { 1089c4bf6374SJason M. Bills public: 109008a4e4b5SAnthony Wilson DBusEventLogEntry(CrowApp &app) : 1091c4bf6374SJason M. Bills Node(app, 1092029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 1093029573d4SEd Tanous std::string()) 1094c4bf6374SJason M. Bills { 1095c4bf6374SJason M. Bills entityPrivileges = { 1096c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1097c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1098c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1099c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1100c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1101c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1102c4bf6374SJason M. Bills } 1103c4bf6374SJason M. Bills 1104c4bf6374SJason M. Bills private: 1105c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1106c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 1107c4bf6374SJason M. Bills { 1108c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1109029573d4SEd Tanous if (params.size() != 1) 1110c4bf6374SJason M. Bills { 1111c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 1112c4bf6374SJason M. Bills return; 1113c4bf6374SJason M. Bills } 1114029573d4SEd Tanous const std::string &entryID = params[0]; 1115cb92c03bSAndrew Geissler 1116cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 1117cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 1118cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1119cb92c03bSAndrew Geissler [asyncResp, entryID](const boost::system::error_code ec, 1120cb92c03bSAndrew Geissler GetManagedPropertyType &resp) { 1121cb92c03bSAndrew Geissler if (ec) 1122cb92c03bSAndrew Geissler { 1123cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 1124cb92c03bSAndrew Geissler << "EventLogEntry (DBus) resp_handler got error " << ec; 1125cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 1126cb92c03bSAndrew Geissler return; 1127cb92c03bSAndrew Geissler } 112866664f25SEd Tanous uint32_t *id = nullptr; 112966664f25SEd Tanous std::time_t timestamp{}; 113066664f25SEd Tanous std::string *severity = nullptr; 113166664f25SEd Tanous std::string *message = nullptr; 1132cb92c03bSAndrew Geissler for (auto &propertyMap : resp) 1133cb92c03bSAndrew Geissler { 1134cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 1135cb92c03bSAndrew Geissler { 1136cb92c03bSAndrew Geissler id = std::get_if<uint32_t>(&propertyMap.second); 1137cb92c03bSAndrew Geissler if (id == nullptr) 1138cb92c03bSAndrew Geissler { 1139cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, "Id"); 1140cb92c03bSAndrew Geissler } 1141cb92c03bSAndrew Geissler } 1142cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 1143cb92c03bSAndrew Geissler { 1144cb92c03bSAndrew Geissler const uint64_t *millisTimeStamp = 1145cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 1146cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 1147cb92c03bSAndrew Geissler { 1148cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1149cb92c03bSAndrew Geissler "Timestamp"); 1150271584abSEd Tanous continue; 1151cb92c03bSAndrew Geissler } 1152cb92c03bSAndrew Geissler // Retrieve Created property with format: 1153cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 1154cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 1155cb92c03bSAndrew Geissler *millisTimeStamp); 1156cb92c03bSAndrew Geissler timestamp = 1157271584abSEd Tanous std::chrono::duration_cast< 1158271584abSEd Tanous std::chrono::duration<int>>(chronoTimeStamp) 1159cb92c03bSAndrew Geissler .count(); 1160cb92c03bSAndrew Geissler } 1161cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 1162cb92c03bSAndrew Geissler { 1163cb92c03bSAndrew Geissler severity = 1164cb92c03bSAndrew Geissler std::get_if<std::string>(&propertyMap.second); 1165cb92c03bSAndrew Geissler if (severity == nullptr) 1166cb92c03bSAndrew Geissler { 1167cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1168cb92c03bSAndrew Geissler "Severity"); 1169cb92c03bSAndrew Geissler } 1170cb92c03bSAndrew Geissler } 1171cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 1172cb92c03bSAndrew Geissler { 1173cb92c03bSAndrew Geissler message = std::get_if<std::string>(&propertyMap.second); 1174cb92c03bSAndrew Geissler if (message == nullptr) 1175cb92c03bSAndrew Geissler { 1176cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 1177cb92c03bSAndrew Geissler "Message"); 1178cb92c03bSAndrew Geissler } 1179cb92c03bSAndrew Geissler } 1180cb92c03bSAndrew Geissler } 1181271584abSEd Tanous if (id == nullptr || message == nullptr || severity == nullptr) 1182271584abSEd Tanous { 1183271584abSEd Tanous return; 1184271584abSEd Tanous } 1185cb92c03bSAndrew Geissler asyncResp->res.jsonValue = { 1186cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1187cb92c03bSAndrew Geissler {"@odata.id", 1188cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1189cb92c03bSAndrew Geissler "Entries/" + 1190cb92c03bSAndrew Geissler std::to_string(*id)}, 119127062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1192cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1193cb92c03bSAndrew Geissler {"Message", *message}, 1194cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1195cb92c03bSAndrew Geissler {"Severity", translateSeverityDbusToRedfish(*severity)}, 119608a4e4b5SAnthony Wilson {"Created", crow::utility::getDateTime(timestamp)}}; 1197cb92c03bSAndrew Geissler }, 1198cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1199cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1200cb92c03bSAndrew Geissler "org.freedesktop.DBus.Properties", "GetAll", 1201cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry"); 1202c4bf6374SJason M. Bills } 1203336e96c6SChicago Duan 1204336e96c6SChicago Duan void doDelete(crow::Response &res, const crow::Request &req, 1205336e96c6SChicago Duan const std::vector<std::string> ¶ms) override 1206336e96c6SChicago Duan { 1207336e96c6SChicago Duan 1208336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1209336e96c6SChicago Duan 1210336e96c6SChicago Duan auto asyncResp = std::make_shared<AsyncResp>(res); 1211336e96c6SChicago Duan 1212336e96c6SChicago Duan if (params.size() != 1) 1213336e96c6SChicago Duan { 1214336e96c6SChicago Duan messages::internalError(asyncResp->res); 1215336e96c6SChicago Duan return; 1216336e96c6SChicago Duan } 1217336e96c6SChicago Duan std::string entryID = params[0]; 1218336e96c6SChicago Duan 1219336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1220336e96c6SChicago Duan 1221336e96c6SChicago Duan // Process response from Logging service. 1222336e96c6SChicago Duan auto respHandler = [asyncResp](const boost::system::error_code ec) { 1223336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1224336e96c6SChicago Duan if (ec) 1225336e96c6SChicago Duan { 1226336e96c6SChicago Duan // TODO Handle for specific error code 1227336e96c6SChicago Duan BMCWEB_LOG_ERROR 1228336e96c6SChicago Duan << "EventLogEntry (DBus) doDelete respHandler got error " 1229336e96c6SChicago Duan << ec; 1230336e96c6SChicago Duan asyncResp->res.result( 1231336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1232336e96c6SChicago Duan return; 1233336e96c6SChicago Duan } 1234336e96c6SChicago Duan 1235336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1236336e96c6SChicago Duan }; 1237336e96c6SChicago Duan 1238336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1239336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1240336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1241336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1242336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 1243336e96c6SChicago Duan } 1244c4bf6374SJason M. Bills }; 1245c4bf6374SJason M. Bills 1246c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node 1247c4bf6374SJason M. Bills { 1248c4bf6374SJason M. Bills public: 1249c4bf6374SJason M. Bills template <typename CrowApp> 1250c4bf6374SJason M. Bills BMCLogServiceCollection(CrowApp &app) : 12514ed77cd5SEd Tanous Node(app, "/redfish/v1/Managers/bmc/LogServices/") 12521da66f75SEd Tanous { 12531da66f75SEd Tanous entityPrivileges = { 1254e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1255e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1256e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1257e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1258e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1259e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 12601da66f75SEd Tanous } 12611da66f75SEd Tanous 12621da66f75SEd Tanous private: 12631da66f75SEd Tanous /** 12641da66f75SEd Tanous * Functions triggers appropriate requests on DBus 12651da66f75SEd Tanous */ 12661da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 12671da66f75SEd Tanous const std::vector<std::string> ¶ms) override 12681da66f75SEd Tanous { 1269e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 12701da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 12711da66f75SEd Tanous // it has a duplicate entry for members 1272e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 12731da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1274e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1275e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 1276e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 1277e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 12781da66f75SEd Tanous "Collection of LogServices for this Manager"; 1279c4bf6374SJason M. Bills nlohmann::json &logServiceArray = asyncResp->res.jsonValue["Members"]; 1280c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 1281c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1282c4bf6374SJason M. Bills logServiceArray.push_back( 128308a4e4b5SAnthony Wilson {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1284c4bf6374SJason M. Bills #endif 1285e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1286c4bf6374SJason M. Bills logServiceArray.size(); 12871da66f75SEd Tanous } 12881da66f75SEd Tanous }; 12891da66f75SEd Tanous 1290c4bf6374SJason M. Bills class BMCJournalLogService : public Node 12911da66f75SEd Tanous { 12921da66f75SEd Tanous public: 12931da66f75SEd Tanous template <typename CrowApp> 1294c4bf6374SJason M. Bills BMCJournalLogService(CrowApp &app) : 1295c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1296e1f26343SJason M. Bills { 1297e1f26343SJason M. Bills entityPrivileges = { 1298e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1299e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1300e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1301e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1302e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1303e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1304e1f26343SJason M. Bills } 1305e1f26343SJason M. Bills 1306e1f26343SJason M. Bills private: 1307e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1308e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1309e1f26343SJason M. Bills { 1310e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1311e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1312e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 13130f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 13140f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 1315c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 1316c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 1317c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1318e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1319cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1320cd50aa42SJason M. Bills {"@odata.id", 1321086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 1322e1f26343SJason M. Bills } 1323e1f26343SJason M. Bills }; 1324e1f26343SJason M. Bills 1325c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string &bmcJournalLogEntryID, 1326e1f26343SJason M. Bills sd_journal *journal, 1327c4bf6374SJason M. Bills nlohmann::json &bmcJournalLogEntryJson) 1328e1f26343SJason M. Bills { 1329e1f26343SJason M. Bills // Get the Log Entry contents 1330e1f26343SJason M. Bills int ret = 0; 1331e1f26343SJason M. Bills 133239e77504SEd Tanous std::string_view msg; 133316428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1334e1f26343SJason M. Bills if (ret < 0) 1335e1f26343SJason M. Bills { 1336e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1337e1f26343SJason M. Bills return 1; 1338e1f26343SJason M. Bills } 1339e1f26343SJason M. Bills 1340e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1341271584abSEd Tanous long int severity = 8; // Default to an invalid priority 134216428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1343e1f26343SJason M. Bills if (ret < 0) 1344e1f26343SJason M. Bills { 1345e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1346e1f26343SJason M. Bills } 1347e1f26343SJason M. Bills 1348e1f26343SJason M. Bills // Get the Created time from the timestamp 134916428a1aSJason M. Bills std::string entryTimeStr; 135016428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1351e1f26343SJason M. Bills { 135216428a1aSJason M. Bills return 1; 1353e1f26343SJason M. Bills } 1354e1f26343SJason M. Bills 1355e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1356c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1357cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1358c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1359c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1360e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1361c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 136216428a1aSJason M. Bills {"Message", msg}, 1363e1f26343SJason M. Bills {"EntryType", "Oem"}, 1364e1f26343SJason M. Bills {"Severity", 1365b6a61a5eSJason M. Bills severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"}, 1366086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1367e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1368e1f26343SJason M. Bills return 0; 1369e1f26343SJason M. Bills } 1370e1f26343SJason M. Bills 1371c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node 1372e1f26343SJason M. Bills { 1373e1f26343SJason M. Bills public: 1374e1f26343SJason M. Bills template <typename CrowApp> 1375c4bf6374SJason M. Bills BMCJournalLogEntryCollection(CrowApp &app) : 1376c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1377e1f26343SJason M. Bills { 1378e1f26343SJason M. Bills entityPrivileges = { 1379e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1380e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1381e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1382e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1383e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1384e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1385e1f26343SJason M. Bills } 1386e1f26343SJason M. Bills 1387e1f26343SJason M. Bills private: 1388e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1389e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1390e1f26343SJason M. Bills { 1391e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1392193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1393271584abSEd Tanous uint64_t skip = 0; 1394271584abSEd Tanous uint64_t top = maxEntriesPerPage; // Show max entries by default 139516428a1aSJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1396193ad2faSJason M. Bills { 1397193ad2faSJason M. Bills return; 1398193ad2faSJason M. Bills } 139916428a1aSJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1400193ad2faSJason M. Bills { 1401193ad2faSJason M. Bills return; 1402193ad2faSJason M. Bills } 1403e1f26343SJason M. Bills // Collections don't include the static data added by SubRoute because 1404e1f26343SJason M. Bills // it has a duplicate entry for members 1405e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1406e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 14070f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 14080f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1409e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1410c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1411e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1412e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1413e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 14140f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 14150f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries"; 1416e1f26343SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 1417e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1418e1f26343SJason M. Bills 1419e1f26343SJason M. Bills // Go through the journal and use the timestamp to create a unique ID 1420e1f26343SJason M. Bills // for each entry 1421e1f26343SJason M. Bills sd_journal *journalTmp = nullptr; 1422e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1423e1f26343SJason M. Bills if (ret < 0) 1424e1f26343SJason M. Bills { 1425e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1426f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1427e1f26343SJason M. Bills return; 1428e1f26343SJason M. Bills } 1429e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1430e1f26343SJason M. Bills journalTmp, sd_journal_close); 1431e1f26343SJason M. Bills journalTmp = nullptr; 1432b01bf299SEd Tanous uint64_t entryCount = 0; 1433e85d6b16SJason M. Bills // Reset the unique ID on the first entry 1434e85d6b16SJason M. Bills bool firstEntry = true; 1435e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1436e1f26343SJason M. Bills { 1437193ad2faSJason M. Bills entryCount++; 1438193ad2faSJason M. Bills // Handle paging using skip (number of entries to skip from the 1439193ad2faSJason M. Bills // start) and top (number of entries to display) 1440193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1441193ad2faSJason M. Bills { 1442193ad2faSJason M. Bills continue; 1443193ad2faSJason M. Bills } 1444193ad2faSJason M. Bills 144516428a1aSJason M. Bills std::string idStr; 1446e85d6b16SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1447e1f26343SJason M. Bills { 1448e1f26343SJason M. Bills continue; 1449e1f26343SJason M. Bills } 1450e1f26343SJason M. Bills 1451e85d6b16SJason M. Bills if (firstEntry) 1452e85d6b16SJason M. Bills { 1453e85d6b16SJason M. Bills firstEntry = false; 1454e85d6b16SJason M. Bills } 1455e85d6b16SJason M. Bills 1456e1f26343SJason M. Bills logEntryArray.push_back({}); 1457c4bf6374SJason M. Bills nlohmann::json &bmcJournalLogEntry = logEntryArray.back(); 1458c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1459c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1460e1f26343SJason M. Bills { 1461f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1462e1f26343SJason M. Bills return; 1463e1f26343SJason M. Bills } 1464e1f26343SJason M. Bills } 1465193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1466193ad2faSJason M. Bills if (skip + top < entryCount) 1467193ad2faSJason M. Bills { 1468193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 1469c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 1470193ad2faSJason M. Bills std::to_string(skip + top); 1471193ad2faSJason M. Bills } 1472e1f26343SJason M. Bills } 1473e1f26343SJason M. Bills }; 1474e1f26343SJason M. Bills 1475c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node 1476e1f26343SJason M. Bills { 1477e1f26343SJason M. Bills public: 1478c4bf6374SJason M. Bills BMCJournalLogEntry(CrowApp &app) : 1479c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/", 1480e1f26343SJason M. Bills std::string()) 1481e1f26343SJason M. Bills { 1482e1f26343SJason M. Bills entityPrivileges = { 1483e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1484e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1485e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1486e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1487e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1488e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1489e1f26343SJason M. Bills } 1490e1f26343SJason M. Bills 1491e1f26343SJason M. Bills private: 1492e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1493e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1494e1f26343SJason M. Bills { 1495e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1496e1f26343SJason M. Bills if (params.size() != 1) 1497e1f26343SJason M. Bills { 1498f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1499e1f26343SJason M. Bills return; 1500e1f26343SJason M. Bills } 150116428a1aSJason M. Bills const std::string &entryID = params[0]; 1502e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1503e1f26343SJason M. Bills uint64_t ts = 0; 1504271584abSEd Tanous uint64_t index = 0; 150516428a1aSJason M. Bills if (!getTimestampFromID(asyncResp->res, entryID, ts, index)) 1506e1f26343SJason M. Bills { 150716428a1aSJason M. Bills return; 1508e1f26343SJason M. Bills } 1509e1f26343SJason M. Bills 1510e1f26343SJason M. Bills sd_journal *journalTmp = nullptr; 1511e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1512e1f26343SJason M. Bills if (ret < 0) 1513e1f26343SJason M. Bills { 1514e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1515f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1516e1f26343SJason M. Bills return; 1517e1f26343SJason M. Bills } 1518e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1519e1f26343SJason M. Bills journalTmp, sd_journal_close); 1520e1f26343SJason M. Bills journalTmp = nullptr; 1521e1f26343SJason M. Bills // Go to the timestamp in the log and move to the entry at the index 1522af07e3f5SJason M. Bills // tracking the unique ID 1523af07e3f5SJason M. Bills std::string idStr; 1524af07e3f5SJason M. Bills bool firstEntry = true; 1525e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 1526271584abSEd Tanous for (uint64_t i = 0; i <= index; i++) 1527e1f26343SJason M. Bills { 1528e1f26343SJason M. Bills sd_journal_next(journal.get()); 1529af07e3f5SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr, firstEntry)) 1530af07e3f5SJason M. Bills { 1531af07e3f5SJason M. Bills messages::internalError(asyncResp->res); 1532af07e3f5SJason M. Bills return; 1533af07e3f5SJason M. Bills } 1534af07e3f5SJason M. Bills if (firstEntry) 1535af07e3f5SJason M. Bills { 1536af07e3f5SJason M. Bills firstEntry = false; 1537af07e3f5SJason M. Bills } 1538e1f26343SJason M. Bills } 1539c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 1540af07e3f5SJason M. Bills if (idStr != entryID) 1541c4bf6374SJason M. Bills { 1542c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 1543c4bf6374SJason M. Bills return; 1544c4bf6374SJason M. Bills } 1545c4bf6374SJason M. Bills 1546c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 1547e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 1548e1f26343SJason M. Bills { 1549f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1550e1f26343SJason M. Bills return; 1551e1f26343SJason M. Bills } 1552e1f26343SJason M. Bills } 1553e1f26343SJason M. Bills }; 1554e1f26343SJason M. Bills 1555*c9bb6861Sraviteja-b class SystemDumpService : public Node 1556*c9bb6861Sraviteja-b { 1557*c9bb6861Sraviteja-b public: 1558*c9bb6861Sraviteja-b template <typename CrowApp> 1559*c9bb6861Sraviteja-b SystemDumpService(CrowApp &app) : 1560*c9bb6861Sraviteja-b Node(app, "/redfish/v1/Systems/system/LogServices/System/") 1561*c9bb6861Sraviteja-b { 1562*c9bb6861Sraviteja-b entityPrivileges = { 1563*c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 1564*c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 1565*c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1566*c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1567*c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1568*c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1569*c9bb6861Sraviteja-b } 1570*c9bb6861Sraviteja-b 1571*c9bb6861Sraviteja-b private: 1572*c9bb6861Sraviteja-b void doGet(crow::Response &res, const crow::Request &req, 1573*c9bb6861Sraviteja-b const std::vector<std::string> ¶ms) override 1574*c9bb6861Sraviteja-b { 1575*c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1576*c9bb6861Sraviteja-b 1577*c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 1578*c9bb6861Sraviteja-b "/redfish/v1/Systems/system/LogServices/System"; 1579*c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 1580*c9bb6861Sraviteja-b "#LogService.v1_1_0.LogService"; 1581*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "Dump Log Service"; 1582*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = "System Dump Log Service"; 1583*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Id"] = "System"; 1584*c9bb6861Sraviteja-b asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1585*c9bb6861Sraviteja-b asyncResp->res.jsonValue["LogEntryTypes"] = "Dump"; 1586*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Oem"]["DumpType"] = "System"; 1587*c9bb6861Sraviteja-b 1588*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Entries"] = { 1589*c9bb6861Sraviteja-b {"@odata.id", 1590*c9bb6861Sraviteja-b "/redfish/v1/Systems/system/LogServices/System/Entries"}}; 1591*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 1592*c9bb6861Sraviteja-b {"target", "/redfish/v1/Systems/system/LogServices/System/" 1593*c9bb6861Sraviteja-b "Actions/LogService.ClearLog"}}; 1594*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Actions"]["#LogService.CreateLog"] = { 1595*c9bb6861Sraviteja-b {"target", "/redfish/v1/Systems/system/LogServices/System/" 1596*c9bb6861Sraviteja-b "Actions/LogService.CreateLog"}}; 1597*c9bb6861Sraviteja-b } 1598*c9bb6861Sraviteja-b }; 1599*c9bb6861Sraviteja-b 1600*c9bb6861Sraviteja-b class SystemDumpEntryCollection : public Node 1601*c9bb6861Sraviteja-b { 1602*c9bb6861Sraviteja-b public: 1603*c9bb6861Sraviteja-b template <typename CrowApp> 1604*c9bb6861Sraviteja-b SystemDumpEntryCollection(CrowApp &app) : 1605*c9bb6861Sraviteja-b Node(app, "/redfish/v1/Systems/system/LogServices/System/Entries/") 1606*c9bb6861Sraviteja-b { 1607*c9bb6861Sraviteja-b entityPrivileges = { 1608*c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 1609*c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 1610*c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1611*c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1612*c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1613*c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1614*c9bb6861Sraviteja-b } 1615*c9bb6861Sraviteja-b 1616*c9bb6861Sraviteja-b private: 1617*c9bb6861Sraviteja-b /** 1618*c9bb6861Sraviteja-b * Functions triggers appropriate requests on DBus 1619*c9bb6861Sraviteja-b */ 1620*c9bb6861Sraviteja-b void doGet(crow::Response &res, const crow::Request &req, 1621*c9bb6861Sraviteja-b const std::vector<std::string> ¶ms) override 1622*c9bb6861Sraviteja-b { 1623*c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1624*c9bb6861Sraviteja-b 1625*c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.type"] = 1626*c9bb6861Sraviteja-b "#LogEntryCollection.LogEntryCollection"; 1627*c9bb6861Sraviteja-b asyncResp->res.jsonValue["@odata.id"] = 1628*c9bb6861Sraviteja-b "/redfish/v1/Systems/system/LogServices/System/Entries"; 1629*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Name"] = "System Dump Entries"; 1630*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Description"] = 1631*c9bb6861Sraviteja-b "Collection of System Dump Entries"; 1632*c9bb6861Sraviteja-b 1633*c9bb6861Sraviteja-b crow::connections::systemBus->async_method_call( 1634*c9bb6861Sraviteja-b [asyncResp](const boost::system::error_code ec, 1635*c9bb6861Sraviteja-b const crow::openbmc_mapper::GetSubTreeType &resp) { 1636*c9bb6861Sraviteja-b if (ec) 1637*c9bb6861Sraviteja-b { 1638*c9bb6861Sraviteja-b BMCWEB_LOG_ERROR << " resp_handler got error " << ec; 1639*c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 1640*c9bb6861Sraviteja-b return; 1641*c9bb6861Sraviteja-b } 1642*c9bb6861Sraviteja-b 1643*c9bb6861Sraviteja-b nlohmann::json &logArray = asyncResp->res.jsonValue["Members"]; 1644*c9bb6861Sraviteja-b logArray = nlohmann::json::array(); 1645*c9bb6861Sraviteja-b for (auto &object : resp) 1646*c9bb6861Sraviteja-b { 1647*c9bb6861Sraviteja-b const std::string &path = 1648*c9bb6861Sraviteja-b static_cast<const std::string &>(object.first); 1649*c9bb6861Sraviteja-b std::size_t lastPos = path.rfind("/"); 1650*c9bb6861Sraviteja-b if (lastPos == std::string::npos) 1651*c9bb6861Sraviteja-b { 1652*c9bb6861Sraviteja-b continue; 1653*c9bb6861Sraviteja-b } 1654*c9bb6861Sraviteja-b std::string logID = path.substr(lastPos + 1); 1655*c9bb6861Sraviteja-b logArray.push_back( 1656*c9bb6861Sraviteja-b {{"@odata.id", "/redfish/v1/Systems/system/LogServices/" 1657*c9bb6861Sraviteja-b "System/Entries/" + 1658*c9bb6861Sraviteja-b logID}}); 1659*c9bb6861Sraviteja-b } 1660*c9bb6861Sraviteja-b asyncResp->res.jsonValue["Members@odata.count"] = 1661*c9bb6861Sraviteja-b logArray.size(); 1662*c9bb6861Sraviteja-b }, 1663*c9bb6861Sraviteja-b "xyz.openbmc_project.ObjectMapper", 1664*c9bb6861Sraviteja-b "/xyz/openbmc_project/object_mapper", 1665*c9bb6861Sraviteja-b "xyz.openbmc_project.ObjectMapper", "GetSubTree", 1666*c9bb6861Sraviteja-b "/xyz/openbmc_project/dump", 0, 1667*c9bb6861Sraviteja-b std::array<const char *, 1>{ 1668*c9bb6861Sraviteja-b "xyz.openbmc_project.Dump.Entry.System"}); 1669*c9bb6861Sraviteja-b } 1670*c9bb6861Sraviteja-b }; 1671*c9bb6861Sraviteja-b 1672*c9bb6861Sraviteja-b class SystemDumpEntry : public Node 1673*c9bb6861Sraviteja-b { 1674*c9bb6861Sraviteja-b public: 1675*c9bb6861Sraviteja-b SystemDumpEntry(CrowApp &app) : 1676*c9bb6861Sraviteja-b Node(app, 1677*c9bb6861Sraviteja-b "/redfish/v1/Systems/system/LogServices/System/Entries/<str>/", 1678*c9bb6861Sraviteja-b std::string()) 1679*c9bb6861Sraviteja-b { 1680*c9bb6861Sraviteja-b entityPrivileges = { 1681*c9bb6861Sraviteja-b {boost::beast::http::verb::get, {{"Login"}}}, 1682*c9bb6861Sraviteja-b {boost::beast::http::verb::head, {{"Login"}}}, 1683*c9bb6861Sraviteja-b {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1684*c9bb6861Sraviteja-b {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1685*c9bb6861Sraviteja-b {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1686*c9bb6861Sraviteja-b {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1687*c9bb6861Sraviteja-b } 1688*c9bb6861Sraviteja-b 1689*c9bb6861Sraviteja-b private: 1690*c9bb6861Sraviteja-b void doGet(crow::Response &res, const crow::Request &req, 1691*c9bb6861Sraviteja-b const std::vector<std::string> ¶ms) override 1692*c9bb6861Sraviteja-b { 1693*c9bb6861Sraviteja-b std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1694*c9bb6861Sraviteja-b if (params.size() != 1) 1695*c9bb6861Sraviteja-b { 1696*c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 1697*c9bb6861Sraviteja-b return; 1698*c9bb6861Sraviteja-b } 1699*c9bb6861Sraviteja-b const std::string &entryID = params[0]; 1700*c9bb6861Sraviteja-b crow::connections::systemBus->async_method_call( 1701*c9bb6861Sraviteja-b [asyncResp, entryID](const boost::system::error_code ec, 1702*c9bb6861Sraviteja-b GetManagedObjectsType &resp) { 1703*c9bb6861Sraviteja-b if (ec) 1704*c9bb6861Sraviteja-b { 1705*c9bb6861Sraviteja-b BMCWEB_LOG_ERROR 1706*c9bb6861Sraviteja-b << "SystemDumpEntry resp_handler got error " << ec; 1707*c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 1708*c9bb6861Sraviteja-b return; 1709*c9bb6861Sraviteja-b } 1710*c9bb6861Sraviteja-b 1711*c9bb6861Sraviteja-b for (auto &objectPath : resp) 1712*c9bb6861Sraviteja-b { 1713*c9bb6861Sraviteja-b if (objectPath.first.str.find( 1714*c9bb6861Sraviteja-b "/xyz/openbmc_project/dump/entry/" + entryID) == 1715*c9bb6861Sraviteja-b std::string::npos) 1716*c9bb6861Sraviteja-b { 1717*c9bb6861Sraviteja-b continue; 1718*c9bb6861Sraviteja-b } 1719*c9bb6861Sraviteja-b 1720*c9bb6861Sraviteja-b bool foundSystemDumpEntry = false; 1721*c9bb6861Sraviteja-b for (auto &interfaceMap : objectPath.second) 1722*c9bb6861Sraviteja-b { 1723*c9bb6861Sraviteja-b if (interfaceMap.first == 1724*c9bb6861Sraviteja-b "xyz.openbmc_project.Dump.Entry.System") 1725*c9bb6861Sraviteja-b { 1726*c9bb6861Sraviteja-b foundSystemDumpEntry = true; 1727*c9bb6861Sraviteja-b break; 1728*c9bb6861Sraviteja-b } 1729*c9bb6861Sraviteja-b } 1730*c9bb6861Sraviteja-b if (foundSystemDumpEntry == false) 1731*c9bb6861Sraviteja-b { 1732*c9bb6861Sraviteja-b BMCWEB_LOG_DEBUG << "Can't find System Dump Entry"; 1733*c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 1734*c9bb6861Sraviteja-b return; 1735*c9bb6861Sraviteja-b } 1736*c9bb6861Sraviteja-b 1737*c9bb6861Sraviteja-b std::string timestamp{}; 1738*c9bb6861Sraviteja-b uint64_t size = 0; 1739*c9bb6861Sraviteja-b 1740*c9bb6861Sraviteja-b for (auto &interfaceMap : objectPath.second) 1741*c9bb6861Sraviteja-b { 1742*c9bb6861Sraviteja-b if (interfaceMap.first == 1743*c9bb6861Sraviteja-b "xyz.openbmc_project.Dump.Entry") 1744*c9bb6861Sraviteja-b { 1745*c9bb6861Sraviteja-b for (auto &propertyMap : interfaceMap.second) 1746*c9bb6861Sraviteja-b { 1747*c9bb6861Sraviteja-b if (propertyMap.first == "Size") 1748*c9bb6861Sraviteja-b { 1749*c9bb6861Sraviteja-b auto sizePtr = std::get_if<uint64_t>( 1750*c9bb6861Sraviteja-b &propertyMap.second); 1751*c9bb6861Sraviteja-b if (sizePtr == nullptr) 1752*c9bb6861Sraviteja-b { 1753*c9bb6861Sraviteja-b messages::propertyMissing( 1754*c9bb6861Sraviteja-b asyncResp->res, "Size"); 1755*c9bb6861Sraviteja-b break; 1756*c9bb6861Sraviteja-b } 1757*c9bb6861Sraviteja-b size = *sizePtr; 1758*c9bb6861Sraviteja-b break; 1759*c9bb6861Sraviteja-b } 1760*c9bb6861Sraviteja-b } 1761*c9bb6861Sraviteja-b } 1762*c9bb6861Sraviteja-b else if (interfaceMap.first == 1763*c9bb6861Sraviteja-b "xyz.openbmc_project.Time.EpochTime") 1764*c9bb6861Sraviteja-b { 1765*c9bb6861Sraviteja-b for (auto &propertyMap : interfaceMap.second) 1766*c9bb6861Sraviteja-b { 1767*c9bb6861Sraviteja-b if (propertyMap.first == "Elapsed") 1768*c9bb6861Sraviteja-b { 1769*c9bb6861Sraviteja-b const uint64_t *usecsTimeStamp = 1770*c9bb6861Sraviteja-b std::get_if<uint64_t>( 1771*c9bb6861Sraviteja-b &propertyMap.second); 1772*c9bb6861Sraviteja-b if (usecsTimeStamp == nullptr) 1773*c9bb6861Sraviteja-b { 1774*c9bb6861Sraviteja-b messages::propertyMissing( 1775*c9bb6861Sraviteja-b asyncResp->res, "Elapsed"); 1776*c9bb6861Sraviteja-b break; 1777*c9bb6861Sraviteja-b } 1778*c9bb6861Sraviteja-b getTimestampStr(*usecsTimeStamp, timestamp); 1779*c9bb6861Sraviteja-b break; 1780*c9bb6861Sraviteja-b } 1781*c9bb6861Sraviteja-b } 1782*c9bb6861Sraviteja-b } 1783*c9bb6861Sraviteja-b } 1784*c9bb6861Sraviteja-b asyncResp->res.jsonValue = { 1785*c9bb6861Sraviteja-b {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1786*c9bb6861Sraviteja-b {"@odata.id", 1787*c9bb6861Sraviteja-b "/redfish/v1/Systems/system/LogServices/System/" 1788*c9bb6861Sraviteja-b "Entries/" + 1789*c9bb6861Sraviteja-b entryID}, 1790*c9bb6861Sraviteja-b {"Name", "System Dump Entry"}, 1791*c9bb6861Sraviteja-b {"Id", entryID}, 1792*c9bb6861Sraviteja-b {"SizeInB", size}, 1793*c9bb6861Sraviteja-b {"EntryType", "Dump"}, 1794*c9bb6861Sraviteja-b {"EntryCode", "User generated dump"}, 1795*c9bb6861Sraviteja-b {"Created", timestamp}}; 1796*c9bb6861Sraviteja-b 1797*c9bb6861Sraviteja-b asyncResp->res 1798*c9bb6861Sraviteja-b .jsonValue["Actions"]["#LogEntry.DownloadLog"] = { 1799*c9bb6861Sraviteja-b {"target", 1800*c9bb6861Sraviteja-b "/redfish/v1/Systems/system/LogServices/System/" 1801*c9bb6861Sraviteja-b "Entries/" + 1802*c9bb6861Sraviteja-b entryID + "/Actions/LogEntry.DownloadLog"}}; 1803*c9bb6861Sraviteja-b } 1804*c9bb6861Sraviteja-b }, 1805*c9bb6861Sraviteja-b "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump", 1806*c9bb6861Sraviteja-b "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 1807*c9bb6861Sraviteja-b } 1808*c9bb6861Sraviteja-b 1809*c9bb6861Sraviteja-b void doDelete(crow::Response &res, const crow::Request &req, 1810*c9bb6861Sraviteja-b const std::vector<std::string> ¶ms) override 1811*c9bb6861Sraviteja-b { 1812*c9bb6861Sraviteja-b BMCWEB_LOG_DEBUG << "Do delete single dump entry"; 1813*c9bb6861Sraviteja-b 1814*c9bb6861Sraviteja-b auto asyncResp = std::make_shared<AsyncResp>(res); 1815*c9bb6861Sraviteja-b 1816*c9bb6861Sraviteja-b if (params.size() != 1) 1817*c9bb6861Sraviteja-b { 1818*c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 1819*c9bb6861Sraviteja-b return; 1820*c9bb6861Sraviteja-b } 1821*c9bb6861Sraviteja-b std::string entryID = params[0]; 1822*c9bb6861Sraviteja-b 1823*c9bb6861Sraviteja-b crow::connections::systemBus->async_method_call( 1824*c9bb6861Sraviteja-b [asyncResp, 1825*c9bb6861Sraviteja-b entryID](const boost::system::error_code ec, 1826*c9bb6861Sraviteja-b const crow::openbmc_mapper::GetSubTreeType &resp) { 1827*c9bb6861Sraviteja-b if (ec) 1828*c9bb6861Sraviteja-b { 1829*c9bb6861Sraviteja-b BMCWEB_LOG_ERROR << " resp_handler got error " << ec; 1830*c9bb6861Sraviteja-b messages::internalError(asyncResp->res); 1831*c9bb6861Sraviteja-b return; 1832*c9bb6861Sraviteja-b } 1833*c9bb6861Sraviteja-b 1834*c9bb6861Sraviteja-b for (auto &object : resp) 1835*c9bb6861Sraviteja-b { 1836*c9bb6861Sraviteja-b const std::string &path = 1837*c9bb6861Sraviteja-b static_cast<const std::string &>(object.first); 1838*c9bb6861Sraviteja-b 1839*c9bb6861Sraviteja-b std::size_t pos = path.rfind( 1840*c9bb6861Sraviteja-b "/xyz/openbmc_project/dump/entry/" + entryID); 1841*c9bb6861Sraviteja-b if (pos != std::string::npos) 1842*c9bb6861Sraviteja-b { 1843*c9bb6861Sraviteja-b deleteSystemDumpEntry(asyncResp->res, entryID); 1844*c9bb6861Sraviteja-b return; 1845*c9bb6861Sraviteja-b } 1846*c9bb6861Sraviteja-b } 1847*c9bb6861Sraviteja-b }, 1848*c9bb6861Sraviteja-b "xyz.openbmc_project.ObjectMapper", 1849*c9bb6861Sraviteja-b "/xyz/openbmc_project/object_mapper", 1850*c9bb6861Sraviteja-b "xyz.openbmc_project.ObjectMapper", "GetSubTree", 1851*c9bb6861Sraviteja-b "/xyz/openbmc_project/dump", 0, 1852*c9bb6861Sraviteja-b std::array<const char *, 1>{ 1853*c9bb6861Sraviteja-b "xyz.openbmc_project.Dump.Entry.System"}); 1854*c9bb6861Sraviteja-b } 1855*c9bb6861Sraviteja-b }; 1856*c9bb6861Sraviteja-b 1857424c4176SJason M. Bills class CrashdumpService : public Node 1858e1f26343SJason M. Bills { 1859e1f26343SJason M. Bills public: 1860e1f26343SJason M. Bills template <typename CrowApp> 1861424c4176SJason M. Bills CrashdumpService(CrowApp &app) : 1862424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 18631da66f75SEd Tanous { 18643946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 18653946028dSAppaRao Puli // method for security reasons. 18661da66f75SEd Tanous entityPrivileges = { 18673946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 18683946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 1869e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1870e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1871e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1872e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 18731da66f75SEd Tanous } 18741da66f75SEd Tanous 18751da66f75SEd Tanous private: 18761da66f75SEd Tanous /** 18771da66f75SEd Tanous * Functions triggers appropriate requests on DBus 18781da66f75SEd Tanous */ 18791da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 18801da66f75SEd Tanous const std::vector<std::string> ¶ms) override 18811da66f75SEd Tanous { 1882e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 18831da66f75SEd Tanous // Copy over the static data to include the entries added by SubRoute 18840f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1885424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 1886e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1887e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 18884f50ae4bSGunnar Mills asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service"; 18894f50ae4bSGunnar Mills asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service"; 18904f50ae4bSGunnar Mills asyncResp->res.jsonValue["Id"] = "Oem Crashdump"; 1891e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1892e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 1893cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1894cd50aa42SJason M. Bills {"@odata.id", 1895424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 1896e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 18975b61b5e8SJason M. Bills {"#LogService.ClearLog", 18985b61b5e8SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 18995b61b5e8SJason M. Bills "Actions/LogService.ClearLog"}}}, 19001da66f75SEd Tanous {"Oem", 1901424c4176SJason M. Bills {{"#Crashdump.OnDemand", 1902424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 1903424c4176SJason M. Bills "Actions/Oem/Crashdump.OnDemand"}}}}}}; 19041da66f75SEd Tanous 19051da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI 1906e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"]["Oem"].push_back( 1907424c4176SJason M. Bills {"#Crashdump.SendRawPeci", 190808a4e4b5SAnthony Wilson {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 1909424c4176SJason M. Bills "Actions/Oem/Crashdump.SendRawPeci"}}}); 19101da66f75SEd Tanous #endif 19111da66f75SEd Tanous } 19121da66f75SEd Tanous }; 19131da66f75SEd Tanous 19145b61b5e8SJason M. Bills class CrashdumpClear : public Node 19155b61b5e8SJason M. Bills { 19165b61b5e8SJason M. Bills public: 19175b61b5e8SJason M. Bills CrashdumpClear(CrowApp &app) : 19185b61b5e8SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/" 19195b61b5e8SJason M. Bills "LogService.ClearLog/") 19205b61b5e8SJason M. Bills { 19213946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 19223946028dSAppaRao Puli // method for security reasons. 19235b61b5e8SJason M. Bills entityPrivileges = { 19243946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 19253946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 19265b61b5e8SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 19275b61b5e8SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 19285b61b5e8SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 19295b61b5e8SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 19305b61b5e8SJason M. Bills } 19315b61b5e8SJason M. Bills 19325b61b5e8SJason M. Bills private: 19335b61b5e8SJason M. Bills void doPost(crow::Response &res, const crow::Request &req, 19345b61b5e8SJason M. Bills const std::vector<std::string> ¶ms) override 19355b61b5e8SJason M. Bills { 19365b61b5e8SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 19375b61b5e8SJason M. Bills 19385b61b5e8SJason M. Bills crow::connections::systemBus->async_method_call( 19395b61b5e8SJason M. Bills [asyncResp](const boost::system::error_code ec, 19405b61b5e8SJason M. Bills const std::string &resp) { 19415b61b5e8SJason M. Bills if (ec) 19425b61b5e8SJason M. Bills { 19435b61b5e8SJason M. Bills messages::internalError(asyncResp->res); 19445b61b5e8SJason M. Bills return; 19455b61b5e8SJason M. Bills } 19465b61b5e8SJason M. Bills messages::success(asyncResp->res); 19475b61b5e8SJason M. Bills }, 19485b61b5e8SJason M. Bills crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll"); 19495b61b5e8SJason M. Bills } 19505b61b5e8SJason M. Bills }; 19515b61b5e8SJason M. Bills 1952e855dd28SJason M. Bills static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp, 1953e855dd28SJason M. Bills const std::string &logID, 1954e855dd28SJason M. Bills nlohmann::json &logEntryJson) 1955e855dd28SJason M. Bills { 1956043a0536SJohnathan Mantey auto getStoredLogCallback = 1957043a0536SJohnathan Mantey [asyncResp, logID, &logEntryJson]( 1958e855dd28SJason M. Bills const boost::system::error_code ec, 1959043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>> ¶ms) { 1960e855dd28SJason M. Bills if (ec) 1961e855dd28SJason M. Bills { 1962e855dd28SJason M. Bills BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 19631ddcf01aSJason M. Bills if (ec.value() == 19641ddcf01aSJason M. Bills boost::system::linux_error::bad_request_descriptor) 19651ddcf01aSJason M. Bills { 1966043a0536SJohnathan Mantey messages::resourceNotFound(asyncResp->res, "LogEntry", 1967043a0536SJohnathan Mantey logID); 19681ddcf01aSJason M. Bills } 19691ddcf01aSJason M. Bills else 19701ddcf01aSJason M. Bills { 1971e855dd28SJason M. Bills messages::internalError(asyncResp->res); 19721ddcf01aSJason M. Bills } 1973e855dd28SJason M. Bills return; 1974e855dd28SJason M. Bills } 1975043a0536SJohnathan Mantey 1976043a0536SJohnathan Mantey std::string timestamp{}; 1977043a0536SJohnathan Mantey std::string filename{}; 1978043a0536SJohnathan Mantey std::string logfile{}; 1979043a0536SJohnathan Mantey ParseCrashdumpParameters(params, filename, timestamp, logfile); 1980043a0536SJohnathan Mantey 1981043a0536SJohnathan Mantey if (filename.empty() || timestamp.empty()) 1982e855dd28SJason M. Bills { 1983043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, logID); 1984e855dd28SJason M. Bills return; 1985e855dd28SJason M. Bills } 1986e855dd28SJason M. Bills 1987043a0536SJohnathan Mantey std::string crashdumpURI = 1988e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 1989043a0536SJohnathan Mantey logID + "/" + filename; 1990043a0536SJohnathan Mantey logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1991043a0536SJohnathan Mantey {"@odata.id", "/redfish/v1/Systems/system/" 1992043a0536SJohnathan Mantey "LogServices/Crashdump/Entries/" + 1993e855dd28SJason M. Bills logID}, 1994e855dd28SJason M. Bills {"Name", "CPU Crashdump"}, 1995e855dd28SJason M. Bills {"Id", logID}, 1996e855dd28SJason M. Bills {"EntryType", "Oem"}, 1997e855dd28SJason M. Bills {"OemRecordFormat", "Crashdump URI"}, 1998043a0536SJohnathan Mantey {"Message", std::move(crashdumpURI)}, 1999043a0536SJohnathan Mantey {"Created", std::move(timestamp)}}; 2000e855dd28SJason M. Bills }; 2001e855dd28SJason M. Bills crow::connections::systemBus->async_method_call( 20025b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 20035b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2004043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 2005e855dd28SJason M. Bills } 2006e855dd28SJason M. Bills 2007424c4176SJason M. Bills class CrashdumpEntryCollection : public Node 20081da66f75SEd Tanous { 20091da66f75SEd Tanous public: 20101da66f75SEd Tanous template <typename CrowApp> 2011424c4176SJason M. Bills CrashdumpEntryCollection(CrowApp &app) : 2012424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 20131da66f75SEd Tanous { 20143946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 20153946028dSAppaRao Puli // method for security reasons. 20161da66f75SEd Tanous entityPrivileges = { 20173946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 20183946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2019e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2020e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2021e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2022e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 20231da66f75SEd Tanous } 20241da66f75SEd Tanous 20251da66f75SEd Tanous private: 20261da66f75SEd Tanous /** 20271da66f75SEd Tanous * Functions triggers appropriate requests on DBus 20281da66f75SEd Tanous */ 20291da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 20301da66f75SEd Tanous const std::vector<std::string> ¶ms) override 20311da66f75SEd Tanous { 2032e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 20331da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 20341da66f75SEd Tanous // it has a duplicate entry for members 2035e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 2036e1f26343SJason M. Bills const boost::system::error_code ec, 20371da66f75SEd Tanous const std::vector<std::string> &resp) { 20381da66f75SEd Tanous if (ec) 20391da66f75SEd Tanous { 20401da66f75SEd Tanous if (ec.value() != 20411da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 20421da66f75SEd Tanous { 20431da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 20441da66f75SEd Tanous << ec.message(); 2045f12894f8SJason M. Bills messages::internalError(asyncResp->res); 20461da66f75SEd Tanous return; 20471da66f75SEd Tanous } 20481da66f75SEd Tanous } 2049e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 20501da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 20510f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2052424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 2053424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 2054e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 2055424c4176SJason M. Bills "Collection of Crashdump Entries"; 2056e1f26343SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 2057e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 2058e855dd28SJason M. Bills std::vector<std::string> logIDs; 2059e855dd28SJason M. Bills // Get the list of log entries and build up an empty array big 2060e855dd28SJason M. Bills // enough to hold them 20611da66f75SEd Tanous for (const std::string &objpath : resp) 20621da66f75SEd Tanous { 2063e855dd28SJason M. Bills // Get the log ID 20644ed77cd5SEd Tanous std::size_t lastPos = objpath.rfind("/"); 2065e855dd28SJason M. Bills if (lastPos == std::string::npos) 20661da66f75SEd Tanous { 2067e855dd28SJason M. Bills continue; 20681da66f75SEd Tanous } 2069e855dd28SJason M. Bills logIDs.emplace_back(objpath.substr(lastPos + 1)); 2070e855dd28SJason M. Bills 2071e855dd28SJason M. Bills // Add a space for the log entry to the array 2072e855dd28SJason M. Bills logEntryArray.push_back({}); 2073e855dd28SJason M. Bills } 2074e855dd28SJason M. Bills // Now go through and set up async calls to fill in the entries 2075e855dd28SJason M. Bills size_t index = 0; 2076e855dd28SJason M. Bills for (const std::string &logID : logIDs) 2077e855dd28SJason M. Bills { 2078e855dd28SJason M. Bills // Add the log entry to the array 2079e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]); 20801da66f75SEd Tanous } 2081e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 2082e1f26343SJason M. Bills logEntryArray.size(); 20831da66f75SEd Tanous }; 20841da66f75SEd Tanous crow::connections::systemBus->async_method_call( 20851da66f75SEd Tanous std::move(getLogEntriesCallback), 20861da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 20871da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 20881da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 20895b61b5e8SJason M. Bills std::array<const char *, 1>{crashdumpInterface}); 20901da66f75SEd Tanous } 20911da66f75SEd Tanous }; 20921da66f75SEd Tanous 2093424c4176SJason M. Bills class CrashdumpEntry : public Node 20941da66f75SEd Tanous { 20951da66f75SEd Tanous public: 2096424c4176SJason M. Bills CrashdumpEntry(CrowApp &app) : 2097d53dd41fSJason M. Bills Node(app, 2098424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/", 20991da66f75SEd Tanous std::string()) 21001da66f75SEd Tanous { 21013946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 21023946028dSAppaRao Puli // method for security reasons. 21031da66f75SEd Tanous entityPrivileges = { 21043946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 21053946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2106e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2107e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2108e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2109e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 21101da66f75SEd Tanous } 21111da66f75SEd Tanous 21121da66f75SEd Tanous private: 21131da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 21141da66f75SEd Tanous const std::vector<std::string> ¶ms) override 21151da66f75SEd Tanous { 2116e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 21171da66f75SEd Tanous if (params.size() != 1) 21181da66f75SEd Tanous { 2119f12894f8SJason M. Bills messages::internalError(asyncResp->res); 21201da66f75SEd Tanous return; 21211da66f75SEd Tanous } 2122e855dd28SJason M. Bills const std::string &logID = params[0]; 2123e855dd28SJason M. Bills logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue); 2124e855dd28SJason M. Bills } 2125e855dd28SJason M. Bills }; 2126e855dd28SJason M. Bills 2127e855dd28SJason M. Bills class CrashdumpFile : public Node 2128e855dd28SJason M. Bills { 2129e855dd28SJason M. Bills public: 2130e855dd28SJason M. Bills CrashdumpFile(CrowApp &app) : 2131e855dd28SJason M. Bills Node(app, 2132e855dd28SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/" 2133e855dd28SJason M. Bills "<str>/", 2134e855dd28SJason M. Bills std::string(), std::string()) 2135e855dd28SJason M. Bills { 21363946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 21373946028dSAppaRao Puli // method for security reasons. 2138e855dd28SJason M. Bills entityPrivileges = { 21393946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 21403946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 2141e855dd28SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2142e855dd28SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2143e855dd28SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2144e855dd28SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2145e855dd28SJason M. Bills } 2146e855dd28SJason M. Bills 2147e855dd28SJason M. Bills private: 2148e855dd28SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 2149e855dd28SJason M. Bills const std::vector<std::string> ¶ms) override 2150e855dd28SJason M. Bills { 2151e855dd28SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2152e855dd28SJason M. Bills if (params.size() != 2) 2153e855dd28SJason M. Bills { 2154e855dd28SJason M. Bills messages::internalError(asyncResp->res); 2155e855dd28SJason M. Bills return; 2156e855dd28SJason M. Bills } 2157e855dd28SJason M. Bills const std::string &logID = params[0]; 2158e855dd28SJason M. Bills const std::string &fileName = params[1]; 2159e855dd28SJason M. Bills 2160043a0536SJohnathan Mantey auto getStoredLogCallback = 2161043a0536SJohnathan Mantey [asyncResp, logID, fileName]( 2162abf2add6SEd Tanous const boost::system::error_code ec, 2163043a0536SJohnathan Mantey const std::vector<std::pair<std::string, VariantType>> &resp) { 21641da66f75SEd Tanous if (ec) 21651da66f75SEd Tanous { 2166043a0536SJohnathan Mantey BMCWEB_LOG_DEBUG << "failed to get log ec: " 2167043a0536SJohnathan Mantey << ec.message(); 2168f12894f8SJason M. Bills messages::internalError(asyncResp->res); 21691da66f75SEd Tanous return; 21701da66f75SEd Tanous } 2171e855dd28SJason M. Bills 2172043a0536SJohnathan Mantey std::string dbusFilename{}; 2173043a0536SJohnathan Mantey std::string dbusTimestamp{}; 2174043a0536SJohnathan Mantey std::string dbusFilepath{}; 2175043a0536SJohnathan Mantey 2176043a0536SJohnathan Mantey ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp, 2177043a0536SJohnathan Mantey dbusFilepath); 2178043a0536SJohnathan Mantey 2179043a0536SJohnathan Mantey if (dbusFilename.empty() || dbusTimestamp.empty() || 2180043a0536SJohnathan Mantey dbusFilepath.empty()) 21811da66f75SEd Tanous { 2182e855dd28SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, fileName); 21831da66f75SEd Tanous return; 21841da66f75SEd Tanous } 2185e855dd28SJason M. Bills 2186043a0536SJohnathan Mantey // Verify the file name parameter is correct 2187043a0536SJohnathan Mantey if (fileName != dbusFilename) 2188043a0536SJohnathan Mantey { 2189043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2190043a0536SJohnathan Mantey return; 2191043a0536SJohnathan Mantey } 2192043a0536SJohnathan Mantey 2193043a0536SJohnathan Mantey if (!std::filesystem::exists(dbusFilepath)) 2194043a0536SJohnathan Mantey { 2195043a0536SJohnathan Mantey messages::resourceMissingAtURI(asyncResp->res, fileName); 2196043a0536SJohnathan Mantey return; 2197043a0536SJohnathan Mantey } 2198043a0536SJohnathan Mantey std::ifstream ifs(dbusFilepath, std::ios::in | 2199043a0536SJohnathan Mantey std::ios::binary | 2200043a0536SJohnathan Mantey std::ios::ate); 2201043a0536SJohnathan Mantey std::ifstream::pos_type fileSize = ifs.tellg(); 2202043a0536SJohnathan Mantey if (fileSize < 0) 2203043a0536SJohnathan Mantey { 2204043a0536SJohnathan Mantey messages::generalError(asyncResp->res); 2205043a0536SJohnathan Mantey return; 2206043a0536SJohnathan Mantey } 2207043a0536SJohnathan Mantey ifs.seekg(0, std::ios::beg); 2208043a0536SJohnathan Mantey 2209043a0536SJohnathan Mantey auto crashData = std::make_unique<char[]>( 2210043a0536SJohnathan Mantey static_cast<unsigned int>(fileSize)); 2211043a0536SJohnathan Mantey 2212043a0536SJohnathan Mantey ifs.read(crashData.get(), static_cast<int>(fileSize)); 2213043a0536SJohnathan Mantey 2214043a0536SJohnathan Mantey // The cast to std::string is intentional in order to use the 2215043a0536SJohnathan Mantey // assign() that applies move mechanics 2216043a0536SJohnathan Mantey asyncResp->res.body().assign( 2217043a0536SJohnathan Mantey static_cast<std::string>(crashData.get())); 2218043a0536SJohnathan Mantey 2219043a0536SJohnathan Mantey // Configure this to be a file download when accessed from 2220043a0536SJohnathan Mantey // a browser 2221e855dd28SJason M. Bills asyncResp->res.addHeader("Content-Disposition", "attachment"); 22221da66f75SEd Tanous }; 22231da66f75SEd Tanous crow::connections::systemBus->async_method_call( 22245b61b5e8SJason M. Bills std::move(getStoredLogCallback), crashdumpObject, 22255b61b5e8SJason M. Bills crashdumpPath + std::string("/") + logID, 2226043a0536SJohnathan Mantey "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface); 22271da66f75SEd Tanous } 22281da66f75SEd Tanous }; 22291da66f75SEd Tanous 2230424c4176SJason M. Bills class OnDemandCrashdump : public Node 22311da66f75SEd Tanous { 22321da66f75SEd Tanous public: 2233424c4176SJason M. Bills OnDemandCrashdump(CrowApp &app) : 2234424c4176SJason M. Bills Node(app, 2235424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2236424c4176SJason M. Bills "Crashdump.OnDemand/") 22371da66f75SEd Tanous { 22383946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 22393946028dSAppaRao Puli // method for security reasons. 22401da66f75SEd Tanous entityPrivileges = { 22413946028dSAppaRao Puli {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 22423946028dSAppaRao Puli {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 22433946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 22443946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 22453946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 22463946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 22471da66f75SEd Tanous } 22481da66f75SEd Tanous 22491da66f75SEd Tanous private: 22501da66f75SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 22511da66f75SEd Tanous const std::vector<std::string> ¶ms) override 22521da66f75SEd Tanous { 2253e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 22541da66f75SEd Tanous 2255fe306728SJames Feist auto generateonDemandLogCallback = [asyncResp, 2256fe306728SJames Feist req](const boost::system::error_code 225746229577SJames Feist ec, 22581da66f75SEd Tanous const std::string &resp) { 22591da66f75SEd Tanous if (ec) 22601da66f75SEd Tanous { 226146229577SJames Feist if (ec.value() == boost::system::errc::operation_not_supported) 22621da66f75SEd Tanous { 2263f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 22641da66f75SEd Tanous } 22654363d3b2SJason M. Bills else if (ec.value() == 22664363d3b2SJason M. Bills boost::system::errc::device_or_resource_busy) 22674363d3b2SJason M. Bills { 22684363d3b2SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, 22694363d3b2SJason M. Bills "60"); 22704363d3b2SJason M. Bills } 22711da66f75SEd Tanous else 22721da66f75SEd Tanous { 2273f12894f8SJason M. Bills messages::internalError(asyncResp->res); 22741da66f75SEd Tanous } 22751da66f75SEd Tanous return; 22761da66f75SEd Tanous } 227746229577SJames Feist std::shared_ptr<task::TaskData> task = task::TaskData::createTask( 227866afe4faSJames Feist [](boost::system::error_code err, sdbusplus::message::message &, 227966afe4faSJames Feist const std::shared_ptr<task::TaskData> &taskData) { 228066afe4faSJames Feist if (!err) 228166afe4faSJames Feist { 228266afe4faSJames Feist taskData->messages.emplace_back(messages::success()); 2283831d6b09SJames Feist taskData->state = "Completed"; 228466afe4faSJames Feist } 228532898ceaSJames Feist return task::completed; 228666afe4faSJames Feist }, 228746229577SJames Feist "type='signal',interface='org.freedesktop.DBus.Properties'," 228846229577SJames Feist "member='PropertiesChanged',arg0namespace='com.intel." 228946229577SJames Feist "crashdump'"); 229046229577SJames Feist task->startTimer(std::chrono::minutes(5)); 229146229577SJames Feist task->populateResp(asyncResp->res); 2292fe306728SJames Feist task->payload.emplace(req); 22931da66f75SEd Tanous }; 22941da66f75SEd Tanous crow::connections::systemBus->async_method_call( 22955b61b5e8SJason M. Bills std::move(generateonDemandLogCallback), crashdumpObject, 22965b61b5e8SJason M. Bills crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog"); 22971da66f75SEd Tanous } 22981da66f75SEd Tanous }; 22991da66f75SEd Tanous 2300e1f26343SJason M. Bills class SendRawPECI : public Node 23011da66f75SEd Tanous { 23021da66f75SEd Tanous public: 2303e1f26343SJason M. Bills SendRawPECI(CrowApp &app) : 2304424c4176SJason M. Bills Node(app, 2305424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 2306424c4176SJason M. Bills "Crashdump.SendRawPeci/") 23071da66f75SEd Tanous { 23083946028dSAppaRao Puli // Note: Deviated from redfish privilege registry for GET & HEAD 23093946028dSAppaRao Puli // method for security reasons. 23101da66f75SEd Tanous entityPrivileges = { 23111da66f75SEd Tanous {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 23121da66f75SEd Tanous {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 23131da66f75SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 23141da66f75SEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 23151da66f75SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 23161da66f75SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 23171da66f75SEd Tanous } 23181da66f75SEd Tanous 23191da66f75SEd Tanous private: 23201da66f75SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 23211da66f75SEd Tanous const std::vector<std::string> ¶ms) override 23221da66f75SEd Tanous { 2323e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 23248724c297SKarthick Sundarrajan std::vector<std::vector<uint8_t>> peciCommands; 23258724c297SKarthick Sundarrajan 23268724c297SKarthick Sundarrajan nlohmann::json reqJson = 23278724c297SKarthick Sundarrajan nlohmann::json::parse(req.body, nullptr, false); 23288724c297SKarthick Sundarrajan if (reqJson.find("PECICommands") != reqJson.end()) 23298724c297SKarthick Sundarrajan { 23308724c297SKarthick Sundarrajan if (!json_util::readJson(req, res, "PECICommands", peciCommands)) 23318724c297SKarthick Sundarrajan { 23328724c297SKarthick Sundarrajan return; 23338724c297SKarthick Sundarrajan } 23348724c297SKarthick Sundarrajan uint32_t idx = 0; 23358724c297SKarthick Sundarrajan for (auto const &cmd : peciCommands) 23368724c297SKarthick Sundarrajan { 23378724c297SKarthick Sundarrajan if (cmd.size() < 3) 23388724c297SKarthick Sundarrajan { 23398724c297SKarthick Sundarrajan std::string s("["); 23408724c297SKarthick Sundarrajan for (auto const &val : cmd) 23418724c297SKarthick Sundarrajan { 23428724c297SKarthick Sundarrajan if (val != *cmd.begin()) 23438724c297SKarthick Sundarrajan { 23448724c297SKarthick Sundarrajan s += ","; 23458724c297SKarthick Sundarrajan } 23468724c297SKarthick Sundarrajan s += std::to_string(val); 23478724c297SKarthick Sundarrajan } 23488724c297SKarthick Sundarrajan s += "]"; 23498724c297SKarthick Sundarrajan messages::actionParameterValueFormatError( 23508724c297SKarthick Sundarrajan res, s, "PECICommands[" + std::to_string(idx) + "]", 23518724c297SKarthick Sundarrajan "SendRawPeci"); 23528724c297SKarthick Sundarrajan return; 23538724c297SKarthick Sundarrajan } 23548724c297SKarthick Sundarrajan idx++; 23558724c297SKarthick Sundarrajan } 23568724c297SKarthick Sundarrajan } 23578724c297SKarthick Sundarrajan else 23588724c297SKarthick Sundarrajan { 23598724c297SKarthick Sundarrajan /* This interface is deprecated */ 2360b1556427SEd Tanous uint8_t clientAddress = 0; 2361b1556427SEd Tanous uint8_t readLength = 0; 23621da66f75SEd Tanous std::vector<uint8_t> peciCommand; 2363b1556427SEd Tanous if (!json_util::readJson(req, res, "ClientAddress", clientAddress, 2364b1556427SEd Tanous "ReadLength", readLength, "PECICommand", 2365b1556427SEd Tanous peciCommand)) 23661da66f75SEd Tanous { 23671da66f75SEd Tanous return; 23681da66f75SEd Tanous } 23698724c297SKarthick Sundarrajan peciCommands.push_back({clientAddress, 0, readLength}); 23708724c297SKarthick Sundarrajan peciCommands[0].insert(peciCommands[0].end(), peciCommand.begin(), 23718724c297SKarthick Sundarrajan peciCommand.end()); 23728724c297SKarthick Sundarrajan } 23731da66f75SEd Tanous // Callback to return the Raw PECI response 2374e1f26343SJason M. Bills auto sendRawPECICallback = 2375e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 23768724c297SKarthick Sundarrajan const std::vector<std::vector<uint8_t>> &resp) { 23771da66f75SEd Tanous if (ec) 23781da66f75SEd Tanous { 23798724c297SKarthick Sundarrajan BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: " 23801da66f75SEd Tanous << ec.message(); 2381f12894f8SJason M. Bills messages::internalError(asyncResp->res); 23821da66f75SEd Tanous return; 23831da66f75SEd Tanous } 2384e1f26343SJason M. Bills asyncResp->res.jsonValue = {{"Name", "PECI Command Response"}, 23851da66f75SEd Tanous {"PECIResponse", resp}}; 23861da66f75SEd Tanous }; 23871da66f75SEd Tanous // Call the SendRawPECI command with the provided data 23881da66f75SEd Tanous crow::connections::systemBus->async_method_call( 23895b61b5e8SJason M. Bills std::move(sendRawPECICallback), crashdumpObject, crashdumpPath, 23908724c297SKarthick Sundarrajan crashdumpRawPECIInterface, "SendRawPeci", peciCommands); 23911da66f75SEd Tanous } 23921da66f75SEd Tanous }; 23931da66f75SEd Tanous 2394cb92c03bSAndrew Geissler /** 2395cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 2396cb92c03bSAndrew Geissler */ 2397cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node 2398cb92c03bSAndrew Geissler { 2399cb92c03bSAndrew Geissler public: 2400cb92c03bSAndrew Geissler DBusLogServiceActionsClear(CrowApp &app) : 2401cb92c03bSAndrew Geissler Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 24027af91514SGunnar Mills "LogService.ClearLog/") 2403cb92c03bSAndrew Geissler { 2404cb92c03bSAndrew Geissler entityPrivileges = { 2405cb92c03bSAndrew Geissler {boost::beast::http::verb::get, {{"Login"}}}, 2406cb92c03bSAndrew Geissler {boost::beast::http::verb::head, {{"Login"}}}, 2407cb92c03bSAndrew Geissler {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2408cb92c03bSAndrew Geissler {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2409cb92c03bSAndrew Geissler {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2410cb92c03bSAndrew Geissler {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2411cb92c03bSAndrew Geissler } 2412cb92c03bSAndrew Geissler 2413cb92c03bSAndrew Geissler private: 2414cb92c03bSAndrew Geissler /** 2415cb92c03bSAndrew Geissler * Function handles POST method request. 2416cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 2417cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 2418cb92c03bSAndrew Geissler */ 2419cb92c03bSAndrew Geissler void doPost(crow::Response &res, const crow::Request &req, 2420cb92c03bSAndrew Geissler const std::vector<std::string> ¶ms) override 2421cb92c03bSAndrew Geissler { 2422cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 2423cb92c03bSAndrew Geissler 2424cb92c03bSAndrew Geissler auto asyncResp = std::make_shared<AsyncResp>(res); 2425cb92c03bSAndrew Geissler // Process response from Logging service. 2426cb92c03bSAndrew Geissler auto resp_handler = [asyncResp](const boost::system::error_code ec) { 2427cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 2428cb92c03bSAndrew Geissler if (ec) 2429cb92c03bSAndrew Geissler { 2430cb92c03bSAndrew Geissler // TODO Handle for specific error code 2431cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 2432cb92c03bSAndrew Geissler asyncResp->res.result( 2433cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 2434cb92c03bSAndrew Geissler return; 2435cb92c03bSAndrew Geissler } 2436cb92c03bSAndrew Geissler 2437cb92c03bSAndrew Geissler asyncResp->res.result(boost::beast::http::status::no_content); 2438cb92c03bSAndrew Geissler }; 2439cb92c03bSAndrew Geissler 2440cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 2441cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 2442cb92c03bSAndrew Geissler resp_handler, "xyz.openbmc_project.Logging", 2443cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 2444cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 2445cb92c03bSAndrew Geissler } 2446cb92c03bSAndrew Geissler }; 2447a3316fc6SZhikuiRen 2448a3316fc6SZhikuiRen /**************************************************** 2449a3316fc6SZhikuiRen * Redfish PostCode interfaces 2450a3316fc6SZhikuiRen * using DBUS interface: getPostCodesTS 2451a3316fc6SZhikuiRen ******************************************************/ 2452a3316fc6SZhikuiRen class PostCodesLogService : public Node 2453a3316fc6SZhikuiRen { 2454a3316fc6SZhikuiRen public: 2455a3316fc6SZhikuiRen PostCodesLogService(CrowApp &app) : 2456a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/") 2457a3316fc6SZhikuiRen { 2458a3316fc6SZhikuiRen entityPrivileges = { 2459a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2460a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2461a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2462a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2463a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2464a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2465a3316fc6SZhikuiRen } 2466a3316fc6SZhikuiRen 2467a3316fc6SZhikuiRen private: 2468a3316fc6SZhikuiRen void doGet(crow::Response &res, const crow::Request &req, 2469a3316fc6SZhikuiRen const std::vector<std::string> ¶ms) override 2470a3316fc6SZhikuiRen { 2471a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2472a3316fc6SZhikuiRen 2473a3316fc6SZhikuiRen asyncResp->res.jsonValue = { 2474a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"}, 2475a3316fc6SZhikuiRen {"@odata.type", "#LogService.v1_1_0.LogService"}, 2476a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"}, 2477a3316fc6SZhikuiRen {"Name", "POST Code Log Service"}, 2478a3316fc6SZhikuiRen {"Description", "POST Code Log Service"}, 2479a3316fc6SZhikuiRen {"Id", "BIOS POST Code Log"}, 2480a3316fc6SZhikuiRen {"OverWritePolicy", "WrapsWhenFull"}, 2481a3316fc6SZhikuiRen {"Entries", 2482a3316fc6SZhikuiRen {{"@odata.id", 2483a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}}; 2484a3316fc6SZhikuiRen asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 2485a3316fc6SZhikuiRen {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/" 2486a3316fc6SZhikuiRen "Actions/LogService.ClearLog"}}; 2487a3316fc6SZhikuiRen } 2488a3316fc6SZhikuiRen }; 2489a3316fc6SZhikuiRen 2490a3316fc6SZhikuiRen class PostCodesClear : public Node 2491a3316fc6SZhikuiRen { 2492a3316fc6SZhikuiRen public: 2493a3316fc6SZhikuiRen PostCodesClear(CrowApp &app) : 2494a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/" 2495a3316fc6SZhikuiRen "LogService.ClearLog/") 2496a3316fc6SZhikuiRen { 2497a3316fc6SZhikuiRen entityPrivileges = { 2498a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2499a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 25003946028dSAppaRao Puli {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 25013946028dSAppaRao Puli {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 25023946028dSAppaRao Puli {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 25033946028dSAppaRao Puli {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 2504a3316fc6SZhikuiRen } 2505a3316fc6SZhikuiRen 2506a3316fc6SZhikuiRen private: 2507a3316fc6SZhikuiRen void doPost(crow::Response &res, const crow::Request &req, 2508a3316fc6SZhikuiRen const std::vector<std::string> ¶ms) override 2509a3316fc6SZhikuiRen { 2510a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Do delete all postcodes entries."; 2511a3316fc6SZhikuiRen 2512a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2513a3316fc6SZhikuiRen // Make call to post-code service to request clear all 2514a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2515a3316fc6SZhikuiRen [asyncResp](const boost::system::error_code ec) { 2516a3316fc6SZhikuiRen if (ec) 2517a3316fc6SZhikuiRen { 2518a3316fc6SZhikuiRen // TODO Handle for specific error code 2519a3316fc6SZhikuiRen BMCWEB_LOG_ERROR 2520a3316fc6SZhikuiRen << "doClearPostCodes resp_handler got error " << ec; 2521a3316fc6SZhikuiRen asyncResp->res.result( 2522a3316fc6SZhikuiRen boost::beast::http::status::internal_server_error); 2523a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 2524a3316fc6SZhikuiRen return; 2525a3316fc6SZhikuiRen } 2526a3316fc6SZhikuiRen }, 2527a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2528a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2529a3316fc6SZhikuiRen "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 2530a3316fc6SZhikuiRen } 2531a3316fc6SZhikuiRen }; 2532a3316fc6SZhikuiRen 2533a3316fc6SZhikuiRen static void fillPostCodeEntry( 2534a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> aResp, 2535a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t> &postcode, 2536a3316fc6SZhikuiRen const uint16_t bootIndex, const uint64_t codeIndex = 0, 2537a3316fc6SZhikuiRen const uint64_t skip = 0, const uint64_t top = 0) 2538a3316fc6SZhikuiRen { 2539a3316fc6SZhikuiRen // Get the Message from the MessageRegistry 2540a3316fc6SZhikuiRen const message_registries::Message *message = 2541a3316fc6SZhikuiRen message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode"); 2542a3316fc6SZhikuiRen std::string severity; 2543a3316fc6SZhikuiRen if (message != nullptr) 2544a3316fc6SZhikuiRen { 2545a3316fc6SZhikuiRen severity = message->severity; 2546a3316fc6SZhikuiRen } 2547a3316fc6SZhikuiRen 2548a3316fc6SZhikuiRen uint64_t currentCodeIndex = 0; 2549a3316fc6SZhikuiRen nlohmann::json &logEntryArray = aResp->res.jsonValue["Members"]; 2550a3316fc6SZhikuiRen 2551a3316fc6SZhikuiRen uint64_t firstCodeTimeUs = 0; 2552a3316fc6SZhikuiRen for (const std::pair<uint64_t, uint64_t> &code : postcode) 2553a3316fc6SZhikuiRen { 2554a3316fc6SZhikuiRen currentCodeIndex++; 2555a3316fc6SZhikuiRen std::string postcodeEntryID = 2556a3316fc6SZhikuiRen "B" + std::to_string(bootIndex) + "-" + 2557a3316fc6SZhikuiRen std::to_string(currentCodeIndex); // 1 based index in EntryID string 2558a3316fc6SZhikuiRen 2559a3316fc6SZhikuiRen uint64_t usecSinceEpoch = code.first; 2560a3316fc6SZhikuiRen uint64_t usTimeOffset = 0; 2561a3316fc6SZhikuiRen 2562a3316fc6SZhikuiRen if (1 == currentCodeIndex) 2563a3316fc6SZhikuiRen { // already incremented 2564a3316fc6SZhikuiRen firstCodeTimeUs = code.first; 2565a3316fc6SZhikuiRen } 2566a3316fc6SZhikuiRen else 2567a3316fc6SZhikuiRen { 2568a3316fc6SZhikuiRen usTimeOffset = code.first - firstCodeTimeUs; 2569a3316fc6SZhikuiRen } 2570a3316fc6SZhikuiRen 2571a3316fc6SZhikuiRen // skip if no specific codeIndex is specified and currentCodeIndex does 2572a3316fc6SZhikuiRen // not fall between top and skip 2573a3316fc6SZhikuiRen if ((codeIndex == 0) && 2574a3316fc6SZhikuiRen (currentCodeIndex <= skip || currentCodeIndex > top)) 2575a3316fc6SZhikuiRen { 2576a3316fc6SZhikuiRen continue; 2577a3316fc6SZhikuiRen } 2578a3316fc6SZhikuiRen 2579a3316fc6SZhikuiRen // skip if a sepcific codeIndex is specified and does not match the 2580a3316fc6SZhikuiRen // currentIndex 2581a3316fc6SZhikuiRen if ((codeIndex > 0) && (currentCodeIndex != codeIndex)) 2582a3316fc6SZhikuiRen { 2583a3316fc6SZhikuiRen // This is done for simplicity. 1st entry is needed to calculate 2584a3316fc6SZhikuiRen // time offset. To improve efficiency, one can get to the entry 2585a3316fc6SZhikuiRen // directly (possibly with flatmap's nth method) 2586a3316fc6SZhikuiRen continue; 2587a3316fc6SZhikuiRen } 2588a3316fc6SZhikuiRen 2589a3316fc6SZhikuiRen // currentCodeIndex is within top and skip or equal to specified code 2590a3316fc6SZhikuiRen // index 2591a3316fc6SZhikuiRen 2592a3316fc6SZhikuiRen // Get the Created time from the timestamp 2593a3316fc6SZhikuiRen std::string entryTimeStr; 2594a3316fc6SZhikuiRen if (!getTimestampStr(usecSinceEpoch, entryTimeStr)) 2595a3316fc6SZhikuiRen { 2596a3316fc6SZhikuiRen continue; 2597a3316fc6SZhikuiRen } 2598a3316fc6SZhikuiRen 2599a3316fc6SZhikuiRen // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex) 2600a3316fc6SZhikuiRen std::ostringstream hexCode; 2601a3316fc6SZhikuiRen hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex 2602a3316fc6SZhikuiRen << code.second; 2603a3316fc6SZhikuiRen std::ostringstream timeOffsetStr; 2604a3316fc6SZhikuiRen // Set Fixed -Point Notation 2605a3316fc6SZhikuiRen timeOffsetStr << std::fixed; 2606a3316fc6SZhikuiRen // Set precision to 4 digits 2607a3316fc6SZhikuiRen timeOffsetStr << std::setprecision(4); 2608a3316fc6SZhikuiRen // Add double to stream 2609a3316fc6SZhikuiRen timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000; 2610a3316fc6SZhikuiRen std::vector<std::string> messageArgs = { 2611a3316fc6SZhikuiRen std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()}; 2612a3316fc6SZhikuiRen 2613a3316fc6SZhikuiRen // Get MessageArgs template from message registry 2614a3316fc6SZhikuiRen std::string msg; 2615a3316fc6SZhikuiRen if (message != nullptr) 2616a3316fc6SZhikuiRen { 2617a3316fc6SZhikuiRen msg = message->message; 2618a3316fc6SZhikuiRen 2619a3316fc6SZhikuiRen // fill in this post code value 2620a3316fc6SZhikuiRen int i = 0; 2621a3316fc6SZhikuiRen for (const std::string &messageArg : messageArgs) 2622a3316fc6SZhikuiRen { 2623a3316fc6SZhikuiRen std::string argStr = "%" + std::to_string(++i); 2624a3316fc6SZhikuiRen size_t argPos = msg.find(argStr); 2625a3316fc6SZhikuiRen if (argPos != std::string::npos) 2626a3316fc6SZhikuiRen { 2627a3316fc6SZhikuiRen msg.replace(argPos, argStr.length(), messageArg); 2628a3316fc6SZhikuiRen } 2629a3316fc6SZhikuiRen } 2630a3316fc6SZhikuiRen } 2631a3316fc6SZhikuiRen 2632a3316fc6SZhikuiRen // add to AsyncResp 2633a3316fc6SZhikuiRen logEntryArray.push_back({}); 2634a3316fc6SZhikuiRen nlohmann::json &bmcLogEntry = logEntryArray.back(); 2635a3316fc6SZhikuiRen bmcLogEntry = { 2636a3316fc6SZhikuiRen {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 2637a3316fc6SZhikuiRen {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 2638a3316fc6SZhikuiRen {"@odata.id", "/redfish/v1/Systems/system/LogServices/" 2639a3316fc6SZhikuiRen "PostCodes/Entries/" + 2640a3316fc6SZhikuiRen postcodeEntryID}, 2641a3316fc6SZhikuiRen {"Name", "POST Code Log Entry"}, 2642a3316fc6SZhikuiRen {"Id", postcodeEntryID}, 2643a3316fc6SZhikuiRen {"Message", std::move(msg)}, 2644a3316fc6SZhikuiRen {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"}, 2645a3316fc6SZhikuiRen {"MessageArgs", std::move(messageArgs)}, 2646a3316fc6SZhikuiRen {"EntryType", "Event"}, 2647a3316fc6SZhikuiRen {"Severity", std::move(severity)}, 2648a3316fc6SZhikuiRen {"Created", std::move(entryTimeStr)}}; 2649a3316fc6SZhikuiRen } 2650a3316fc6SZhikuiRen } 2651a3316fc6SZhikuiRen 2652a3316fc6SZhikuiRen static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp, 2653a3316fc6SZhikuiRen const uint16_t bootIndex, 2654a3316fc6SZhikuiRen const uint64_t codeIndex) 2655a3316fc6SZhikuiRen { 2656a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2657a3316fc6SZhikuiRen [aResp, bootIndex, codeIndex]( 2658a3316fc6SZhikuiRen const boost::system::error_code ec, 2659a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t> &postcode) { 2660a3316fc6SZhikuiRen if (ec) 2661a3316fc6SZhikuiRen { 2662a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 2663a3316fc6SZhikuiRen messages::internalError(aResp->res); 2664a3316fc6SZhikuiRen return; 2665a3316fc6SZhikuiRen } 2666a3316fc6SZhikuiRen 2667a3316fc6SZhikuiRen // skip the empty postcode boots 2668a3316fc6SZhikuiRen if (postcode.empty()) 2669a3316fc6SZhikuiRen { 2670a3316fc6SZhikuiRen return; 2671a3316fc6SZhikuiRen } 2672a3316fc6SZhikuiRen 2673a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex); 2674a3316fc6SZhikuiRen 2675a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = 2676a3316fc6SZhikuiRen aResp->res.jsonValue["Members"].size(); 2677a3316fc6SZhikuiRen }, 2678a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2679a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2680a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 2681a3316fc6SZhikuiRen bootIndex); 2682a3316fc6SZhikuiRen } 2683a3316fc6SZhikuiRen 2684a3316fc6SZhikuiRen static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp, 2685a3316fc6SZhikuiRen const uint16_t bootIndex, 2686a3316fc6SZhikuiRen const uint16_t bootCount, 2687a3316fc6SZhikuiRen const uint64_t entryCount, const uint64_t skip, 2688a3316fc6SZhikuiRen const uint64_t top) 2689a3316fc6SZhikuiRen { 2690a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2691a3316fc6SZhikuiRen [aResp, bootIndex, bootCount, entryCount, skip, 2692a3316fc6SZhikuiRen top](const boost::system::error_code ec, 2693a3316fc6SZhikuiRen const boost::container::flat_map<uint64_t, uint64_t> &postcode) { 2694a3316fc6SZhikuiRen if (ec) 2695a3316fc6SZhikuiRen { 2696a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error"; 2697a3316fc6SZhikuiRen messages::internalError(aResp->res); 2698a3316fc6SZhikuiRen return; 2699a3316fc6SZhikuiRen } 2700a3316fc6SZhikuiRen 2701a3316fc6SZhikuiRen uint64_t endCount = entryCount; 2702a3316fc6SZhikuiRen if (!postcode.empty()) 2703a3316fc6SZhikuiRen { 2704a3316fc6SZhikuiRen endCount = entryCount + postcode.size(); 2705a3316fc6SZhikuiRen 2706a3316fc6SZhikuiRen if ((skip < endCount) && ((top + skip) > entryCount)) 2707a3316fc6SZhikuiRen { 2708a3316fc6SZhikuiRen uint64_t thisBootSkip = 2709a3316fc6SZhikuiRen std::max(skip, entryCount) - entryCount; 2710a3316fc6SZhikuiRen uint64_t thisBootTop = 2711a3316fc6SZhikuiRen std::min(top + skip, endCount) - entryCount; 2712a3316fc6SZhikuiRen 2713a3316fc6SZhikuiRen fillPostCodeEntry(aResp, postcode, bootIndex, 0, 2714a3316fc6SZhikuiRen thisBootSkip, thisBootTop); 2715a3316fc6SZhikuiRen } 2716a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.count"] = endCount; 2717a3316fc6SZhikuiRen } 2718a3316fc6SZhikuiRen 2719a3316fc6SZhikuiRen // continue to previous bootIndex 2720a3316fc6SZhikuiRen if (bootIndex < bootCount) 2721a3316fc6SZhikuiRen { 2722a3316fc6SZhikuiRen getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1), 2723a3316fc6SZhikuiRen bootCount, endCount, skip, top); 2724a3316fc6SZhikuiRen } 2725a3316fc6SZhikuiRen else 2726a3316fc6SZhikuiRen { 2727a3316fc6SZhikuiRen aResp->res.jsonValue["Members@odata.nextLink"] = 2728a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 2729a3316fc6SZhikuiRen "Entries?$skip=" + 2730a3316fc6SZhikuiRen std::to_string(skip + top); 2731a3316fc6SZhikuiRen } 2732a3316fc6SZhikuiRen }, 2733a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2734a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2735a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp", 2736a3316fc6SZhikuiRen bootIndex); 2737a3316fc6SZhikuiRen } 2738a3316fc6SZhikuiRen 2739a3316fc6SZhikuiRen static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp, 2740a3316fc6SZhikuiRen const uint64_t skip, const uint64_t top) 2741a3316fc6SZhikuiRen { 2742a3316fc6SZhikuiRen uint64_t entryCount = 0; 2743a3316fc6SZhikuiRen crow::connections::systemBus->async_method_call( 2744a3316fc6SZhikuiRen [aResp, entryCount, skip, 2745a3316fc6SZhikuiRen top](const boost::system::error_code ec, 2746a3316fc6SZhikuiRen const std::variant<uint16_t> &bootCount) { 2747a3316fc6SZhikuiRen if (ec) 2748a3316fc6SZhikuiRen { 2749a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 2750a3316fc6SZhikuiRen messages::internalError(aResp->res); 2751a3316fc6SZhikuiRen return; 2752a3316fc6SZhikuiRen } 2753a3316fc6SZhikuiRen auto pVal = std::get_if<uint16_t>(&bootCount); 2754a3316fc6SZhikuiRen if (pVal) 2755a3316fc6SZhikuiRen { 2756a3316fc6SZhikuiRen getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top); 2757a3316fc6SZhikuiRen } 2758a3316fc6SZhikuiRen else 2759a3316fc6SZhikuiRen { 2760a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Post code boot index failed."; 2761a3316fc6SZhikuiRen } 2762a3316fc6SZhikuiRen }, 2763a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", 2764a3316fc6SZhikuiRen "/xyz/openbmc_project/State/Boot/PostCode", 2765a3316fc6SZhikuiRen "org.freedesktop.DBus.Properties", "Get", 2766a3316fc6SZhikuiRen "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount"); 2767a3316fc6SZhikuiRen } 2768a3316fc6SZhikuiRen 2769a3316fc6SZhikuiRen class PostCodesEntryCollection : public Node 2770a3316fc6SZhikuiRen { 2771a3316fc6SZhikuiRen public: 2772a3316fc6SZhikuiRen template <typename CrowApp> 2773a3316fc6SZhikuiRen PostCodesEntryCollection(CrowApp &app) : 2774a3316fc6SZhikuiRen Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/") 2775a3316fc6SZhikuiRen { 2776a3316fc6SZhikuiRen entityPrivileges = { 2777a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2778a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2779a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2780a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2781a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2782a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2783a3316fc6SZhikuiRen } 2784a3316fc6SZhikuiRen 2785a3316fc6SZhikuiRen private: 2786a3316fc6SZhikuiRen void doGet(crow::Response &res, const crow::Request &req, 2787a3316fc6SZhikuiRen const std::vector<std::string> ¶ms) override 2788a3316fc6SZhikuiRen { 2789a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2790a3316fc6SZhikuiRen 2791a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = 2792a3316fc6SZhikuiRen "#LogEntryCollection.LogEntryCollection"; 2793a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 2794a3316fc6SZhikuiRen "/redfish/v1/" 2795a3316fc6SZhikuiRen "$metadata#LogEntryCollection.LogEntryCollection"; 2796a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 2797a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"; 2798a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 2799a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 2800a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 2801a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 2802a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 2803a3316fc6SZhikuiRen 2804a3316fc6SZhikuiRen uint64_t skip = 0; 2805a3316fc6SZhikuiRen uint64_t top = maxEntriesPerPage; // Show max entries by default 2806a3316fc6SZhikuiRen if (!getSkipParam(asyncResp->res, req, skip)) 2807a3316fc6SZhikuiRen { 2808a3316fc6SZhikuiRen return; 2809a3316fc6SZhikuiRen } 2810a3316fc6SZhikuiRen if (!getTopParam(asyncResp->res, req, top)) 2811a3316fc6SZhikuiRen { 2812a3316fc6SZhikuiRen return; 2813a3316fc6SZhikuiRen } 2814a3316fc6SZhikuiRen getCurrentBootNumber(asyncResp, skip, top); 2815a3316fc6SZhikuiRen } 2816a3316fc6SZhikuiRen }; 2817a3316fc6SZhikuiRen 2818a3316fc6SZhikuiRen class PostCodesEntry : public Node 2819a3316fc6SZhikuiRen { 2820a3316fc6SZhikuiRen public: 2821a3316fc6SZhikuiRen PostCodesEntry(CrowApp &app) : 2822a3316fc6SZhikuiRen Node(app, 2823a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/", 2824a3316fc6SZhikuiRen std::string()) 2825a3316fc6SZhikuiRen { 2826a3316fc6SZhikuiRen entityPrivileges = { 2827a3316fc6SZhikuiRen {boost::beast::http::verb::get, {{"Login"}}}, 2828a3316fc6SZhikuiRen {boost::beast::http::verb::head, {{"Login"}}}, 2829a3316fc6SZhikuiRen {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 2830a3316fc6SZhikuiRen {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 2831a3316fc6SZhikuiRen {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 2832a3316fc6SZhikuiRen {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 2833a3316fc6SZhikuiRen } 2834a3316fc6SZhikuiRen 2835a3316fc6SZhikuiRen private: 2836a3316fc6SZhikuiRen void doGet(crow::Response &res, const crow::Request &req, 2837a3316fc6SZhikuiRen const std::vector<std::string> ¶ms) override 2838a3316fc6SZhikuiRen { 2839a3316fc6SZhikuiRen std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 2840a3316fc6SZhikuiRen if (params.size() != 1) 2841a3316fc6SZhikuiRen { 2842a3316fc6SZhikuiRen messages::internalError(asyncResp->res); 2843a3316fc6SZhikuiRen return; 2844a3316fc6SZhikuiRen } 2845a3316fc6SZhikuiRen 2846a3316fc6SZhikuiRen const std::string &targetID = params[0]; 2847a3316fc6SZhikuiRen 2848a3316fc6SZhikuiRen size_t bootPos = targetID.find('B'); 2849a3316fc6SZhikuiRen if (bootPos == std::string::npos) 2850a3316fc6SZhikuiRen { 2851a3316fc6SZhikuiRen // Requested ID was not found 2852a3316fc6SZhikuiRen messages::resourceMissingAtURI(asyncResp->res, targetID); 2853a3316fc6SZhikuiRen return; 2854a3316fc6SZhikuiRen } 2855a3316fc6SZhikuiRen std::string_view bootIndexStr(targetID); 2856a3316fc6SZhikuiRen bootIndexStr.remove_prefix(bootPos + 1); 2857a3316fc6SZhikuiRen uint16_t bootIndex = 0; 2858a3316fc6SZhikuiRen uint64_t codeIndex = 0; 2859a3316fc6SZhikuiRen size_t dashPos = bootIndexStr.find('-'); 2860a3316fc6SZhikuiRen 2861a3316fc6SZhikuiRen if (dashPos == std::string::npos) 2862a3316fc6SZhikuiRen { 2863a3316fc6SZhikuiRen return; 2864a3316fc6SZhikuiRen } 2865a3316fc6SZhikuiRen std::string_view codeIndexStr(bootIndexStr); 2866a3316fc6SZhikuiRen bootIndexStr.remove_suffix(dashPos); 2867a3316fc6SZhikuiRen codeIndexStr.remove_prefix(dashPos + 1); 2868a3316fc6SZhikuiRen 2869a3316fc6SZhikuiRen bootIndex = static_cast<uint16_t>( 2870a3316fc6SZhikuiRen strtoul(std::string(bootIndexStr).c_str(), NULL, 0)); 2871a3316fc6SZhikuiRen codeIndex = strtoul(std::string(codeIndexStr).c_str(), NULL, 0); 2872a3316fc6SZhikuiRen if (bootIndex == 0 || codeIndex == 0) 2873a3316fc6SZhikuiRen { 2874a3316fc6SZhikuiRen BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string " 2875a3316fc6SZhikuiRen << params[0]; 2876a3316fc6SZhikuiRen } 2877a3316fc6SZhikuiRen 2878a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry"; 2879a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.context"] = 2880a3316fc6SZhikuiRen "/redfish/v1/$metadata#LogEntry.LogEntry"; 2881a3316fc6SZhikuiRen asyncResp->res.jsonValue["@odata.id"] = 2882a3316fc6SZhikuiRen "/redfish/v1/Systems/system/LogServices/PostCodes/" 2883a3316fc6SZhikuiRen "Entries"; 2884a3316fc6SZhikuiRen asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries"; 2885a3316fc6SZhikuiRen asyncResp->res.jsonValue["Description"] = 2886a3316fc6SZhikuiRen "Collection of POST Code Log Entries"; 2887a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); 2888a3316fc6SZhikuiRen asyncResp->res.jsonValue["Members@odata.count"] = 0; 2889a3316fc6SZhikuiRen 2890a3316fc6SZhikuiRen getPostCodeForEntry(asyncResp, bootIndex, codeIndex); 2891a3316fc6SZhikuiRen } 2892a3316fc6SZhikuiRen }; 2893a3316fc6SZhikuiRen 28941da66f75SEd Tanous } // namespace redfish 2895