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" 221da66f75SEd Tanous 23e1f26343SJason M. Bills #include <systemd/sd-journal.h> 24e1f26343SJason M. Bills 254851d45dSJason M. Bills #include <boost/algorithm/string/split.hpp> 264851d45dSJason M. Bills #include <boost/beast/core/span.hpp> 271da66f75SEd Tanous #include <boost/container/flat_map.hpp> 28cb92c03bSAndrew Geissler #include <error_messages.hpp> 294418c7f0SJames Feist #include <filesystem> 30cd225da8SJason M. Bills #include <string_view> 31abf2add6SEd Tanous #include <variant> 321da66f75SEd Tanous 331da66f75SEd Tanous namespace redfish 341da66f75SEd Tanous { 351da66f75SEd Tanous 36424c4176SJason M. Bills constexpr char const *CrashdumpObject = "com.intel.crashdump"; 37424c4176SJason M. Bills constexpr char const *CrashdumpPath = "/com/intel/crashdump"; 38424c4176SJason M. Bills constexpr char const *CrashdumpOnDemandPath = "/com/intel/crashdump/OnDemand"; 39424c4176SJason M. Bills constexpr char const *CrashdumpInterface = "com.intel.crashdump"; 40424c4176SJason M. Bills constexpr char const *CrashdumpOnDemandInterface = 41424c4176SJason M. Bills "com.intel.crashdump.OnDemand"; 42424c4176SJason M. Bills constexpr char const *CrashdumpRawPECIInterface = 43424c4176SJason M. Bills "com.intel.crashdump.SendRawPeci"; 441da66f75SEd Tanous 454851d45dSJason M. Bills namespace message_registries 464851d45dSJason M. Bills { 474851d45dSJason M. Bills static const Message *getMessageFromRegistry( 484851d45dSJason M. Bills const std::string &messageKey, 494851d45dSJason M. Bills const boost::beast::span<const MessageEntry> registry) 504851d45dSJason M. Bills { 514851d45dSJason M. Bills boost::beast::span<const MessageEntry>::const_iterator messageIt = 524851d45dSJason M. Bills std::find_if(registry.cbegin(), registry.cend(), 534851d45dSJason M. Bills [&messageKey](const MessageEntry &messageEntry) { 544851d45dSJason M. Bills return !std::strcmp(messageEntry.first, 554851d45dSJason M. Bills messageKey.c_str()); 564851d45dSJason M. Bills }); 574851d45dSJason M. Bills if (messageIt != registry.cend()) 584851d45dSJason M. Bills { 594851d45dSJason M. Bills return &messageIt->second; 604851d45dSJason M. Bills } 614851d45dSJason M. Bills 624851d45dSJason M. Bills return nullptr; 634851d45dSJason M. Bills } 644851d45dSJason M. Bills 654851d45dSJason M. Bills static const Message *getMessage(const std::string_view &messageID) 664851d45dSJason M. Bills { 674851d45dSJason M. Bills // Redfish MessageIds are in the form 684851d45dSJason M. Bills // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find 694851d45dSJason M. Bills // the right Message 704851d45dSJason M. Bills std::vector<std::string> fields; 714851d45dSJason M. Bills fields.reserve(4); 724851d45dSJason M. Bills boost::split(fields, messageID, boost::is_any_of(".")); 734851d45dSJason M. Bills std::string ®istryName = fields[0]; 744851d45dSJason M. Bills std::string &messageKey = fields[3]; 754851d45dSJason M. Bills 764851d45dSJason M. Bills // Find the right registry and check it for the MessageKey 774851d45dSJason M. Bills if (std::string(base::header.registryPrefix) == registryName) 784851d45dSJason M. Bills { 794851d45dSJason M. Bills return getMessageFromRegistry( 804851d45dSJason M. Bills messageKey, boost::beast::span<const MessageEntry>(base::registry)); 814851d45dSJason M. Bills } 824851d45dSJason M. Bills if (std::string(openbmc::header.registryPrefix) == registryName) 834851d45dSJason M. Bills { 844851d45dSJason M. Bills return getMessageFromRegistry( 854851d45dSJason M. Bills messageKey, 864851d45dSJason M. Bills boost::beast::span<const MessageEntry>(openbmc::registry)); 874851d45dSJason M. Bills } 884851d45dSJason M. Bills return nullptr; 894851d45dSJason M. Bills } 904851d45dSJason M. Bills } // namespace message_registries 914851d45dSJason M. Bills 92f6150403SJames Feist namespace fs = std::filesystem; 931da66f75SEd Tanous 94cb92c03bSAndrew Geissler using GetManagedPropertyType = boost::container::flat_map< 95cb92c03bSAndrew Geissler std::string, 96cb92c03bSAndrew Geissler sdbusplus::message::variant<std::string, bool, uint8_t, int16_t, uint16_t, 97cb92c03bSAndrew Geissler int32_t, uint32_t, int64_t, uint64_t, double>>; 98cb92c03bSAndrew Geissler 99cb92c03bSAndrew Geissler using GetManagedObjectsType = boost::container::flat_map< 100cb92c03bSAndrew Geissler sdbusplus::message::object_path, 101cb92c03bSAndrew Geissler boost::container::flat_map<std::string, GetManagedPropertyType>>; 102cb92c03bSAndrew Geissler 103cb92c03bSAndrew Geissler inline std::string translateSeverityDbusToRedfish(const std::string &s) 104cb92c03bSAndrew Geissler { 105cb92c03bSAndrew Geissler if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert") 106cb92c03bSAndrew Geissler { 107cb92c03bSAndrew Geissler return "Critical"; 108cb92c03bSAndrew Geissler } 109cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") 110cb92c03bSAndrew Geissler { 111cb92c03bSAndrew Geissler return "Critical"; 112cb92c03bSAndrew Geissler } 113cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug") 114cb92c03bSAndrew Geissler { 115cb92c03bSAndrew Geissler return "OK"; 116cb92c03bSAndrew Geissler } 117cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") 118cb92c03bSAndrew Geissler { 119cb92c03bSAndrew Geissler return "Critical"; 120cb92c03bSAndrew Geissler } 121cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error") 122cb92c03bSAndrew Geissler { 123cb92c03bSAndrew Geissler return "Critical"; 124cb92c03bSAndrew Geissler } 125cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") 126cb92c03bSAndrew Geissler { 127cb92c03bSAndrew Geissler return "OK"; 128cb92c03bSAndrew Geissler } 129cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice") 130cb92c03bSAndrew Geissler { 131cb92c03bSAndrew Geissler return "OK"; 132cb92c03bSAndrew Geissler } 133cb92c03bSAndrew Geissler else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning") 134cb92c03bSAndrew Geissler { 135cb92c03bSAndrew Geissler return "Warning"; 136cb92c03bSAndrew Geissler } 137cb92c03bSAndrew Geissler return ""; 138cb92c03bSAndrew Geissler } 139cb92c03bSAndrew Geissler 14016428a1aSJason M. Bills static int getJournalMetadata(sd_journal *journal, 14139e77504SEd Tanous const std::string_view &field, 14239e77504SEd Tanous std::string_view &contents) 14316428a1aSJason M. Bills { 14416428a1aSJason M. Bills const char *data = nullptr; 14516428a1aSJason M. Bills size_t length = 0; 14616428a1aSJason M. Bills int ret = 0; 14716428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 148b01bf299SEd Tanous ret = sd_journal_get_data(journal, field.data(), (const void **)&data, 149b01bf299SEd Tanous &length); 15016428a1aSJason M. Bills if (ret < 0) 15116428a1aSJason M. Bills { 15216428a1aSJason M. Bills return ret; 15316428a1aSJason M. Bills } 15439e77504SEd Tanous contents = std::string_view(data, length); 15516428a1aSJason M. Bills // Only use the content after the "=" character. 15616428a1aSJason M. Bills contents.remove_prefix(std::min(contents.find("=") + 1, contents.size())); 15716428a1aSJason M. Bills return ret; 15816428a1aSJason M. Bills } 15916428a1aSJason M. Bills 16016428a1aSJason M. Bills static int getJournalMetadata(sd_journal *journal, 16139e77504SEd Tanous const std::string_view &field, const int &base, 16216428a1aSJason M. Bills int &contents) 16316428a1aSJason M. Bills { 16416428a1aSJason M. Bills int ret = 0; 16539e77504SEd Tanous std::string_view metadata; 16616428a1aSJason M. Bills // Get the metadata from the requested field of the journal entry 16716428a1aSJason M. Bills ret = getJournalMetadata(journal, field, metadata); 16816428a1aSJason M. Bills if (ret < 0) 16916428a1aSJason M. Bills { 17016428a1aSJason M. Bills return ret; 17116428a1aSJason M. Bills } 172b01bf299SEd Tanous contents = strtol(metadata.data(), nullptr, base); 17316428a1aSJason M. Bills return ret; 17416428a1aSJason M. Bills } 17516428a1aSJason M. Bills 17616428a1aSJason M. Bills static bool getEntryTimestamp(sd_journal *journal, std::string &entryTimestamp) 17716428a1aSJason M. Bills { 17816428a1aSJason M. Bills int ret = 0; 17916428a1aSJason M. Bills uint64_t timestamp = 0; 18016428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, ×tamp); 18116428a1aSJason M. Bills if (ret < 0) 18216428a1aSJason M. Bills { 18316428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 18416428a1aSJason M. Bills << strerror(-ret); 18516428a1aSJason M. Bills return false; 18616428a1aSJason M. Bills } 18716428a1aSJason M. Bills time_t t = 18816428a1aSJason M. Bills static_cast<time_t>(timestamp / 1000 / 1000); // Convert from us to s 18916428a1aSJason M. Bills struct tm *loctime = localtime(&t); 19016428a1aSJason M. Bills char entryTime[64] = {}; 19116428a1aSJason M. Bills if (NULL != loctime) 19216428a1aSJason M. Bills { 19316428a1aSJason M. Bills strftime(entryTime, sizeof(entryTime), "%FT%T%z", loctime); 19416428a1aSJason M. Bills } 19516428a1aSJason M. Bills // Insert the ':' into the timezone 19639e77504SEd Tanous std::string_view t1(entryTime); 19739e77504SEd Tanous std::string_view t2(entryTime); 19816428a1aSJason M. Bills if (t1.size() > 2 && t2.size() > 2) 19916428a1aSJason M. Bills { 20016428a1aSJason M. Bills t1.remove_suffix(2); 20116428a1aSJason M. Bills t2.remove_prefix(t2.size() - 2); 20216428a1aSJason M. Bills } 20339e77504SEd Tanous entryTimestamp = std::string(t1) + ":" + std::string(t2); 20416428a1aSJason M. Bills return true; 20516428a1aSJason M. Bills } 20616428a1aSJason M. Bills 20716428a1aSJason M. Bills static bool getSkipParam(crow::Response &res, const crow::Request &req, 20816428a1aSJason M. Bills long &skip) 20916428a1aSJason M. Bills { 21016428a1aSJason M. Bills char *skipParam = req.urlParams.get("$skip"); 21116428a1aSJason M. Bills if (skipParam != nullptr) 21216428a1aSJason M. Bills { 21316428a1aSJason M. Bills char *ptr = nullptr; 21416428a1aSJason M. Bills skip = std::strtol(skipParam, &ptr, 10); 21516428a1aSJason M. Bills if (*skipParam == '\0' || *ptr != '\0') 21616428a1aSJason M. Bills { 21716428a1aSJason M. Bills 21816428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(skipParam), 21916428a1aSJason M. Bills "$skip"); 22016428a1aSJason M. Bills return false; 22116428a1aSJason M. Bills } 22216428a1aSJason M. Bills if (skip < 0) 22316428a1aSJason M. Bills { 22416428a1aSJason M. Bills 22516428a1aSJason M. Bills messages::queryParameterOutOfRange(res, std::to_string(skip), 22616428a1aSJason M. Bills "$skip", "greater than 0"); 22716428a1aSJason M. Bills return false; 22816428a1aSJason M. Bills } 22916428a1aSJason M. Bills } 23016428a1aSJason M. Bills return true; 23116428a1aSJason M. Bills } 23216428a1aSJason M. Bills 23316428a1aSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 23416428a1aSJason M. Bills static bool getTopParam(crow::Response &res, const crow::Request &req, 23516428a1aSJason M. Bills long &top) 23616428a1aSJason M. Bills { 23716428a1aSJason M. Bills char *topParam = req.urlParams.get("$top"); 23816428a1aSJason M. Bills if (topParam != nullptr) 23916428a1aSJason M. Bills { 24016428a1aSJason M. Bills char *ptr = nullptr; 24116428a1aSJason M. Bills top = std::strtol(topParam, &ptr, 10); 24216428a1aSJason M. Bills if (*topParam == '\0' || *ptr != '\0') 24316428a1aSJason M. Bills { 24416428a1aSJason M. Bills messages::queryParameterValueTypeError(res, std::string(topParam), 24516428a1aSJason M. Bills "$top"); 24616428a1aSJason M. Bills return false; 24716428a1aSJason M. Bills } 24816428a1aSJason M. Bills if (top < 1 || top > maxEntriesPerPage) 24916428a1aSJason M. Bills { 25016428a1aSJason M. Bills 25116428a1aSJason M. Bills messages::queryParameterOutOfRange( 25216428a1aSJason M. Bills res, std::to_string(top), "$top", 25316428a1aSJason M. Bills "1-" + std::to_string(maxEntriesPerPage)); 25416428a1aSJason M. Bills return false; 25516428a1aSJason M. Bills } 25616428a1aSJason M. Bills } 25716428a1aSJason M. Bills return true; 25816428a1aSJason M. Bills } 25916428a1aSJason M. Bills 26016428a1aSJason M. Bills static bool getUniqueEntryID(sd_journal *journal, std::string &entryID) 26116428a1aSJason M. Bills { 26216428a1aSJason M. Bills int ret = 0; 26316428a1aSJason M. Bills static uint64_t prevTs = 0; 26416428a1aSJason M. Bills static int index = 0; 26516428a1aSJason M. Bills // Get the entry timestamp 26616428a1aSJason M. Bills uint64_t curTs = 0; 26716428a1aSJason M. Bills ret = sd_journal_get_realtime_usec(journal, &curTs); 26816428a1aSJason M. Bills if (ret < 0) 26916428a1aSJason M. Bills { 27016428a1aSJason M. Bills BMCWEB_LOG_ERROR << "Failed to read entry timestamp: " 27116428a1aSJason M. Bills << strerror(-ret); 27216428a1aSJason M. Bills return false; 27316428a1aSJason M. Bills } 27416428a1aSJason M. Bills // If the timestamp isn't unique, increment the index 27516428a1aSJason M. Bills if (curTs == prevTs) 27616428a1aSJason M. Bills { 27716428a1aSJason M. Bills index++; 27816428a1aSJason M. Bills } 27916428a1aSJason M. Bills else 28016428a1aSJason M. Bills { 28116428a1aSJason M. Bills // Otherwise, reset it 28216428a1aSJason M. Bills index = 0; 28316428a1aSJason M. Bills } 28416428a1aSJason M. Bills // Save the timestamp 28516428a1aSJason M. Bills prevTs = curTs; 28616428a1aSJason M. Bills 28716428a1aSJason M. Bills entryID = std::to_string(curTs); 28816428a1aSJason M. Bills if (index > 0) 28916428a1aSJason M. Bills { 29016428a1aSJason M. Bills entryID += "_" + std::to_string(index); 29116428a1aSJason M. Bills } 29216428a1aSJason M. Bills return true; 29316428a1aSJason M. Bills } 29416428a1aSJason M. Bills 29595820184SJason M. Bills static bool getUniqueEntryID(const std::string &logEntry, std::string &entryID) 29695820184SJason M. Bills { 29795820184SJason M. Bills static uint64_t prevTs = 0; 29895820184SJason M. Bills static int index = 0; 29995820184SJason M. Bills // Get the entry timestamp 30095820184SJason M. Bills uint64_t curTs = 0; 30195820184SJason M. Bills std::tm timeStruct = {}; 30295820184SJason M. Bills std::istringstream entryStream(logEntry); 30395820184SJason M. Bills if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S")) 30495820184SJason M. Bills { 30595820184SJason M. Bills curTs = std::mktime(&timeStruct); 30695820184SJason M. Bills } 30795820184SJason M. Bills // If the timestamp isn't unique, increment the index 30895820184SJason M. Bills if (curTs == prevTs) 30995820184SJason M. Bills { 31095820184SJason M. Bills index++; 31195820184SJason M. Bills } 31295820184SJason M. Bills else 31395820184SJason M. Bills { 31495820184SJason M. Bills // Otherwise, reset it 31595820184SJason M. Bills index = 0; 31695820184SJason M. Bills } 31795820184SJason M. Bills // Save the timestamp 31895820184SJason M. Bills prevTs = curTs; 31995820184SJason M. Bills 32095820184SJason M. Bills entryID = std::to_string(curTs); 32195820184SJason M. Bills if (index > 0) 32295820184SJason M. Bills { 32395820184SJason M. Bills entryID += "_" + std::to_string(index); 32495820184SJason M. Bills } 32595820184SJason M. Bills return true; 32695820184SJason M. Bills } 32795820184SJason M. Bills 32816428a1aSJason M. Bills static bool getTimestampFromID(crow::Response &res, const std::string &entryID, 32916428a1aSJason M. Bills uint64_t ×tamp, uint16_t &index) 33016428a1aSJason M. Bills { 33116428a1aSJason M. Bills if (entryID.empty()) 33216428a1aSJason M. Bills { 33316428a1aSJason M. Bills return false; 33416428a1aSJason M. Bills } 33516428a1aSJason M. Bills // Convert the unique ID back to a timestamp to find the entry 33639e77504SEd Tanous std::string_view tsStr(entryID); 33716428a1aSJason M. Bills 33816428a1aSJason M. Bills auto underscorePos = tsStr.find("_"); 33916428a1aSJason M. Bills if (underscorePos != tsStr.npos) 34016428a1aSJason M. Bills { 34116428a1aSJason M. Bills // Timestamp has an index 34216428a1aSJason M. Bills tsStr.remove_suffix(tsStr.size() - underscorePos); 34339e77504SEd Tanous std::string_view indexStr(entryID); 34416428a1aSJason M. Bills indexStr.remove_prefix(underscorePos + 1); 34516428a1aSJason M. Bills std::size_t pos; 34616428a1aSJason M. Bills try 34716428a1aSJason M. Bills { 34839e77504SEd Tanous index = std::stoul(std::string(indexStr), &pos); 34916428a1aSJason M. Bills } 350b01bf299SEd Tanous catch (std::invalid_argument) 35116428a1aSJason M. Bills { 35216428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35316428a1aSJason M. Bills return false; 35416428a1aSJason M. Bills } 355b01bf299SEd Tanous catch (std::out_of_range) 35616428a1aSJason M. Bills { 35716428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 35816428a1aSJason M. Bills return false; 35916428a1aSJason M. Bills } 36016428a1aSJason M. Bills if (pos != indexStr.size()) 36116428a1aSJason M. Bills { 36216428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 36316428a1aSJason M. Bills return false; 36416428a1aSJason M. Bills } 36516428a1aSJason M. Bills } 36616428a1aSJason M. Bills // Timestamp has no index 36716428a1aSJason M. Bills std::size_t pos; 36816428a1aSJason M. Bills try 36916428a1aSJason M. Bills { 37039e77504SEd Tanous timestamp = std::stoull(std::string(tsStr), &pos); 37116428a1aSJason M. Bills } 372b01bf299SEd Tanous catch (std::invalid_argument) 37316428a1aSJason M. Bills { 37416428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 37516428a1aSJason M. Bills return false; 37616428a1aSJason M. Bills } 377b01bf299SEd Tanous catch (std::out_of_range) 37816428a1aSJason M. Bills { 37916428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 38016428a1aSJason M. Bills return false; 38116428a1aSJason M. Bills } 38216428a1aSJason M. Bills if (pos != tsStr.size()) 38316428a1aSJason M. Bills { 38416428a1aSJason M. Bills messages::resourceMissingAtURI(res, entryID); 38516428a1aSJason M. Bills return false; 38616428a1aSJason M. Bills } 38716428a1aSJason M. Bills return true; 38816428a1aSJason M. Bills } 38916428a1aSJason M. Bills 39095820184SJason M. Bills static bool 39195820184SJason M. Bills getRedfishLogFiles(std::vector<std::filesystem::path> &redfishLogFiles) 39295820184SJason M. Bills { 39395820184SJason M. Bills static const std::filesystem::path redfishLogDir = "/var/log"; 39495820184SJason M. Bills static const std::string redfishLogFilename = "redfish"; 39595820184SJason M. Bills 39695820184SJason M. Bills // Loop through the directory looking for redfish log files 39795820184SJason M. Bills for (const std::filesystem::directory_entry &dirEnt : 39895820184SJason M. Bills std::filesystem::directory_iterator(redfishLogDir)) 39995820184SJason M. Bills { 40095820184SJason M. Bills // If we find a redfish log file, save the path 40195820184SJason M. Bills std::string filename = dirEnt.path().filename(); 40295820184SJason M. Bills if (boost::starts_with(filename, redfishLogFilename)) 40395820184SJason M. Bills { 40495820184SJason M. Bills redfishLogFiles.emplace_back(redfishLogDir / filename); 40595820184SJason M. Bills } 40695820184SJason M. Bills } 40795820184SJason M. Bills // As the log files rotate, they are appended with a ".#" that is higher for 40895820184SJason M. Bills // the older logs. Since we don't expect more than 10 log files, we 40995820184SJason M. Bills // can just sort the list to get them in order from newest to oldest 41095820184SJason M. Bills std::sort(redfishLogFiles.begin(), redfishLogFiles.end()); 41195820184SJason M. Bills 41295820184SJason M. Bills return !redfishLogFiles.empty(); 41395820184SJason M. Bills } 41495820184SJason M. Bills 415c4bf6374SJason M. Bills class SystemLogServiceCollection : public Node 4161da66f75SEd Tanous { 4171da66f75SEd Tanous public: 4181da66f75SEd Tanous template <typename CrowApp> 419c4bf6374SJason M. Bills SystemLogServiceCollection(CrowApp &app) : 420029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/") 421c4bf6374SJason M. Bills { 422c4bf6374SJason M. Bills entityPrivileges = { 423c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 424c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 425c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 426c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 427c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 428c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 429c4bf6374SJason M. Bills } 430c4bf6374SJason M. Bills 431c4bf6374SJason M. Bills private: 432c4bf6374SJason M. Bills /** 433c4bf6374SJason M. Bills * Functions triggers appropriate requests on DBus 434c4bf6374SJason M. Bills */ 435c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 436c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 437c4bf6374SJason M. Bills { 438c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 439c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 440c4bf6374SJason M. Bills // it has a duplicate entry for members 441c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 442c4bf6374SJason M. Bills "#LogServiceCollection.LogServiceCollection"; 443c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.context"] = 444c4bf6374SJason M. Bills "/redfish/v1/$metadata#LogServiceCollection.LogServiceCollection"; 445c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 446029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices"; 447c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Log Services Collection"; 448c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 449c4bf6374SJason M. Bills "Collection of LogServices for this Computer System"; 450c4bf6374SJason M. Bills nlohmann::json &logServiceArray = asyncResp->res.jsonValue["Members"]; 451c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 452029573d4SEd Tanous logServiceArray.push_back( 453029573d4SEd Tanous {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}}); 454d53dd41fSJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG 455d53dd41fSJason M. Bills logServiceArray.push_back( 456cb92c03bSAndrew Geissler {{"@odata.id", 457424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"}}); 458d53dd41fSJason M. Bills #endif 459c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 460c4bf6374SJason M. Bills logServiceArray.size(); 461c4bf6374SJason M. Bills } 462c4bf6374SJason M. Bills }; 463c4bf6374SJason M. Bills 464c4bf6374SJason M. Bills class EventLogService : public Node 465c4bf6374SJason M. Bills { 466c4bf6374SJason M. Bills public: 467c4bf6374SJason M. Bills template <typename CrowApp> 468c4bf6374SJason M. Bills EventLogService(CrowApp &app) : 469029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/") 470c4bf6374SJason M. Bills { 471c4bf6374SJason M. Bills entityPrivileges = { 472c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 473c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 474c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 475c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 476c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 477c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 478c4bf6374SJason M. Bills } 479c4bf6374SJason M. Bills 480c4bf6374SJason M. Bills private: 481c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 482c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 483c4bf6374SJason M. Bills { 484c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 485c4bf6374SJason M. Bills 486c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 487029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog"; 488c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 489c4bf6374SJason M. Bills "#LogService.v1_1_0.LogService"; 490c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.context"] = 491c4bf6374SJason M. Bills "/redfish/v1/$metadata#LogService.LogService"; 492c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Event Log Service"; 493c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "System Event Log Service"; 494c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "Event Log"; 495c4bf6374SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 496c4bf6374SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 497c4bf6374SJason M. Bills {"@odata.id", 498029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}}; 499e7d6c8b2SGunnar Mills asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = { 500e7d6c8b2SGunnar Mills 501e7d6c8b2SGunnar Mills {"target", "/redfish/v1/Systems/system/LogServices/EventLog/" 502e7d6c8b2SGunnar Mills "Actions/LogService.ClearLog"}}; 503489640c6SJason M. Bills } 504489640c6SJason M. Bills }; 505489640c6SJason M. Bills 506489640c6SJason M. Bills class EventLogClear : public Node 507489640c6SJason M. Bills { 508489640c6SJason M. Bills public: 509489640c6SJason M. Bills EventLogClear(CrowApp &app) : 510489640c6SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 511489640c6SJason M. Bills "LogService.ClearLog/") 512489640c6SJason M. Bills { 513489640c6SJason M. Bills entityPrivileges = { 514489640c6SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 515489640c6SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 516489640c6SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 517489640c6SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 518489640c6SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 519489640c6SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 520489640c6SJason M. Bills } 521489640c6SJason M. Bills 522489640c6SJason M. Bills private: 523489640c6SJason M. Bills void doPost(crow::Response &res, const crow::Request &req, 524489640c6SJason M. Bills const std::vector<std::string> ¶ms) override 525489640c6SJason M. Bills { 526489640c6SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 527489640c6SJason M. Bills 528489640c6SJason M. Bills // Clear the EventLog by deleting the log files 529489640c6SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 530489640c6SJason M. Bills if (getRedfishLogFiles(redfishLogFiles)) 531489640c6SJason M. Bills { 532489640c6SJason M. Bills for (const std::filesystem::path &file : redfishLogFiles) 533489640c6SJason M. Bills { 534489640c6SJason M. Bills std::error_code ec; 535489640c6SJason M. Bills std::filesystem::remove(file, ec); 536489640c6SJason M. Bills } 537489640c6SJason M. Bills } 538489640c6SJason M. Bills 539489640c6SJason M. Bills // Reload rsyslog so it knows to start new log files 540489640c6SJason M. Bills crow::connections::systemBus->async_method_call( 541489640c6SJason M. Bills [asyncResp](const boost::system::error_code ec) { 542489640c6SJason M. Bills if (ec) 543489640c6SJason M. Bills { 544489640c6SJason M. Bills BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec; 545489640c6SJason M. Bills messages::internalError(asyncResp->res); 546489640c6SJason M. Bills return; 547489640c6SJason M. Bills } 548489640c6SJason M. Bills 549489640c6SJason M. Bills messages::success(asyncResp->res); 550489640c6SJason M. Bills }, 551489640c6SJason M. Bills "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 552489640c6SJason M. Bills "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service", 553489640c6SJason M. Bills "replace"); 554c4bf6374SJason M. Bills } 555c4bf6374SJason M. Bills }; 556c4bf6374SJason M. Bills 55795820184SJason M. Bills static int fillEventLogEntryJson(const std::string &logEntryID, 55895820184SJason M. Bills const std::string logEntry, 55995820184SJason M. Bills nlohmann::json &logEntryJson) 560c4bf6374SJason M. Bills { 56195820184SJason M. Bills // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>" 562cd225da8SJason M. Bills // First get the Timestamp 563cd225da8SJason M. Bills size_t space = logEntry.find_first_of(" "); 564cd225da8SJason M. Bills if (space == std::string::npos) 56595820184SJason M. Bills { 56695820184SJason M. Bills return 1; 56795820184SJason M. Bills } 568cd225da8SJason M. Bills std::string timestamp = logEntry.substr(0, space); 569cd225da8SJason M. Bills // Then get the log contents 570cd225da8SJason M. Bills size_t entryStart = logEntry.find_first_not_of(" ", space); 571cd225da8SJason M. Bills if (entryStart == std::string::npos) 572cd225da8SJason M. Bills { 573cd225da8SJason M. Bills return 1; 574cd225da8SJason M. Bills } 575cd225da8SJason M. Bills std::string_view entry(logEntry); 576cd225da8SJason M. Bills entry.remove_prefix(entryStart); 577cd225da8SJason M. Bills // Use split to separate the entry into its fields 578cd225da8SJason M. Bills std::vector<std::string> logEntryFields; 579cd225da8SJason M. Bills boost::split(logEntryFields, entry, boost::is_any_of(","), 580cd225da8SJason M. Bills boost::token_compress_on); 581cd225da8SJason M. Bills // We need at least a MessageId to be valid 582cd225da8SJason M. Bills if (logEntryFields.size() < 1) 583cd225da8SJason M. Bills { 584cd225da8SJason M. Bills return 1; 585cd225da8SJason M. Bills } 586cd225da8SJason M. Bills std::string &messageID = logEntryFields[0]; 58795820184SJason M. Bills 5884851d45dSJason M. Bills // Get the Message from the MessageRegistry 5894851d45dSJason M. Bills const message_registries::Message *message = 5904851d45dSJason M. Bills message_registries::getMessage(messageID); 591c4bf6374SJason M. Bills 5924851d45dSJason M. Bills std::string msg; 5934851d45dSJason M. Bills std::string severity; 5944851d45dSJason M. Bills if (message != nullptr) 595c4bf6374SJason M. Bills { 5964851d45dSJason M. Bills msg = message->message; 5974851d45dSJason M. Bills severity = message->severity; 598c4bf6374SJason M. Bills } 599c4bf6374SJason M. Bills 60015a86ff6SJason M. Bills // Get the MessageArgs from the log if there are any 60115a86ff6SJason M. Bills boost::beast::span<std::string> messageArgs; 60215a86ff6SJason M. Bills if (logEntryFields.size() > 1) 60315a86ff6SJason M. Bills { 60415a86ff6SJason M. Bills std::string &messageArgsStart = logEntryFields[1]; 60515a86ff6SJason M. Bills // If the first string is empty, assume there are no MessageArgs 60615a86ff6SJason M. Bills std::size_t messageArgsSize = 0; 60715a86ff6SJason M. Bills if (!messageArgsStart.empty()) 60815a86ff6SJason M. Bills { 60915a86ff6SJason M. Bills messageArgsSize = logEntryFields.size() - 1; 61015a86ff6SJason M. Bills } 61115a86ff6SJason M. Bills 61215a86ff6SJason M. Bills messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize); 613c4bf6374SJason M. Bills 6144851d45dSJason M. Bills // Fill the MessageArgs into the Message 61595820184SJason M. Bills int i = 0; 61695820184SJason M. Bills for (const std::string &messageArg : messageArgs) 6174851d45dSJason M. Bills { 61895820184SJason M. Bills std::string argStr = "%" + std::to_string(++i); 6194851d45dSJason M. Bills size_t argPos = msg.find(argStr); 6204851d45dSJason M. Bills if (argPos != std::string::npos) 6214851d45dSJason M. Bills { 62295820184SJason M. Bills msg.replace(argPos, argStr.length(), messageArg); 6234851d45dSJason M. Bills } 6244851d45dSJason M. Bills } 62515a86ff6SJason M. Bills } 6264851d45dSJason M. Bills 62795820184SJason M. Bills // Get the Created time from the timestamp. The log timestamp is in RFC3339 62895820184SJason M. Bills // format which matches the Redfish format except for the fractional seconds 62995820184SJason M. Bills // between the '.' and the '+', so just remove them. 63095820184SJason M. Bills std::size_t dot = timestamp.find_first_of("."); 63195820184SJason M. Bills std::size_t plus = timestamp.find_first_of("+"); 63295820184SJason M. Bills if (dot != std::string::npos && plus != std::string::npos) 633c4bf6374SJason M. Bills { 63495820184SJason M. Bills timestamp.erase(dot, plus - dot); 635c4bf6374SJason M. Bills } 636c4bf6374SJason M. Bills 637c4bf6374SJason M. Bills // Fill in the log entry with the gathered data 63895820184SJason M. Bills logEntryJson = { 639cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 640c4bf6374SJason M. Bills {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 641029573d4SEd Tanous {"@odata.id", 64295820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/Entries/#" + 64395820184SJason M. Bills logEntryID}, 644c4bf6374SJason M. Bills {"Name", "System Event Log Entry"}, 64595820184SJason M. Bills {"Id", logEntryID}, 64695820184SJason M. Bills {"Message", std::move(msg)}, 64795820184SJason M. Bills {"MessageId", std::move(messageID)}, 648c4bf6374SJason M. Bills {"MessageArgs", std::move(messageArgs)}, 649c4bf6374SJason M. Bills {"EntryType", "Event"}, 65095820184SJason M. Bills {"Severity", std::move(severity)}, 65195820184SJason M. Bills {"Created", std::move(timestamp)}}; 652c4bf6374SJason M. Bills return 0; 653c4bf6374SJason M. Bills } 654c4bf6374SJason M. Bills 65527062605SAnthony Wilson class JournalEventLogEntryCollection : public Node 656c4bf6374SJason M. Bills { 657c4bf6374SJason M. Bills public: 658c4bf6374SJason M. Bills template <typename CrowApp> 65927062605SAnthony Wilson JournalEventLogEntryCollection(CrowApp &app) : 660029573d4SEd Tanous Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 661c4bf6374SJason M. Bills { 662c4bf6374SJason M. Bills entityPrivileges = { 663c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 664c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 665c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 666c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 667c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 668c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 669c4bf6374SJason M. Bills } 670c4bf6374SJason M. Bills 671c4bf6374SJason M. Bills private: 672c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 673c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 674c4bf6374SJason M. Bills { 675c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 676c4bf6374SJason M. Bills long skip = 0; 677c4bf6374SJason M. Bills long top = maxEntriesPerPage; // Show max entries by default 678c4bf6374SJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 679c4bf6374SJason M. Bills { 680c4bf6374SJason M. Bills return; 681c4bf6374SJason M. Bills } 682c4bf6374SJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 683c4bf6374SJason M. Bills { 684c4bf6374SJason M. Bills return; 685c4bf6374SJason M. Bills } 686c4bf6374SJason M. Bills // Collections don't include the static data added by SubRoute because 687c4bf6374SJason M. Bills // it has a duplicate entry for members 688c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 689c4bf6374SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 690c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.context"] = 691c4bf6374SJason M. Bills "/redfish/v1/$metadata#LogEntryCollection.LogEntryCollection"; 692c4bf6374SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 693029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 694c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 695c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = 696c4bf6374SJason M. Bills "Collection of System Event Log Entries"; 697cb92c03bSAndrew Geissler 698c4bf6374SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 699c4bf6374SJason M. Bills logEntryArray = nlohmann::json::array(); 70095820184SJason M. Bills // Go through the log files and create a unique ID for each entry 70195820184SJason M. Bills std::vector<std::filesystem::path> redfishLogFiles; 70295820184SJason M. Bills getRedfishLogFiles(redfishLogFiles); 703b01bf299SEd Tanous uint64_t entryCount = 0; 704cd225da8SJason M. Bills std::string logEntry; 70595820184SJason M. Bills 70695820184SJason M. Bills // Oldest logs are in the last file, so start there and loop backwards 707cd225da8SJason M. Bills for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend(); 708cd225da8SJason M. Bills it++) 709c4bf6374SJason M. Bills { 710cd225da8SJason M. Bills std::ifstream logStream(*it); 71195820184SJason M. Bills if (!logStream.is_open()) 712c4bf6374SJason M. Bills { 713c4bf6374SJason M. Bills continue; 714c4bf6374SJason M. Bills } 715c4bf6374SJason M. Bills 71695820184SJason M. Bills while (std::getline(logStream, logEntry)) 71795820184SJason M. Bills { 718c4bf6374SJason M. Bills entryCount++; 719c4bf6374SJason M. Bills // Handle paging using skip (number of entries to skip from the 720c4bf6374SJason M. Bills // start) and top (number of entries to display) 721c4bf6374SJason M. Bills if (entryCount <= skip || entryCount > skip + top) 722c4bf6374SJason M. Bills { 723c4bf6374SJason M. Bills continue; 724c4bf6374SJason M. Bills } 725c4bf6374SJason M. Bills 726c4bf6374SJason M. Bills std::string idStr; 72795820184SJason M. Bills if (!getUniqueEntryID(logEntry, idStr)) 728c4bf6374SJason M. Bills { 729c4bf6374SJason M. Bills continue; 730c4bf6374SJason M. Bills } 731c4bf6374SJason M. Bills 732c4bf6374SJason M. Bills logEntryArray.push_back({}); 733c4bf6374SJason M. Bills nlohmann::json &bmcLogEntry = logEntryArray.back(); 73495820184SJason M. Bills if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0) 735c4bf6374SJason M. Bills { 736c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 737c4bf6374SJason M. Bills return; 738c4bf6374SJason M. Bills } 739c4bf6374SJason M. Bills } 74095820184SJason M. Bills } 741c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 742c4bf6374SJason M. Bills if (skip + top < entryCount) 743c4bf6374SJason M. Bills { 744c4bf6374SJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 74595820184SJason M. Bills "/redfish/v1/Systems/system/LogServices/EventLog/" 74695820184SJason M. Bills "Entries?$skip=" + 747c4bf6374SJason M. Bills std::to_string(skip + top); 748c4bf6374SJason M. Bills } 74908a4e4b5SAnthony Wilson } 75008a4e4b5SAnthony Wilson }; 75108a4e4b5SAnthony Wilson 75208a4e4b5SAnthony Wilson class DBusEventLogEntryCollection : public Node 75308a4e4b5SAnthony Wilson { 75408a4e4b5SAnthony Wilson public: 75508a4e4b5SAnthony Wilson template <typename CrowApp> 75608a4e4b5SAnthony Wilson DBusEventLogEntryCollection(CrowApp &app) : 75708a4e4b5SAnthony Wilson Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/") 75808a4e4b5SAnthony Wilson { 75908a4e4b5SAnthony Wilson entityPrivileges = { 76008a4e4b5SAnthony Wilson {boost::beast::http::verb::get, {{"Login"}}}, 76108a4e4b5SAnthony Wilson {boost::beast::http::verb::head, {{"Login"}}}, 76208a4e4b5SAnthony Wilson {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 76308a4e4b5SAnthony Wilson {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 76408a4e4b5SAnthony Wilson {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 76508a4e4b5SAnthony Wilson {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 76608a4e4b5SAnthony Wilson } 76708a4e4b5SAnthony Wilson 76808a4e4b5SAnthony Wilson private: 76908a4e4b5SAnthony Wilson void doGet(crow::Response &res, const crow::Request &req, 77008a4e4b5SAnthony Wilson const std::vector<std::string> ¶ms) override 77108a4e4b5SAnthony Wilson { 77208a4e4b5SAnthony Wilson std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 77308a4e4b5SAnthony Wilson 77408a4e4b5SAnthony Wilson // Collections don't include the static data added by SubRoute because 77508a4e4b5SAnthony Wilson // it has a duplicate entry for members 77608a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.type"] = 77708a4e4b5SAnthony Wilson "#LogEntryCollection.LogEntryCollection"; 77808a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.context"] = 77908a4e4b5SAnthony Wilson "/redfish/v1/$metadata#LogEntryCollection.LogEntryCollection"; 78008a4e4b5SAnthony Wilson asyncResp->res.jsonValue["@odata.id"] = 78108a4e4b5SAnthony Wilson "/redfish/v1/Systems/system/LogServices/EventLog/Entries"; 78208a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Name"] = "System Event Log Entries"; 78308a4e4b5SAnthony Wilson asyncResp->res.jsonValue["Description"] = 78408a4e4b5SAnthony Wilson "Collection of System Event Log Entries"; 78508a4e4b5SAnthony Wilson 786cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 787cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 788cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 789cb92c03bSAndrew Geissler [asyncResp](const boost::system::error_code ec, 790cb92c03bSAndrew Geissler GetManagedObjectsType &resp) { 791cb92c03bSAndrew Geissler if (ec) 792cb92c03bSAndrew Geissler { 793cb92c03bSAndrew Geissler // TODO Handle for specific error code 794cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 795cb92c03bSAndrew Geissler << "getLogEntriesIfaceData resp_handler got error " 796cb92c03bSAndrew Geissler << ec; 797cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 798cb92c03bSAndrew Geissler return; 799cb92c03bSAndrew Geissler } 800cb92c03bSAndrew Geissler nlohmann::json &entriesArray = 801cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members"]; 802cb92c03bSAndrew Geissler entriesArray = nlohmann::json::array(); 803cb92c03bSAndrew Geissler for (auto &objectPath : resp) 804cb92c03bSAndrew Geissler { 805cb92c03bSAndrew Geissler for (auto &interfaceMap : objectPath.second) 806cb92c03bSAndrew Geissler { 807cb92c03bSAndrew Geissler if (interfaceMap.first != 808cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry") 809cb92c03bSAndrew Geissler { 810cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Bailing early on " 811cb92c03bSAndrew Geissler << interfaceMap.first; 812cb92c03bSAndrew Geissler continue; 813cb92c03bSAndrew Geissler } 814cb92c03bSAndrew Geissler entriesArray.push_back({}); 815cb92c03bSAndrew Geissler nlohmann::json &thisEntry = entriesArray.back(); 816cb92c03bSAndrew Geissler uint32_t *id; 817cb92c03bSAndrew Geissler std::time_t timestamp; 818cb92c03bSAndrew Geissler std::string *severity, *message; 819cb92c03bSAndrew Geissler bool *resolved; 820cb92c03bSAndrew Geissler for (auto &propertyMap : interfaceMap.second) 821cb92c03bSAndrew Geissler { 822cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 823cb92c03bSAndrew Geissler { 824cb92c03bSAndrew Geissler id = sdbusplus::message::variant_ns::get_if< 825cb92c03bSAndrew Geissler uint32_t>(&propertyMap.second); 826cb92c03bSAndrew Geissler if (id == nullptr) 827cb92c03bSAndrew Geissler { 828cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 829cb92c03bSAndrew Geissler "Id"); 830cb92c03bSAndrew Geissler } 831cb92c03bSAndrew Geissler } 832cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 833cb92c03bSAndrew Geissler { 834cb92c03bSAndrew Geissler const uint64_t *millisTimeStamp = 835cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 836cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 837cb92c03bSAndrew Geissler { 838cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 839cb92c03bSAndrew Geissler "Timestamp"); 840cb92c03bSAndrew Geissler } 841cb92c03bSAndrew Geissler // Retrieve Created property with format: 842cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 843cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 844cb92c03bSAndrew Geissler *millisTimeStamp); 845cb92c03bSAndrew Geissler timestamp = 846cb92c03bSAndrew Geissler std::chrono::duration_cast< 847cb92c03bSAndrew Geissler std::chrono::seconds>(chronoTimeStamp) 848cb92c03bSAndrew Geissler .count(); 849cb92c03bSAndrew Geissler } 850cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 851cb92c03bSAndrew Geissler { 852cb92c03bSAndrew Geissler severity = std::get_if<std::string>( 853cb92c03bSAndrew Geissler &propertyMap.second); 854cb92c03bSAndrew Geissler if (severity == nullptr) 855cb92c03bSAndrew Geissler { 856cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 857cb92c03bSAndrew Geissler "Severity"); 858cb92c03bSAndrew Geissler } 859cb92c03bSAndrew Geissler } 860cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 861cb92c03bSAndrew Geissler { 862cb92c03bSAndrew Geissler message = std::get_if<std::string>( 863cb92c03bSAndrew Geissler &propertyMap.second); 864cb92c03bSAndrew Geissler if (message == nullptr) 865cb92c03bSAndrew Geissler { 866cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 867cb92c03bSAndrew Geissler "Message"); 868cb92c03bSAndrew Geissler } 869cb92c03bSAndrew Geissler } 870cb92c03bSAndrew Geissler } 871cb92c03bSAndrew Geissler thisEntry = { 872cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 873cb92c03bSAndrew Geissler {"@odata.context", "/redfish/v1/" 874cb92c03bSAndrew Geissler "$metadata#LogEntry.LogEntry"}, 875cb92c03bSAndrew Geissler {"@odata.id", 876cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 877cb92c03bSAndrew Geissler "Entries/" + 878cb92c03bSAndrew Geissler std::to_string(*id)}, 87927062605SAnthony Wilson {"Name", "System Event Log Entry"}, 880cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 881cb92c03bSAndrew Geissler {"Message", *message}, 882cb92c03bSAndrew Geissler {"EntryType", "Event"}, 883cb92c03bSAndrew Geissler {"Severity", 884cb92c03bSAndrew Geissler translateSeverityDbusToRedfish(*severity)}, 885cb92c03bSAndrew Geissler {"Created", crow::utility::getDateTime(timestamp)}}; 886cb92c03bSAndrew Geissler } 887cb92c03bSAndrew Geissler } 888cb92c03bSAndrew Geissler std::sort(entriesArray.begin(), entriesArray.end(), 889cb92c03bSAndrew Geissler [](const nlohmann::json &left, 890cb92c03bSAndrew Geissler const nlohmann::json &right) { 891cb92c03bSAndrew Geissler return (left["Id"] <= right["Id"]); 892cb92c03bSAndrew Geissler }); 893cb92c03bSAndrew Geissler asyncResp->res.jsonValue["Members@odata.count"] = 894cb92c03bSAndrew Geissler entriesArray.size(); 895cb92c03bSAndrew Geissler }, 896cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", 897cb92c03bSAndrew Geissler "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); 898c4bf6374SJason M. Bills } 899c4bf6374SJason M. Bills }; 900c4bf6374SJason M. Bills 90108a4e4b5SAnthony Wilson class DBusEventLogEntry : public Node 902c4bf6374SJason M. Bills { 903c4bf6374SJason M. Bills public: 90408a4e4b5SAnthony Wilson DBusEventLogEntry(CrowApp &app) : 905c4bf6374SJason M. Bills Node(app, 906029573d4SEd Tanous "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/", 907029573d4SEd Tanous std::string()) 908c4bf6374SJason M. Bills { 909c4bf6374SJason M. Bills entityPrivileges = { 910c4bf6374SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 911c4bf6374SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 912c4bf6374SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 913c4bf6374SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 914c4bf6374SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 915c4bf6374SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 916c4bf6374SJason M. Bills } 917c4bf6374SJason M. Bills 918c4bf6374SJason M. Bills private: 919c4bf6374SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 920c4bf6374SJason M. Bills const std::vector<std::string> ¶ms) override 921c4bf6374SJason M. Bills { 922c4bf6374SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 923029573d4SEd Tanous if (params.size() != 1) 924c4bf6374SJason M. Bills { 925c4bf6374SJason M. Bills messages::internalError(asyncResp->res); 926c4bf6374SJason M. Bills return; 927c4bf6374SJason M. Bills } 928029573d4SEd Tanous const std::string &entryID = params[0]; 929cb92c03bSAndrew Geissler 930cb92c03bSAndrew Geissler // DBus implementation of EventLog/Entries 931cb92c03bSAndrew Geissler // Make call to Logging Service to find all log entry objects 932cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 933cb92c03bSAndrew Geissler [asyncResp, entryID](const boost::system::error_code ec, 934cb92c03bSAndrew Geissler GetManagedPropertyType &resp) { 935cb92c03bSAndrew Geissler if (ec) 936cb92c03bSAndrew Geissler { 937cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR 938cb92c03bSAndrew Geissler << "EventLogEntry (DBus) resp_handler got error " << ec; 939cb92c03bSAndrew Geissler messages::internalError(asyncResp->res); 940cb92c03bSAndrew Geissler return; 941cb92c03bSAndrew Geissler } 942cb92c03bSAndrew Geissler uint32_t *id; 943cb92c03bSAndrew Geissler std::time_t timestamp; 944cb92c03bSAndrew Geissler std::string *severity, *message; 945cb92c03bSAndrew Geissler bool *resolved; 946cb92c03bSAndrew Geissler for (auto &propertyMap : resp) 947cb92c03bSAndrew Geissler { 948cb92c03bSAndrew Geissler if (propertyMap.first == "Id") 949cb92c03bSAndrew Geissler { 950cb92c03bSAndrew Geissler id = std::get_if<uint32_t>(&propertyMap.second); 951cb92c03bSAndrew Geissler if (id == nullptr) 952cb92c03bSAndrew Geissler { 953cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, "Id"); 954cb92c03bSAndrew Geissler } 955cb92c03bSAndrew Geissler } 956cb92c03bSAndrew Geissler else if (propertyMap.first == "Timestamp") 957cb92c03bSAndrew Geissler { 958cb92c03bSAndrew Geissler const uint64_t *millisTimeStamp = 959cb92c03bSAndrew Geissler std::get_if<uint64_t>(&propertyMap.second); 960cb92c03bSAndrew Geissler if (millisTimeStamp == nullptr) 961cb92c03bSAndrew Geissler { 962cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 963cb92c03bSAndrew Geissler "Timestamp"); 964cb92c03bSAndrew Geissler } 965cb92c03bSAndrew Geissler // Retrieve Created property with format: 966cb92c03bSAndrew Geissler // yyyy-mm-ddThh:mm:ss 967cb92c03bSAndrew Geissler std::chrono::milliseconds chronoTimeStamp( 968cb92c03bSAndrew Geissler *millisTimeStamp); 969cb92c03bSAndrew Geissler timestamp = 970cb92c03bSAndrew Geissler std::chrono::duration_cast<std::chrono::seconds>( 971cb92c03bSAndrew Geissler chronoTimeStamp) 972cb92c03bSAndrew Geissler .count(); 973cb92c03bSAndrew Geissler } 974cb92c03bSAndrew Geissler else if (propertyMap.first == "Severity") 975cb92c03bSAndrew Geissler { 976cb92c03bSAndrew Geissler severity = 977cb92c03bSAndrew Geissler std::get_if<std::string>(&propertyMap.second); 978cb92c03bSAndrew Geissler if (severity == nullptr) 979cb92c03bSAndrew Geissler { 980cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 981cb92c03bSAndrew Geissler "Severity"); 982cb92c03bSAndrew Geissler } 983cb92c03bSAndrew Geissler } 984cb92c03bSAndrew Geissler else if (propertyMap.first == "Message") 985cb92c03bSAndrew Geissler { 986cb92c03bSAndrew Geissler message = std::get_if<std::string>(&propertyMap.second); 987cb92c03bSAndrew Geissler if (message == nullptr) 988cb92c03bSAndrew Geissler { 989cb92c03bSAndrew Geissler messages::propertyMissing(asyncResp->res, 990cb92c03bSAndrew Geissler "Message"); 991cb92c03bSAndrew Geissler } 992cb92c03bSAndrew Geissler } 993cb92c03bSAndrew Geissler } 994cb92c03bSAndrew Geissler asyncResp->res.jsonValue = { 995cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 996cb92c03bSAndrew Geissler {"@odata.context", "/redfish/v1/" 997cb92c03bSAndrew Geissler "$metadata#LogEntry.LogEntry"}, 998cb92c03bSAndrew Geissler {"@odata.id", 999cb92c03bSAndrew Geissler "/redfish/v1/Systems/system/LogServices/EventLog/" 1000cb92c03bSAndrew Geissler "Entries/" + 1001cb92c03bSAndrew Geissler std::to_string(*id)}, 100227062605SAnthony Wilson {"Name", "System Event Log Entry"}, 1003cb92c03bSAndrew Geissler {"Id", std::to_string(*id)}, 1004cb92c03bSAndrew Geissler {"Message", *message}, 1005cb92c03bSAndrew Geissler {"EntryType", "Event"}, 1006cb92c03bSAndrew Geissler {"Severity", translateSeverityDbusToRedfish(*severity)}, 100708a4e4b5SAnthony Wilson {"Created", crow::utility::getDateTime(timestamp)}}; 1008cb92c03bSAndrew Geissler }, 1009cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging", 1010cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging/entry/" + entryID, 1011cb92c03bSAndrew Geissler "org.freedesktop.DBus.Properties", "GetAll", 1012cb92c03bSAndrew Geissler "xyz.openbmc_project.Logging.Entry"); 1013c4bf6374SJason M. Bills } 1014*336e96c6SChicago Duan 1015*336e96c6SChicago Duan void doDelete(crow::Response &res, const crow::Request &req, 1016*336e96c6SChicago Duan const std::vector<std::string> ¶ms) override 1017*336e96c6SChicago Duan { 1018*336e96c6SChicago Duan 1019*336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "Do delete single event entries."; 1020*336e96c6SChicago Duan 1021*336e96c6SChicago Duan auto asyncResp = std::make_shared<AsyncResp>(res); 1022*336e96c6SChicago Duan 1023*336e96c6SChicago Duan if (params.size() != 1) 1024*336e96c6SChicago Duan { 1025*336e96c6SChicago Duan messages::internalError(asyncResp->res); 1026*336e96c6SChicago Duan return; 1027*336e96c6SChicago Duan } 1028*336e96c6SChicago Duan std::string entryID = params[0]; 1029*336e96c6SChicago Duan 1030*336e96c6SChicago Duan dbus::utility::escapePathForDbus(entryID); 1031*336e96c6SChicago Duan 1032*336e96c6SChicago Duan // Process response from Logging service. 1033*336e96c6SChicago Duan auto respHandler = [asyncResp](const boost::system::error_code ec) { 1034*336e96c6SChicago Duan BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done"; 1035*336e96c6SChicago Duan if (ec) 1036*336e96c6SChicago Duan { 1037*336e96c6SChicago Duan // TODO Handle for specific error code 1038*336e96c6SChicago Duan BMCWEB_LOG_ERROR 1039*336e96c6SChicago Duan << "EventLogEntry (DBus) doDelete respHandler got error " 1040*336e96c6SChicago Duan << ec; 1041*336e96c6SChicago Duan asyncResp->res.result( 1042*336e96c6SChicago Duan boost::beast::http::status::internal_server_error); 1043*336e96c6SChicago Duan return; 1044*336e96c6SChicago Duan } 1045*336e96c6SChicago Duan 1046*336e96c6SChicago Duan asyncResp->res.result(boost::beast::http::status::ok); 1047*336e96c6SChicago Duan }; 1048*336e96c6SChicago Duan 1049*336e96c6SChicago Duan // Make call to Logging service to request Delete Log 1050*336e96c6SChicago Duan crow::connections::systemBus->async_method_call( 1051*336e96c6SChicago Duan respHandler, "xyz.openbmc_project.Logging", 1052*336e96c6SChicago Duan "/xyz/openbmc_project/logging/entry/" + entryID, 1053*336e96c6SChicago Duan "xyz.openbmc_project.Object.Delete", "Delete"); 1054*336e96c6SChicago Duan } 1055c4bf6374SJason M. Bills }; 1056c4bf6374SJason M. Bills 1057c4bf6374SJason M. Bills class BMCLogServiceCollection : public Node 1058c4bf6374SJason M. Bills { 1059c4bf6374SJason M. Bills public: 1060c4bf6374SJason M. Bills template <typename CrowApp> 1061c4bf6374SJason M. Bills BMCLogServiceCollection(CrowApp &app) : 10624ed77cd5SEd Tanous Node(app, "/redfish/v1/Managers/bmc/LogServices/") 10631da66f75SEd Tanous { 10641da66f75SEd Tanous entityPrivileges = { 1065e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1066e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1067e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1068e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1069e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1070e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 10711da66f75SEd Tanous } 10721da66f75SEd Tanous 10731da66f75SEd Tanous private: 10741da66f75SEd Tanous /** 10751da66f75SEd Tanous * Functions triggers appropriate requests on DBus 10761da66f75SEd Tanous */ 10771da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 10781da66f75SEd Tanous const std::vector<std::string> ¶ms) override 10791da66f75SEd Tanous { 1080e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 10811da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 10821da66f75SEd Tanous // it has a duplicate entry for members 1083e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 10841da66f75SEd Tanous "#LogServiceCollection.LogServiceCollection"; 1085e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.context"] = 1086c4bf6374SJason M. Bills "/redfish/v1/$metadata#LogServiceCollection.LogServiceCollection"; 1087e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1088e1f26343SJason M. Bills "/redfish/v1/Managers/bmc/LogServices"; 1089e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection"; 1090e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 10911da66f75SEd Tanous "Collection of LogServices for this Manager"; 1092c4bf6374SJason M. Bills nlohmann::json &logServiceArray = asyncResp->res.jsonValue["Members"]; 1093c4bf6374SJason M. Bills logServiceArray = nlohmann::json::array(); 1094c4bf6374SJason M. Bills #ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL 1095c4bf6374SJason M. Bills logServiceArray.push_back( 109608a4e4b5SAnthony Wilson {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}}); 1097c4bf6374SJason M. Bills #endif 1098e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1099c4bf6374SJason M. Bills logServiceArray.size(); 11001da66f75SEd Tanous } 11011da66f75SEd Tanous }; 11021da66f75SEd Tanous 1103c4bf6374SJason M. Bills class BMCJournalLogService : public Node 11041da66f75SEd Tanous { 11051da66f75SEd Tanous public: 11061da66f75SEd Tanous template <typename CrowApp> 1107c4bf6374SJason M. Bills BMCJournalLogService(CrowApp &app) : 1108c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/") 1109e1f26343SJason M. Bills { 1110e1f26343SJason M. Bills entityPrivileges = { 1111e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1112e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1113e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1114e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1115e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1116e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1117e1f26343SJason M. Bills } 1118e1f26343SJason M. Bills 1119e1f26343SJason M. Bills private: 1120e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1121e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1122e1f26343SJason M. Bills { 1123e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1124e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1125e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 11260f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 11270f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal"; 1128e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.context"] = 1129e1f26343SJason M. Bills "/redfish/v1/$metadata#LogService.LogService"; 1130c4bf6374SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service"; 1131c4bf6374SJason M. Bills asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service"; 1132c4bf6374SJason M. Bills asyncResp->res.jsonValue["Id"] = "BMC Journal"; 1133e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1134cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1135cd50aa42SJason M. Bills {"@odata.id", 1136086be238SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}}; 1137e1f26343SJason M. Bills } 1138e1f26343SJason M. Bills }; 1139e1f26343SJason M. Bills 1140c4bf6374SJason M. Bills static int fillBMCJournalLogEntryJson(const std::string &bmcJournalLogEntryID, 1141e1f26343SJason M. Bills sd_journal *journal, 1142c4bf6374SJason M. Bills nlohmann::json &bmcJournalLogEntryJson) 1143e1f26343SJason M. Bills { 1144e1f26343SJason M. Bills // Get the Log Entry contents 1145e1f26343SJason M. Bills int ret = 0; 1146e1f26343SJason M. Bills 114739e77504SEd Tanous std::string_view msg; 114816428a1aSJason M. Bills ret = getJournalMetadata(journal, "MESSAGE", msg); 1149e1f26343SJason M. Bills if (ret < 0) 1150e1f26343SJason M. Bills { 1151e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret); 1152e1f26343SJason M. Bills return 1; 1153e1f26343SJason M. Bills } 1154e1f26343SJason M. Bills 1155e1f26343SJason M. Bills // Get the severity from the PRIORITY field 1156e1f26343SJason M. Bills int severity = 8; // Default to an invalid priority 115716428a1aSJason M. Bills ret = getJournalMetadata(journal, "PRIORITY", 10, severity); 1158e1f26343SJason M. Bills if (ret < 0) 1159e1f26343SJason M. Bills { 1160e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret); 1161e1f26343SJason M. Bills return 1; 1162e1f26343SJason M. Bills } 1163e1f26343SJason M. Bills 1164e1f26343SJason M. Bills // Get the Created time from the timestamp 116516428a1aSJason M. Bills std::string entryTimeStr; 116616428a1aSJason M. Bills if (!getEntryTimestamp(journal, entryTimeStr)) 1167e1f26343SJason M. Bills { 116816428a1aSJason M. Bills return 1; 1169e1f26343SJason M. Bills } 1170e1f26343SJason M. Bills 1171e1f26343SJason M. Bills // Fill in the log entry with the gathered data 1172c4bf6374SJason M. Bills bmcJournalLogEntryJson = { 1173cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1174e1f26343SJason M. Bills {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 1175c4bf6374SJason M. Bills {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" + 1176c4bf6374SJason M. Bills bmcJournalLogEntryID}, 1177e1f26343SJason M. Bills {"Name", "BMC Journal Entry"}, 1178c4bf6374SJason M. Bills {"Id", bmcJournalLogEntryID}, 117916428a1aSJason M. Bills {"Message", msg}, 1180e1f26343SJason M. Bills {"EntryType", "Oem"}, 1181e1f26343SJason M. Bills {"Severity", 1182e1f26343SJason M. Bills severity <= 2 ? "Critical" 1183e1f26343SJason M. Bills : severity <= 4 ? "Warning" : severity <= 7 ? "OK" : ""}, 1184086be238SEd Tanous {"OemRecordFormat", "BMC Journal Entry"}, 1185e1f26343SJason M. Bills {"Created", std::move(entryTimeStr)}}; 1186e1f26343SJason M. Bills return 0; 1187e1f26343SJason M. Bills } 1188e1f26343SJason M. Bills 1189c4bf6374SJason M. Bills class BMCJournalLogEntryCollection : public Node 1190e1f26343SJason M. Bills { 1191e1f26343SJason M. Bills public: 1192e1f26343SJason M. Bills template <typename CrowApp> 1193c4bf6374SJason M. Bills BMCJournalLogEntryCollection(CrowApp &app) : 1194c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/") 1195e1f26343SJason M. Bills { 1196e1f26343SJason M. Bills entityPrivileges = { 1197e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1198e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1199e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1200e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1201e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1202e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1203e1f26343SJason M. Bills } 1204e1f26343SJason M. Bills 1205e1f26343SJason M. Bills private: 1206e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1207e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1208e1f26343SJason M. Bills { 1209e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1210193ad2faSJason M. Bills static constexpr const long maxEntriesPerPage = 1000; 1211193ad2faSJason M. Bills long skip = 0; 1212193ad2faSJason M. Bills long top = maxEntriesPerPage; // Show max entries by default 121316428a1aSJason M. Bills if (!getSkipParam(asyncResp->res, req, skip)) 1214193ad2faSJason M. Bills { 1215193ad2faSJason M. Bills return; 1216193ad2faSJason M. Bills } 121716428a1aSJason M. Bills if (!getTopParam(asyncResp->res, req, top)) 1218193ad2faSJason M. Bills { 1219193ad2faSJason M. Bills return; 1220193ad2faSJason M. Bills } 1221e1f26343SJason M. Bills // Collections don't include the static data added by SubRoute because 1222e1f26343SJason M. Bills // it has a duplicate entry for members 1223e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1224e1f26343SJason M. Bills "#LogEntryCollection.LogEntryCollection"; 12250f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 12260f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1227e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.context"] = 1228c4bf6374SJason M. Bills "/redfish/v1/$metadata#LogEntryCollection.LogEntryCollection"; 1229e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.id"] = 1230c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"; 1231e1f26343SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries"; 1232e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1233e1f26343SJason M. Bills "Collection of BMC Journal Entries"; 12340f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 12350f74e643SEd Tanous "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries"; 1236e1f26343SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 1237e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 1238e1f26343SJason M. Bills 1239e1f26343SJason M. Bills // Go through the journal and use the timestamp to create a unique ID 1240e1f26343SJason M. Bills // for each entry 1241e1f26343SJason M. Bills sd_journal *journalTmp = nullptr; 1242e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1243e1f26343SJason M. Bills if (ret < 0) 1244e1f26343SJason M. Bills { 1245e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1246f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1247e1f26343SJason M. Bills return; 1248e1f26343SJason M. Bills } 1249e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1250e1f26343SJason M. Bills journalTmp, sd_journal_close); 1251e1f26343SJason M. Bills journalTmp = nullptr; 1252b01bf299SEd Tanous uint64_t entryCount = 0; 1253e1f26343SJason M. Bills SD_JOURNAL_FOREACH(journal.get()) 1254e1f26343SJason M. Bills { 1255193ad2faSJason M. Bills entryCount++; 1256193ad2faSJason M. Bills // Handle paging using skip (number of entries to skip from the 1257193ad2faSJason M. Bills // start) and top (number of entries to display) 1258193ad2faSJason M. Bills if (entryCount <= skip || entryCount > skip + top) 1259193ad2faSJason M. Bills { 1260193ad2faSJason M. Bills continue; 1261193ad2faSJason M. Bills } 1262193ad2faSJason M. Bills 126316428a1aSJason M. Bills std::string idStr; 126416428a1aSJason M. Bills if (!getUniqueEntryID(journal.get(), idStr)) 1265e1f26343SJason M. Bills { 1266e1f26343SJason M. Bills continue; 1267e1f26343SJason M. Bills } 1268e1f26343SJason M. Bills 1269e1f26343SJason M. Bills logEntryArray.push_back({}); 1270c4bf6374SJason M. Bills nlohmann::json &bmcJournalLogEntry = logEntryArray.back(); 1271c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(idStr, journal.get(), 1272c4bf6374SJason M. Bills bmcJournalLogEntry) != 0) 1273e1f26343SJason M. Bills { 1274f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1275e1f26343SJason M. Bills return; 1276e1f26343SJason M. Bills } 1277e1f26343SJason M. Bills } 1278193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = entryCount; 1279193ad2faSJason M. Bills if (skip + top < entryCount) 1280193ad2faSJason M. Bills { 1281193ad2faSJason M. Bills asyncResp->res.jsonValue["Members@odata.nextLink"] = 1282c4bf6374SJason M. Bills "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" + 1283193ad2faSJason M. Bills std::to_string(skip + top); 1284193ad2faSJason M. Bills } 1285e1f26343SJason M. Bills } 1286e1f26343SJason M. Bills }; 1287e1f26343SJason M. Bills 1288c4bf6374SJason M. Bills class BMCJournalLogEntry : public Node 1289e1f26343SJason M. Bills { 1290e1f26343SJason M. Bills public: 1291c4bf6374SJason M. Bills BMCJournalLogEntry(CrowApp &app) : 1292c4bf6374SJason M. Bills Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/", 1293e1f26343SJason M. Bills std::string()) 1294e1f26343SJason M. Bills { 1295e1f26343SJason M. Bills entityPrivileges = { 1296e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1297e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1298e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1299e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1300e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1301e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1302e1f26343SJason M. Bills } 1303e1f26343SJason M. Bills 1304e1f26343SJason M. Bills private: 1305e1f26343SJason M. Bills void doGet(crow::Response &res, const crow::Request &req, 1306e1f26343SJason M. Bills const std::vector<std::string> ¶ms) override 1307e1f26343SJason M. Bills { 1308e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1309e1f26343SJason M. Bills if (params.size() != 1) 1310e1f26343SJason M. Bills { 1311f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1312e1f26343SJason M. Bills return; 1313e1f26343SJason M. Bills } 131416428a1aSJason M. Bills const std::string &entryID = params[0]; 1315e1f26343SJason M. Bills // Convert the unique ID back to a timestamp to find the entry 1316e1f26343SJason M. Bills uint64_t ts = 0; 1317e1f26343SJason M. Bills uint16_t index = 0; 131816428a1aSJason M. Bills if (!getTimestampFromID(asyncResp->res, entryID, ts, index)) 1319e1f26343SJason M. Bills { 132016428a1aSJason M. Bills return; 1321e1f26343SJason M. Bills } 1322e1f26343SJason M. Bills 1323e1f26343SJason M. Bills sd_journal *journalTmp = nullptr; 1324e1f26343SJason M. Bills int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY); 1325e1f26343SJason M. Bills if (ret < 0) 1326e1f26343SJason M. Bills { 1327e1f26343SJason M. Bills BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret); 1328f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1329e1f26343SJason M. Bills return; 1330e1f26343SJason M. Bills } 1331e1f26343SJason M. Bills std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal( 1332e1f26343SJason M. Bills journalTmp, sd_journal_close); 1333e1f26343SJason M. Bills journalTmp = nullptr; 1334e1f26343SJason M. Bills // Go to the timestamp in the log and move to the entry at the index 1335e1f26343SJason M. Bills ret = sd_journal_seek_realtime_usec(journal.get(), ts); 1336e1f26343SJason M. Bills for (int i = 0; i <= index; i++) 1337e1f26343SJason M. Bills { 1338e1f26343SJason M. Bills sd_journal_next(journal.get()); 1339e1f26343SJason M. Bills } 1340c4bf6374SJason M. Bills // Confirm that the entry ID matches what was requested 1341c4bf6374SJason M. Bills std::string idStr; 1342c4bf6374SJason M. Bills if (!getUniqueEntryID(journal.get(), idStr) || idStr != entryID) 1343c4bf6374SJason M. Bills { 1344c4bf6374SJason M. Bills messages::resourceMissingAtURI(asyncResp->res, entryID); 1345c4bf6374SJason M. Bills return; 1346c4bf6374SJason M. Bills } 1347c4bf6374SJason M. Bills 1348c4bf6374SJason M. Bills if (fillBMCJournalLogEntryJson(entryID, journal.get(), 1349e1f26343SJason M. Bills asyncResp->res.jsonValue) != 0) 1350e1f26343SJason M. Bills { 1351f12894f8SJason M. Bills messages::internalError(asyncResp->res); 1352e1f26343SJason M. Bills return; 1353e1f26343SJason M. Bills } 1354e1f26343SJason M. Bills } 1355e1f26343SJason M. Bills }; 1356e1f26343SJason M. Bills 1357424c4176SJason M. Bills class CrashdumpService : public Node 1358e1f26343SJason M. Bills { 1359e1f26343SJason M. Bills public: 1360e1f26343SJason M. Bills template <typename CrowApp> 1361424c4176SJason M. Bills CrashdumpService(CrowApp &app) : 1362424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/") 13631da66f75SEd Tanous { 13641da66f75SEd Tanous entityPrivileges = { 1365e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1366e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1367e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1368e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1369e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1370e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 13711da66f75SEd Tanous } 13721da66f75SEd Tanous 13731da66f75SEd Tanous private: 13741da66f75SEd Tanous /** 13751da66f75SEd Tanous * Functions triggers appropriate requests on DBus 13761da66f75SEd Tanous */ 13771da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 13781da66f75SEd Tanous const std::vector<std::string> ¶ms) override 13791da66f75SEd Tanous { 1380e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 13811da66f75SEd Tanous // Copy over the static data to include the entries added by SubRoute 13820f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1383424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump"; 1384e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 1385e1f26343SJason M. Bills "#LogService.v1_1_0.LogService"; 1386e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.context"] = 1387c4bf6374SJason M. Bills "/redfish/v1/$metadata#LogService.LogService"; 1388424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Service"; 1389424c4176SJason M. Bills asyncResp->res.jsonValue["Description"] = "Crashdump Service"; 1390424c4176SJason M. Bills asyncResp->res.jsonValue["Id"] = "Crashdump"; 1391e1f26343SJason M. Bills asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull"; 1392e1f26343SJason M. Bills asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3; 1393cd50aa42SJason M. Bills asyncResp->res.jsonValue["Entries"] = { 1394cd50aa42SJason M. Bills {"@odata.id", 1395424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}}; 1396e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"] = { 13971da66f75SEd Tanous {"Oem", 1398424c4176SJason M. Bills {{"#Crashdump.OnDemand", 1399424c4176SJason M. Bills {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 1400424c4176SJason M. Bills "Actions/Oem/Crashdump.OnDemand"}}}}}}; 14011da66f75SEd Tanous 14021da66f75SEd Tanous #ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI 1403e1f26343SJason M. Bills asyncResp->res.jsonValue["Actions"]["Oem"].push_back( 1404424c4176SJason M. Bills {"#Crashdump.SendRawPeci", 140508a4e4b5SAnthony Wilson {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/" 1406424c4176SJason M. Bills "Actions/Oem/Crashdump.SendRawPeci"}}}); 14071da66f75SEd Tanous #endif 14081da66f75SEd Tanous } 14091da66f75SEd Tanous }; 14101da66f75SEd Tanous 1411424c4176SJason M. Bills class CrashdumpEntryCollection : public Node 14121da66f75SEd Tanous { 14131da66f75SEd Tanous public: 14141da66f75SEd Tanous template <typename CrowApp> 1415424c4176SJason M. Bills CrashdumpEntryCollection(CrowApp &app) : 1416424c4176SJason M. Bills Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/") 14171da66f75SEd Tanous { 14181da66f75SEd Tanous entityPrivileges = { 1419e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1420e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1421e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1422e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1423e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1424e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 14251da66f75SEd Tanous } 14261da66f75SEd Tanous 14271da66f75SEd Tanous private: 14281da66f75SEd Tanous /** 14291da66f75SEd Tanous * Functions triggers appropriate requests on DBus 14301da66f75SEd Tanous */ 14311da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 14321da66f75SEd Tanous const std::vector<std::string> ¶ms) override 14331da66f75SEd Tanous { 1434e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 14351da66f75SEd Tanous // Collections don't include the static data added by SubRoute because 14361da66f75SEd Tanous // it has a duplicate entry for members 1437e1f26343SJason M. Bills auto getLogEntriesCallback = [asyncResp]( 1438e1f26343SJason M. Bills const boost::system::error_code ec, 14391da66f75SEd Tanous const std::vector<std::string> &resp) { 14401da66f75SEd Tanous if (ec) 14411da66f75SEd Tanous { 14421da66f75SEd Tanous if (ec.value() != 14431da66f75SEd Tanous boost::system::errc::no_such_file_or_directory) 14441da66f75SEd Tanous { 14451da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to get entries ec: " 14461da66f75SEd Tanous << ec.message(); 1447f12894f8SJason M. Bills messages::internalError(asyncResp->res); 14481da66f75SEd Tanous return; 14491da66f75SEd Tanous } 14501da66f75SEd Tanous } 1451e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.type"] = 14521da66f75SEd Tanous "#LogEntryCollection.LogEntryCollection"; 14530f74e643SEd Tanous asyncResp->res.jsonValue["@odata.id"] = 1454424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"; 1455e1f26343SJason M. Bills asyncResp->res.jsonValue["@odata.context"] = 1456d53dd41fSJason M. Bills "/redfish/v1/" 1457d53dd41fSJason M. Bills "$metadata#LogEntryCollection.LogEntryCollection"; 1458424c4176SJason M. Bills asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries"; 1459e1f26343SJason M. Bills asyncResp->res.jsonValue["Description"] = 1460424c4176SJason M. Bills "Collection of Crashdump Entries"; 1461e1f26343SJason M. Bills nlohmann::json &logEntryArray = asyncResp->res.jsonValue["Members"]; 1462e1f26343SJason M. Bills logEntryArray = nlohmann::json::array(); 14631da66f75SEd Tanous for (const std::string &objpath : resp) 14641da66f75SEd Tanous { 146548e4639eSJason M. Bills // Don't list the on-demand log 1466424c4176SJason M. Bills if (objpath.compare(CrashdumpOnDemandPath) == 0) 14671da66f75SEd Tanous { 14681da66f75SEd Tanous continue; 14691da66f75SEd Tanous } 14704ed77cd5SEd Tanous std::size_t lastPos = objpath.rfind("/"); 14714ed77cd5SEd Tanous if (lastPos != std::string::npos) 14721da66f75SEd Tanous { 1473e1f26343SJason M. Bills logEntryArray.push_back( 1474d53dd41fSJason M. Bills {{"@odata.id", "/redfish/v1/Systems/system/LogServices/" 1475424c4176SJason M. Bills "Crashdump/Entries/" + 14764ed77cd5SEd Tanous objpath.substr(lastPos + 1)}}); 14771da66f75SEd Tanous } 14781da66f75SEd Tanous } 1479e1f26343SJason M. Bills asyncResp->res.jsonValue["Members@odata.count"] = 1480e1f26343SJason M. Bills logEntryArray.size(); 14811da66f75SEd Tanous }; 14821da66f75SEd Tanous crow::connections::systemBus->async_method_call( 14831da66f75SEd Tanous std::move(getLogEntriesCallback), 14841da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", 14851da66f75SEd Tanous "/xyz/openbmc_project/object_mapper", 14861da66f75SEd Tanous "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0, 1487424c4176SJason M. Bills std::array<const char *, 1>{CrashdumpInterface}); 14881da66f75SEd Tanous } 14891da66f75SEd Tanous }; 14901da66f75SEd Tanous 1491424c4176SJason M. Bills std::string getLogCreatedTime(const nlohmann::json &Crashdump) 14921da66f75SEd Tanous { 1493424c4176SJason M. Bills nlohmann::json::const_iterator cdIt = Crashdump.find("crashlog_data"); 1494424c4176SJason M. Bills if (cdIt != Crashdump.end()) 14951da66f75SEd Tanous { 1496c4d00437SJason M. Bills nlohmann::json::const_iterator siIt = cdIt->find("SYSTEM_INFO"); 1497c4d00437SJason M. Bills if (siIt != cdIt->end()) 14981da66f75SEd Tanous { 1499c4d00437SJason M. Bills nlohmann::json::const_iterator tsIt = siIt->find("timestamp"); 1500c4d00437SJason M. Bills if (tsIt != siIt->end()) 1501c4d00437SJason M. Bills { 1502c4d00437SJason M. Bills const std::string *logTime = 1503c4d00437SJason M. Bills tsIt->get_ptr<const std::string *>(); 15041da66f75SEd Tanous if (logTime != nullptr) 15051da66f75SEd Tanous { 15061da66f75SEd Tanous return *logTime; 15071da66f75SEd Tanous } 15081da66f75SEd Tanous } 15091da66f75SEd Tanous } 1510c4d00437SJason M. Bills } 15111da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to find log timestamp"; 15121da66f75SEd Tanous 15131da66f75SEd Tanous return std::string(); 15141da66f75SEd Tanous } 15151da66f75SEd Tanous 1516424c4176SJason M. Bills class CrashdumpEntry : public Node 15171da66f75SEd Tanous { 15181da66f75SEd Tanous public: 1519424c4176SJason M. Bills CrashdumpEntry(CrowApp &app) : 1520d53dd41fSJason M. Bills Node(app, 1521424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/", 15221da66f75SEd Tanous std::string()) 15231da66f75SEd Tanous { 15241da66f75SEd Tanous entityPrivileges = { 1525e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1526e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1527e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1528e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1529e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1530e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 15311da66f75SEd Tanous } 15321da66f75SEd Tanous 15331da66f75SEd Tanous private: 15341da66f75SEd Tanous void doGet(crow::Response &res, const crow::Request &req, 15351da66f75SEd Tanous const std::vector<std::string> ¶ms) override 15361da66f75SEd Tanous { 1537e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 15381da66f75SEd Tanous if (params.size() != 1) 15391da66f75SEd Tanous { 1540f12894f8SJason M. Bills messages::internalError(asyncResp->res); 15411da66f75SEd Tanous return; 15421da66f75SEd Tanous } 1543b01bf299SEd Tanous const uint8_t logId = std::atoi(params[0].c_str()); 1544abf2add6SEd Tanous auto getStoredLogCallback = [asyncResp, logId]( 1545abf2add6SEd Tanous const boost::system::error_code ec, 1546abf2add6SEd Tanous const std::variant<std::string> &resp) { 15471da66f75SEd Tanous if (ec) 15481da66f75SEd Tanous { 1549abf2add6SEd Tanous BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); 1550f12894f8SJason M. Bills messages::internalError(asyncResp->res); 15511da66f75SEd Tanous return; 15521da66f75SEd Tanous } 1553abf2add6SEd Tanous const std::string *log = std::get_if<std::string>(&resp); 15541da66f75SEd Tanous if (log == nullptr) 15551da66f75SEd Tanous { 1556f12894f8SJason M. Bills messages::internalError(asyncResp->res); 15571da66f75SEd Tanous return; 15581da66f75SEd Tanous } 15591da66f75SEd Tanous nlohmann::json j = nlohmann::json::parse(*log, nullptr, false); 15601da66f75SEd Tanous if (j.is_discarded()) 15611da66f75SEd Tanous { 1562f12894f8SJason M. Bills messages::internalError(asyncResp->res); 15631da66f75SEd Tanous return; 15641da66f75SEd Tanous } 15651da66f75SEd Tanous std::string t = getLogCreatedTime(j); 1566e1f26343SJason M. Bills asyncResp->res.jsonValue = { 1567cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 1568abf2add6SEd Tanous {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 15691da66f75SEd Tanous {"@odata.id", 1570424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" + 15714ed77cd5SEd Tanous std::to_string(logId)}, 1572424c4176SJason M. Bills {"Name", "CPU Crashdump"}, 15734ed77cd5SEd Tanous {"Id", logId}, 15741da66f75SEd Tanous {"EntryType", "Oem"}, 1575424c4176SJason M. Bills {"OemRecordFormat", "Intel Crashdump"}, 15761da66f75SEd Tanous {"Oem", {{"Intel", std::move(j)}}}, 15771da66f75SEd Tanous {"Created", std::move(t)}}; 15781da66f75SEd Tanous }; 15791da66f75SEd Tanous crow::connections::systemBus->async_method_call( 1580424c4176SJason M. Bills std::move(getStoredLogCallback), CrashdumpObject, 1581424c4176SJason M. Bills CrashdumpPath + std::string("/") + std::to_string(logId), 1582424c4176SJason M. Bills "org.freedesktop.DBus.Properties", "Get", CrashdumpInterface, 1583424c4176SJason M. Bills "Log"); 15841da66f75SEd Tanous } 15851da66f75SEd Tanous }; 15861da66f75SEd Tanous 1587424c4176SJason M. Bills class OnDemandCrashdump : public Node 15881da66f75SEd Tanous { 15891da66f75SEd Tanous public: 1590424c4176SJason M. Bills OnDemandCrashdump(CrowApp &app) : 1591424c4176SJason M. Bills Node(app, 1592424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 1593424c4176SJason M. Bills "Crashdump.OnDemand/") 15941da66f75SEd Tanous { 15951da66f75SEd Tanous entityPrivileges = { 1596e1f26343SJason M. Bills {boost::beast::http::verb::get, {{"Login"}}}, 1597e1f26343SJason M. Bills {boost::beast::http::verb::head, {{"Login"}}}, 1598e1f26343SJason M. Bills {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1599e1f26343SJason M. Bills {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1600e1f26343SJason M. Bills {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1601e1f26343SJason M. Bills {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 16021da66f75SEd Tanous } 16031da66f75SEd Tanous 16041da66f75SEd Tanous private: 16051da66f75SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 16061da66f75SEd Tanous const std::vector<std::string> ¶ms) override 16071da66f75SEd Tanous { 1608e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 160948e4639eSJason M. Bills static std::unique_ptr<sdbusplus::bus::match::match> onDemandLogMatcher; 16101da66f75SEd Tanous 161148e4639eSJason M. Bills // Only allow one OnDemand Log request at a time 161248e4639eSJason M. Bills if (onDemandLogMatcher != nullptr) 16131da66f75SEd Tanous { 1614e1f26343SJason M. Bills asyncResp->res.addHeader("Retry-After", "30"); 1615f12894f8SJason M. Bills messages::serviceTemporarilyUnavailable(asyncResp->res, "30"); 16161da66f75SEd Tanous return; 16171da66f75SEd Tanous } 16181da66f75SEd Tanous // Make this static so it survives outside this method 16191da66f75SEd Tanous static boost::asio::deadline_timer timeout(*req.ioService); 16201da66f75SEd Tanous 16211da66f75SEd Tanous timeout.expires_from_now(boost::posix_time::seconds(30)); 1622e1f26343SJason M. Bills timeout.async_wait([asyncResp](const boost::system::error_code &ec) { 162348e4639eSJason M. Bills onDemandLogMatcher = nullptr; 16241da66f75SEd Tanous if (ec) 16251da66f75SEd Tanous { 16261da66f75SEd Tanous // operation_aborted is expected if timer is canceled before 16271da66f75SEd Tanous // completion. 16281da66f75SEd Tanous if (ec != boost::asio::error::operation_aborted) 16291da66f75SEd Tanous { 16301da66f75SEd Tanous BMCWEB_LOG_ERROR << "Async_wait failed " << ec; 16311da66f75SEd Tanous } 16321da66f75SEd Tanous return; 16331da66f75SEd Tanous } 163448e4639eSJason M. Bills BMCWEB_LOG_ERROR << "Timed out waiting for on-demand log"; 16351da66f75SEd Tanous 1636f12894f8SJason M. Bills messages::internalError(asyncResp->res); 16371da66f75SEd Tanous }); 16381da66f75SEd Tanous 163948e4639eSJason M. Bills auto onDemandLogMatcherCallback = [asyncResp]( 16401da66f75SEd Tanous sdbusplus::message::message &m) { 164148e4639eSJason M. Bills BMCWEB_LOG_DEBUG << "OnDemand log available match fired"; 16421da66f75SEd Tanous boost::system::error_code ec; 16431da66f75SEd Tanous timeout.cancel(ec); 16441da66f75SEd Tanous if (ec) 16451da66f75SEd Tanous { 16461da66f75SEd Tanous BMCWEB_LOG_ERROR << "error canceling timer " << ec; 16471da66f75SEd Tanous } 16484ed77cd5SEd Tanous sdbusplus::message::object_path objPath; 16491da66f75SEd Tanous boost::container::flat_map< 1650abf2add6SEd Tanous std::string, boost::container::flat_map< 1651abf2add6SEd Tanous std::string, std::variant<std::string>>> 16524ed77cd5SEd Tanous interfacesAdded; 16534ed77cd5SEd Tanous m.read(objPath, interfacesAdded); 1654abf2add6SEd Tanous const std::string *log = std::get_if<std::string>( 1655424c4176SJason M. Bills &interfacesAdded[CrashdumpInterface]["Log"]); 16561da66f75SEd Tanous if (log == nullptr) 16571da66f75SEd Tanous { 1658f12894f8SJason M. Bills messages::internalError(asyncResp->res); 165948e4639eSJason M. Bills // Careful with onDemandLogMatcher. It is a unique_ptr to the 16601da66f75SEd Tanous // match object inside which this lambda is executing. Once it 16611da66f75SEd Tanous // is set to nullptr, the match object will be destroyed and the 16621da66f75SEd Tanous // lambda will lose its context, including res, so it needs to 16631da66f75SEd Tanous // be the last thing done. 166448e4639eSJason M. Bills onDemandLogMatcher = nullptr; 16651da66f75SEd Tanous return; 16661da66f75SEd Tanous } 16671da66f75SEd Tanous nlohmann::json j = nlohmann::json::parse(*log, nullptr, false); 16681da66f75SEd Tanous if (j.is_discarded()) 16691da66f75SEd Tanous { 1670f12894f8SJason M. Bills messages::internalError(asyncResp->res); 167148e4639eSJason M. Bills // Careful with onDemandLogMatcher. It is a unique_ptr to the 16721da66f75SEd Tanous // match object inside which this lambda is executing. Once it 16731da66f75SEd Tanous // is set to nullptr, the match object will be destroyed and the 16741da66f75SEd Tanous // lambda will lose its context, including res, so it needs to 16751da66f75SEd Tanous // be the last thing done. 167648e4639eSJason M. Bills onDemandLogMatcher = nullptr; 16771da66f75SEd Tanous return; 16781da66f75SEd Tanous } 16791da66f75SEd Tanous std::string t = getLogCreatedTime(j); 1680e1f26343SJason M. Bills asyncResp->res.jsonValue = { 1681cb92c03bSAndrew Geissler {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, 16821da66f75SEd Tanous {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, 1683424c4176SJason M. Bills {"Name", "CPU Crashdump"}, 16841da66f75SEd Tanous {"EntryType", "Oem"}, 1685424c4176SJason M. Bills {"OemRecordFormat", "Intel Crashdump"}, 16861da66f75SEd Tanous {"Oem", {{"Intel", std::move(j)}}}, 16871da66f75SEd Tanous {"Created", std::move(t)}}; 168848e4639eSJason M. Bills // Careful with onDemandLogMatcher. It is a unique_ptr to the 16891da66f75SEd Tanous // match object inside which this lambda is executing. Once it is 16901da66f75SEd Tanous // set to nullptr, the match object will be destroyed and the lambda 16911da66f75SEd Tanous // will lose its context, including res, so it needs to be the last 16921da66f75SEd Tanous // thing done. 169348e4639eSJason M. Bills onDemandLogMatcher = nullptr; 16941da66f75SEd Tanous }; 169548e4639eSJason M. Bills onDemandLogMatcher = std::make_unique<sdbusplus::bus::match::match>( 16961da66f75SEd Tanous *crow::connections::systemBus, 16971da66f75SEd Tanous sdbusplus::bus::match::rules::interfacesAdded() + 1698424c4176SJason M. Bills sdbusplus::bus::match::rules::argNpath(0, 1699424c4176SJason M. Bills CrashdumpOnDemandPath), 170048e4639eSJason M. Bills std::move(onDemandLogMatcherCallback)); 17011da66f75SEd Tanous 170248e4639eSJason M. Bills auto generateonDemandLogCallback = 1703e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 17041da66f75SEd Tanous const std::string &resp) { 17051da66f75SEd Tanous if (ec) 17061da66f75SEd Tanous { 17071da66f75SEd Tanous if (ec.value() == 17081da66f75SEd Tanous boost::system::errc::operation_not_supported) 17091da66f75SEd Tanous { 1710f12894f8SJason M. Bills messages::resourceInStandby(asyncResp->res); 17111da66f75SEd Tanous } 17121da66f75SEd Tanous else 17131da66f75SEd Tanous { 1714f12894f8SJason M. Bills messages::internalError(asyncResp->res); 17151da66f75SEd Tanous } 17161da66f75SEd Tanous boost::system::error_code timeoutec; 17171da66f75SEd Tanous timeout.cancel(timeoutec); 17181da66f75SEd Tanous if (timeoutec) 17191da66f75SEd Tanous { 17201da66f75SEd Tanous BMCWEB_LOG_ERROR << "error canceling timer " 17211da66f75SEd Tanous << timeoutec; 17221da66f75SEd Tanous } 172348e4639eSJason M. Bills onDemandLogMatcher = nullptr; 17241da66f75SEd Tanous return; 17251da66f75SEd Tanous } 17261da66f75SEd Tanous }; 17271da66f75SEd Tanous crow::connections::systemBus->async_method_call( 1728424c4176SJason M. Bills std::move(generateonDemandLogCallback), CrashdumpObject, 1729424c4176SJason M. Bills CrashdumpPath, CrashdumpOnDemandInterface, "GenerateOnDemandLog"); 17301da66f75SEd Tanous } 17311da66f75SEd Tanous }; 17321da66f75SEd Tanous 1733e1f26343SJason M. Bills class SendRawPECI : public Node 17341da66f75SEd Tanous { 17351da66f75SEd Tanous public: 1736e1f26343SJason M. Bills SendRawPECI(CrowApp &app) : 1737424c4176SJason M. Bills Node(app, 1738424c4176SJason M. Bills "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/" 1739424c4176SJason M. Bills "Crashdump.SendRawPeci/") 17401da66f75SEd Tanous { 17411da66f75SEd Tanous entityPrivileges = { 17421da66f75SEd Tanous {boost::beast::http::verb::get, {{"ConfigureComponents"}}}, 17431da66f75SEd Tanous {boost::beast::http::verb::head, {{"ConfigureComponents"}}}, 17441da66f75SEd Tanous {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, 17451da66f75SEd Tanous {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, 17461da66f75SEd Tanous {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, 17471da66f75SEd Tanous {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; 17481da66f75SEd Tanous } 17491da66f75SEd Tanous 17501da66f75SEd Tanous private: 17511da66f75SEd Tanous void doPost(crow::Response &res, const crow::Request &req, 17521da66f75SEd Tanous const std::vector<std::string> ¶ms) override 17531da66f75SEd Tanous { 1754e1f26343SJason M. Bills std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); 1755b1556427SEd Tanous uint8_t clientAddress = 0; 1756b1556427SEd Tanous uint8_t readLength = 0; 17571da66f75SEd Tanous std::vector<uint8_t> peciCommand; 1758b1556427SEd Tanous if (!json_util::readJson(req, res, "ClientAddress", clientAddress, 1759b1556427SEd Tanous "ReadLength", readLength, "PECICommand", 1760b1556427SEd Tanous peciCommand)) 17611da66f75SEd Tanous { 17621da66f75SEd Tanous return; 17631da66f75SEd Tanous } 1764b1556427SEd Tanous 17651da66f75SEd Tanous // Callback to return the Raw PECI response 1766e1f26343SJason M. Bills auto sendRawPECICallback = 1767e1f26343SJason M. Bills [asyncResp](const boost::system::error_code ec, 17681da66f75SEd Tanous const std::vector<uint8_t> &resp) { 17691da66f75SEd Tanous if (ec) 17701da66f75SEd Tanous { 17711da66f75SEd Tanous BMCWEB_LOG_DEBUG << "failed to send PECI command ec: " 17721da66f75SEd Tanous << ec.message(); 1773f12894f8SJason M. Bills messages::internalError(asyncResp->res); 17741da66f75SEd Tanous return; 17751da66f75SEd Tanous } 1776e1f26343SJason M. Bills asyncResp->res.jsonValue = {{"Name", "PECI Command Response"}, 17771da66f75SEd Tanous {"PECIResponse", resp}}; 17781da66f75SEd Tanous }; 17791da66f75SEd Tanous // Call the SendRawPECI command with the provided data 17801da66f75SEd Tanous crow::connections::systemBus->async_method_call( 1781424c4176SJason M. Bills std::move(sendRawPECICallback), CrashdumpObject, CrashdumpPath, 1782424c4176SJason M. Bills CrashdumpRawPECIInterface, "SendRawPeci", clientAddress, readLength, 17834ed77cd5SEd Tanous peciCommand); 17841da66f75SEd Tanous } 17851da66f75SEd Tanous }; 17861da66f75SEd Tanous 1787cb92c03bSAndrew Geissler /** 1788cb92c03bSAndrew Geissler * DBusLogServiceActionsClear class supports POST method for ClearLog action. 1789cb92c03bSAndrew Geissler */ 1790cb92c03bSAndrew Geissler class DBusLogServiceActionsClear : public Node 1791cb92c03bSAndrew Geissler { 1792cb92c03bSAndrew Geissler public: 1793cb92c03bSAndrew Geissler DBusLogServiceActionsClear(CrowApp &app) : 1794cb92c03bSAndrew Geissler Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/" 1795cb92c03bSAndrew Geissler "LogService.Reset") 1796cb92c03bSAndrew Geissler { 1797cb92c03bSAndrew Geissler entityPrivileges = { 1798cb92c03bSAndrew Geissler {boost::beast::http::verb::get, {{"Login"}}}, 1799cb92c03bSAndrew Geissler {boost::beast::http::verb::head, {{"Login"}}}, 1800cb92c03bSAndrew Geissler {boost::beast::http::verb::patch, {{"ConfigureManager"}}}, 1801cb92c03bSAndrew Geissler {boost::beast::http::verb::put, {{"ConfigureManager"}}}, 1802cb92c03bSAndrew Geissler {boost::beast::http::verb::delete_, {{"ConfigureManager"}}}, 1803cb92c03bSAndrew Geissler {boost::beast::http::verb::post, {{"ConfigureManager"}}}}; 1804cb92c03bSAndrew Geissler } 1805cb92c03bSAndrew Geissler 1806cb92c03bSAndrew Geissler private: 1807cb92c03bSAndrew Geissler /** 1808cb92c03bSAndrew Geissler * Function handles POST method request. 1809cb92c03bSAndrew Geissler * The Clear Log actions does not require any parameter.The action deletes 1810cb92c03bSAndrew Geissler * all entries found in the Entries collection for this Log Service. 1811cb92c03bSAndrew Geissler */ 1812cb92c03bSAndrew Geissler void doPost(crow::Response &res, const crow::Request &req, 1813cb92c03bSAndrew Geissler const std::vector<std::string> ¶ms) override 1814cb92c03bSAndrew Geissler { 1815cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "Do delete all entries."; 1816cb92c03bSAndrew Geissler 1817cb92c03bSAndrew Geissler auto asyncResp = std::make_shared<AsyncResp>(res); 1818cb92c03bSAndrew Geissler // Process response from Logging service. 1819cb92c03bSAndrew Geissler auto resp_handler = [asyncResp](const boost::system::error_code ec) { 1820cb92c03bSAndrew Geissler BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done"; 1821cb92c03bSAndrew Geissler if (ec) 1822cb92c03bSAndrew Geissler { 1823cb92c03bSAndrew Geissler // TODO Handle for specific error code 1824cb92c03bSAndrew Geissler BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec; 1825cb92c03bSAndrew Geissler asyncResp->res.result( 1826cb92c03bSAndrew Geissler boost::beast::http::status::internal_server_error); 1827cb92c03bSAndrew Geissler return; 1828cb92c03bSAndrew Geissler } 1829cb92c03bSAndrew Geissler 1830cb92c03bSAndrew Geissler asyncResp->res.result(boost::beast::http::status::no_content); 1831cb92c03bSAndrew Geissler }; 1832cb92c03bSAndrew Geissler 1833cb92c03bSAndrew Geissler // Make call to Logging service to request Clear Log 1834cb92c03bSAndrew Geissler crow::connections::systemBus->async_method_call( 1835cb92c03bSAndrew Geissler resp_handler, "xyz.openbmc_project.Logging", 1836cb92c03bSAndrew Geissler "/xyz/openbmc_project/logging", 1837cb92c03bSAndrew Geissler "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll"); 1838cb92c03bSAndrew Geissler } 1839cb92c03bSAndrew Geissler }; 18401da66f75SEd Tanous } // namespace redfish 1841