blob: 8464d06f2d66c10efd7b94c8f8a9027514e4e0f3 [file] [log] [blame]
Ed Tanous1da66f72018-07-27 16:13:37 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
18#include "node.hpp"
Jason M. Bills4851d452019-03-28 11:27:48 -070019#include "registries.hpp"
20#include "registries/base_message_registry.hpp"
21#include "registries/openbmc_message_registry.hpp"
James Feist46229572020-02-19 15:11:58 -080022#include "task.hpp"
Ed Tanous1da66f72018-07-27 16:13:37 -070023
Jason M. Billse1f26342018-07-18 12:12:00 -070024#include <systemd/sd-journal.h>
Adriana Kobylak400fd1f2021-01-29 09:01:30 -060025#include <unistd.h>
Jason M. Billse1f26342018-07-18 12:12:00 -070026
Adriana Kobylak400fd1f2021-01-29 09:01:30 -060027#include <boost/algorithm/string/replace.hpp>
Jason M. Bills4851d452019-03-28 11:27:48 -070028#include <boost/algorithm/string/split.hpp>
29#include <boost/beast/core/span.hpp>
Adriana Kobylak400fd1f2021-01-29 09:01:30 -060030#include <boost/beast/http.hpp>
Ed Tanous1da66f72018-07-27 16:13:37 -070031#include <boost/container/flat_map.hpp>
Jason M. Bills1ddcf012019-11-26 14:59:21 -080032#include <boost/system/linux_error.hpp>
Andrew Geisslercb92c032018-08-17 07:56:14 -070033#include <error_messages.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050034
James Feist4418c7f2019-04-15 11:09:15 -070035#include <filesystem>
Xiaochao Ma75710de2021-01-21 17:56:02 +080036#include <optional>
Jason M. Billscd225da2019-05-08 15:31:57 -070037#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080038#include <variant>
Ed Tanous1da66f72018-07-27 16:13:37 -070039
40namespace redfish
41{
42
Gunnar Mills1214b7e2020-06-04 10:11:30 -050043constexpr char const* crashdumpObject = "com.intel.crashdump";
44constexpr char const* crashdumpPath = "/com/intel/crashdump";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050045constexpr char const* crashdumpInterface = "com.intel.crashdump";
46constexpr char const* deleteAllInterface =
Jason M. Bills5b61b5e2019-10-16 10:59:02 -070047 "xyz.openbmc_project.Collection.DeleteAll";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050048constexpr char const* crashdumpOnDemandInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070049 "com.intel.crashdump.OnDemand";
Kenny L. Ku6eda7682020-06-19 09:48:36 -070050constexpr char const* crashdumpTelemetryInterface =
51 "com.intel.crashdump.Telemetry";
Ed Tanous1da66f72018-07-27 16:13:37 -070052
Jason M. Bills4851d452019-03-28 11:27:48 -070053namespace message_registries
54{
Gunnar Mills1214b7e2020-06-04 10:11:30 -050055static const Message* getMessageFromRegistry(
56 const std::string& messageKey,
Jason M. Bills4851d452019-03-28 11:27:48 -070057 const boost::beast::span<const MessageEntry> registry)
58{
59 boost::beast::span<const MessageEntry>::const_iterator messageIt =
60 std::find_if(registry.cbegin(), registry.cend(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -050061 [&messageKey](const MessageEntry& messageEntry) {
Jason M. Bills4851d452019-03-28 11:27:48 -070062 return !std::strcmp(messageEntry.first,
63 messageKey.c_str());
64 });
65 if (messageIt != registry.cend())
66 {
67 return &messageIt->second;
68 }
69
70 return nullptr;
71}
72
Gunnar Mills1214b7e2020-06-04 10:11:30 -050073static const Message* getMessage(const std::string_view& messageID)
Jason M. Bills4851d452019-03-28 11:27:48 -070074{
75 // Redfish MessageIds are in the form
76 // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
77 // the right Message
78 std::vector<std::string> fields;
79 fields.reserve(4);
80 boost::split(fields, messageID, boost::is_any_of("."));
Gunnar Mills1214b7e2020-06-04 10:11:30 -050081 std::string& registryName = fields[0];
82 std::string& messageKey = fields[3];
Jason M. Bills4851d452019-03-28 11:27:48 -070083
84 // Find the right registry and check it for the MessageKey
85 if (std::string(base::header.registryPrefix) == registryName)
86 {
87 return getMessageFromRegistry(
88 messageKey, boost::beast::span<const MessageEntry>(base::registry));
89 }
90 if (std::string(openbmc::header.registryPrefix) == registryName)
91 {
92 return getMessageFromRegistry(
93 messageKey,
94 boost::beast::span<const MessageEntry>(openbmc::registry));
95 }
96 return nullptr;
97}
98} // namespace message_registries
99
James Feistf6150402019-01-08 10:36:20 -0800100namespace fs = std::filesystem;
Ed Tanous1da66f72018-07-27 16:13:37 -0700101
Andrew Geisslercb92c032018-08-17 07:56:14 -0700102using GetManagedPropertyType = boost::container::flat_map<
Patrick Williams19bd78d2020-05-13 17:38:24 -0500103 std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t,
104 int32_t, uint32_t, int64_t, uint64_t, double>>;
Andrew Geisslercb92c032018-08-17 07:56:14 -0700105
106using GetManagedObjectsType = boost::container::flat_map<
107 sdbusplus::message::object_path,
108 boost::container::flat_map<std::string, GetManagedPropertyType>>;
109
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500110inline std::string translateSeverityDbusToRedfish(const std::string& s)
Andrew Geisslercb92c032018-08-17 07:56:14 -0700111{
Ed Tanousd4d25792020-09-29 15:15:03 -0700112 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
113 (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
114 (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
115 (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
Andrew Geisslercb92c032018-08-17 07:56:14 -0700116 {
117 return "Critical";
118 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700119 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
120 (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
121 (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
Andrew Geisslercb92c032018-08-17 07:56:14 -0700122 {
123 return "OK";
124 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700125 if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
Andrew Geisslercb92c032018-08-17 07:56:14 -0700126 {
127 return "Warning";
128 }
129 return "";
130}
131
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500132static int getJournalMetadata(sd_journal* journal,
133 const std::string_view& field,
134 std::string_view& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700135{
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500136 const char* data = nullptr;
Jason M. Bills16428a12018-11-02 12:42:29 -0700137 size_t length = 0;
138 int ret = 0;
139 // Get the metadata from the requested field of the journal entry
Ed Tanous271584a2019-07-09 16:24:22 -0700140 ret = sd_journal_get_data(journal, field.data(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500141 reinterpret_cast<const void**>(&data), &length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700142 if (ret < 0)
143 {
144 return ret;
145 }
Ed Tanous39e77502019-03-04 17:35:53 -0800146 contents = std::string_view(data, length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700147 // Only use the content after the "=" character.
Ed Tanous81ce6092020-12-17 16:54:55 +0000148 contents.remove_prefix(std::min(contents.find('=') + 1, contents.size()));
Jason M. Bills16428a12018-11-02 12:42:29 -0700149 return ret;
150}
151
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500152static int getJournalMetadata(sd_journal* journal,
153 const std::string_view& field, const int& base,
154 long int& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700155{
156 int ret = 0;
Ed Tanous39e77502019-03-04 17:35:53 -0800157 std::string_view metadata;
Jason M. Bills16428a12018-11-02 12:42:29 -0700158 // Get the metadata from the requested field of the journal entry
159 ret = getJournalMetadata(journal, field, metadata);
160 if (ret < 0)
161 {
162 return ret;
163 }
Ed Tanousb01bf292019-03-25 19:25:26 +0000164 contents = strtol(metadata.data(), nullptr, base);
Jason M. Bills16428a12018-11-02 12:42:29 -0700165 return ret;
166}
167
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500168static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800169{
170 int ret = 0;
171 uint64_t timestamp = 0;
172 ret = sd_journal_get_realtime_usec(journal, &timestamp);
173 if (ret < 0)
174 {
175 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
176 << strerror(-ret);
177 return false;
178 }
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -0500179 entryTimestamp = crow::utility::getDateTime(
180 static_cast<std::time_t>(timestamp / 1000 / 1000));
181 return true;
ZhikuiRena3316fc2020-01-29 14:58:08 -0800182}
183
zhanghch058d1b46d2021-04-01 11:18:24 +0800184static bool getSkipParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
185 const crow::Request& req, uint64_t& skip)
Jason M. Bills16428a12018-11-02 12:42:29 -0700186{
James Feist5a7e8772020-07-22 09:08:38 -0700187 boost::urls::url_view::params_type::iterator it =
188 req.urlParams.find("$skip");
189 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700190 {
James Feist5a7e8772020-07-22 09:08:38 -0700191 std::string skipParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500192 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700193 skip = std::strtoul(skipParam.c_str(), &ptr, 10);
194 if (skipParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700195 {
196
zhanghch058d1b46d2021-04-01 11:18:24 +0800197 messages::queryParameterValueTypeError(
198 asyncResp->res, std::string(skipParam), "$skip");
Jason M. Bills16428a12018-11-02 12:42:29 -0700199 return false;
200 }
Jason M. Bills16428a12018-11-02 12:42:29 -0700201 }
202 return true;
203}
204
Ed Tanous271584a2019-07-09 16:24:22 -0700205static constexpr const uint64_t maxEntriesPerPage = 1000;
zhanghch058d1b46d2021-04-01 11:18:24 +0800206static bool getTopParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
207 const crow::Request& req, uint64_t& top)
Jason M. Bills16428a12018-11-02 12:42:29 -0700208{
James Feist5a7e8772020-07-22 09:08:38 -0700209 boost::urls::url_view::params_type::iterator it =
210 req.urlParams.find("$top");
211 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700212 {
James Feist5a7e8772020-07-22 09:08:38 -0700213 std::string topParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500214 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700215 top = std::strtoul(topParam.c_str(), &ptr, 10);
216 if (topParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700217 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800218 messages::queryParameterValueTypeError(
219 asyncResp->res, std::string(topParam), "$top");
Jason M. Bills16428a12018-11-02 12:42:29 -0700220 return false;
221 }
Ed Tanous271584a2019-07-09 16:24:22 -0700222 if (top < 1U || top > maxEntriesPerPage)
Jason M. Bills16428a12018-11-02 12:42:29 -0700223 {
224
225 messages::queryParameterOutOfRange(
zhanghch058d1b46d2021-04-01 11:18:24 +0800226 asyncResp->res, std::to_string(top), "$top",
Jason M. Bills16428a12018-11-02 12:42:29 -0700227 "1-" + std::to_string(maxEntriesPerPage));
228 return false;
229 }
230 }
231 return true;
232}
233
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500234static bool getUniqueEntryID(sd_journal* journal, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700235 const bool firstEntry = true)
Jason M. Bills16428a12018-11-02 12:42:29 -0700236{
237 int ret = 0;
238 static uint64_t prevTs = 0;
239 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700240 if (firstEntry)
241 {
242 prevTs = 0;
243 }
244
Jason M. Bills16428a12018-11-02 12:42:29 -0700245 // Get the entry timestamp
246 uint64_t curTs = 0;
247 ret = sd_journal_get_realtime_usec(journal, &curTs);
248 if (ret < 0)
249 {
250 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
251 << strerror(-ret);
252 return false;
253 }
254 // If the timestamp isn't unique, increment the index
255 if (curTs == prevTs)
256 {
257 index++;
258 }
259 else
260 {
261 // Otherwise, reset it
262 index = 0;
263 }
264 // Save the timestamp
265 prevTs = curTs;
266
267 entryID = std::to_string(curTs);
268 if (index > 0)
269 {
270 entryID += "_" + std::to_string(index);
271 }
272 return true;
273}
274
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500275static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700276 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700277{
Ed Tanous271584a2019-07-09 16:24:22 -0700278 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700279 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700280 if (firstEntry)
281 {
282 prevTs = 0;
283 }
284
Jason M. Bills95820182019-04-22 16:25:34 -0700285 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700286 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700287 std::tm timeStruct = {};
288 std::istringstream entryStream(logEntry);
289 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
290 {
291 curTs = std::mktime(&timeStruct);
292 }
293 // If the timestamp isn't unique, increment the index
294 if (curTs == prevTs)
295 {
296 index++;
297 }
298 else
299 {
300 // Otherwise, reset it
301 index = 0;
302 }
303 // Save the timestamp
304 prevTs = curTs;
305
306 entryID = std::to_string(curTs);
307 if (index > 0)
308 {
309 entryID += "_" + std::to_string(index);
310 }
311 return true;
312}
313
zhanghch058d1b46d2021-04-01 11:18:24 +0800314static bool
315 getTimestampFromID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
316 const std::string& entryID, uint64_t& timestamp,
317 uint64_t& index)
Jason M. Bills16428a12018-11-02 12:42:29 -0700318{
319 if (entryID.empty())
320 {
321 return false;
322 }
323 // Convert the unique ID back to a timestamp to find the entry
Ed Tanous39e77502019-03-04 17:35:53 -0800324 std::string_view tsStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700325
Ed Tanous81ce6092020-12-17 16:54:55 +0000326 auto underscorePos = tsStr.find('_');
Jason M. Bills16428a12018-11-02 12:42:29 -0700327 if (underscorePos != tsStr.npos)
328 {
329 // Timestamp has an index
330 tsStr.remove_suffix(tsStr.size() - underscorePos);
Ed Tanous39e77502019-03-04 17:35:53 -0800331 std::string_view indexStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700332 indexStr.remove_prefix(underscorePos + 1);
333 std::size_t pos;
334 try
335 {
Ed Tanous39e77502019-03-04 17:35:53 -0800336 index = std::stoul(std::string(indexStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700337 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500338 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700339 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800340 messages::resourceMissingAtURI(asyncResp->res, entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700341 return false;
342 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500343 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700344 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800345 messages::resourceMissingAtURI(asyncResp->res, entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700346 return false;
347 }
348 if (pos != indexStr.size())
349 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800350 messages::resourceMissingAtURI(asyncResp->res, entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700351 return false;
352 }
353 }
354 // Timestamp has no index
355 std::size_t pos;
356 try
357 {
Ed Tanous39e77502019-03-04 17:35:53 -0800358 timestamp = std::stoull(std::string(tsStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700359 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500360 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700361 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800362 messages::resourceMissingAtURI(asyncResp->res, entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700363 return false;
364 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500365 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700366 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800367 messages::resourceMissingAtURI(asyncResp->res, entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700368 return false;
369 }
370 if (pos != tsStr.size())
371 {
zhanghch058d1b46d2021-04-01 11:18:24 +0800372 messages::resourceMissingAtURI(asyncResp->res, entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700373 return false;
374 }
375 return true;
376}
377
Jason M. Bills95820182019-04-22 16:25:34 -0700378static bool
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500379 getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700380{
381 static const std::filesystem::path redfishLogDir = "/var/log";
382 static const std::string redfishLogFilename = "redfish";
383
384 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500385 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700386 std::filesystem::directory_iterator(redfishLogDir))
387 {
388 // If we find a redfish log file, save the path
389 std::string filename = dirEnt.path().filename();
390 if (boost::starts_with(filename, redfishLogFilename))
391 {
392 redfishLogFiles.emplace_back(redfishLogDir / filename);
393 }
394 }
395 // As the log files rotate, they are appended with a ".#" that is higher for
396 // the older logs. Since we don't expect more than 10 log files, we
397 // can just sort the list to get them in order from newest to oldest
398 std::sort(redfishLogFiles.begin(), redfishLogFiles.end());
399
400 return !redfishLogFiles.empty();
401}
402
zhanghch058d1b46d2021-04-01 11:18:24 +0800403inline void
404 getDumpEntryCollection(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
405 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500406{
407 std::string dumpPath;
408 if (dumpType == "BMC")
409 {
410 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
411 }
412 else if (dumpType == "System")
413 {
414 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
415 }
416 else
417 {
418 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
419 messages::internalError(asyncResp->res);
420 return;
421 }
422
423 crow::connections::systemBus->async_method_call(
424 [asyncResp, dumpPath, dumpType](const boost::system::error_code ec,
425 GetManagedObjectsType& resp) {
426 if (ec)
427 {
428 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
429 messages::internalError(asyncResp->res);
430 return;
431 }
432
433 nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
434 entriesArray = nlohmann::json::array();
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500435 std::string dumpEntryPath =
436 "/xyz/openbmc_project/dump/" +
437 std::string(boost::algorithm::to_lower_copy(dumpType)) +
438 "/entry/";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500439
440 for (auto& object : resp)
441 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500442 if (object.first.str.find(dumpEntryPath) == std::string::npos)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500443 {
444 continue;
445 }
446 std::time_t timestamp;
447 uint64_t size = 0;
448 entriesArray.push_back({});
449 nlohmann::json& thisEntry = entriesArray.back();
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000450
451 std::string entryID = object.first.filename();
452 if (entryID.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500453 {
454 continue;
455 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500456
457 for (auto& interfaceMap : object.second)
458 {
459 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
460 {
461
462 for (auto& propertyMap : interfaceMap.second)
463 {
464 if (propertyMap.first == "Size")
465 {
466 auto sizePtr =
467 std::get_if<uint64_t>(&propertyMap.second);
468 if (sizePtr == nullptr)
469 {
470 messages::internalError(asyncResp->res);
471 break;
472 }
473 size = *sizePtr;
474 break;
475 }
476 }
477 }
478 else if (interfaceMap.first ==
479 "xyz.openbmc_project.Time.EpochTime")
480 {
481
482 for (auto& propertyMap : interfaceMap.second)
483 {
484 if (propertyMap.first == "Elapsed")
485 {
486 const uint64_t* usecsTimeStamp =
487 std::get_if<uint64_t>(&propertyMap.second);
488 if (usecsTimeStamp == nullptr)
489 {
490 messages::internalError(asyncResp->res);
491 break;
492 }
493 timestamp =
494 static_cast<std::time_t>(*usecsTimeStamp);
495 break;
496 }
497 }
498 }
499 }
500
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500501 thisEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500502 thisEntry["@odata.id"] = dumpPath + entryID;
503 thisEntry["Id"] = entryID;
504 thisEntry["EntryType"] = "Event";
505 thisEntry["Created"] = crow::utility::getDateTime(timestamp);
506 thisEntry["Name"] = dumpType + " Dump Entry";
507
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500508 thisEntry["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500509
510 if (dumpType == "BMC")
511 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500512 thisEntry["DiagnosticDataType"] = "Manager";
513 thisEntry["AdditionalDataURI"] =
514 "/redfish/v1/Managers/bmc/LogServices/Dump/"
515 "attachment/" +
516 entryID;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500517 }
518 else if (dumpType == "System")
519 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500520 thisEntry["DiagnosticDataType"] = "OEM";
521 thisEntry["OEMDiagnosticDataType"] = "System";
522 thisEntry["AdditionalDataURI"] =
523 "/redfish/v1/Systems/system/LogServices/Dump/"
524 "attachment/" +
525 entryID;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500526 }
527 }
528 asyncResp->res.jsonValue["Members@odata.count"] =
529 entriesArray.size();
530 },
531 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
532 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
533}
534
zhanghch058d1b46d2021-04-01 11:18:24 +0800535inline void
536 getDumpEntryById(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
537 const std::string& entryID, const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500538{
539 std::string dumpPath;
540 if (dumpType == "BMC")
541 {
542 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
543 }
544 else if (dumpType == "System")
545 {
546 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
547 }
548 else
549 {
550 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
551 messages::internalError(asyncResp->res);
552 return;
553 }
554
555 crow::connections::systemBus->async_method_call(
556 [asyncResp, entryID, dumpPath, dumpType](
557 const boost::system::error_code ec, GetManagedObjectsType& resp) {
558 if (ec)
559 {
560 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
561 messages::internalError(asyncResp->res);
562 return;
563 }
564
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500565 bool foundDumpEntry = false;
566 std::string dumpEntryPath =
567 "/xyz/openbmc_project/dump/" +
568 std::string(boost::algorithm::to_lower_copy(dumpType)) +
569 "/entry/";
570
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500571 for (auto& objectPath : resp)
572 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500573 if (objectPath.first.str != dumpEntryPath + entryID)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500574 {
575 continue;
576 }
577
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500578 foundDumpEntry = true;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500579 std::time_t timestamp;
580 uint64_t size = 0;
581
582 for (auto& interfaceMap : objectPath.second)
583 {
584 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
585 {
586 for (auto& propertyMap : interfaceMap.second)
587 {
588 if (propertyMap.first == "Size")
589 {
590 auto sizePtr =
591 std::get_if<uint64_t>(&propertyMap.second);
592 if (sizePtr == nullptr)
593 {
594 messages::internalError(asyncResp->res);
595 break;
596 }
597 size = *sizePtr;
598 break;
599 }
600 }
601 }
602 else if (interfaceMap.first ==
603 "xyz.openbmc_project.Time.EpochTime")
604 {
605 for (auto& propertyMap : interfaceMap.second)
606 {
607 if (propertyMap.first == "Elapsed")
608 {
609 const uint64_t* usecsTimeStamp =
610 std::get_if<uint64_t>(&propertyMap.second);
611 if (usecsTimeStamp == nullptr)
612 {
613 messages::internalError(asyncResp->res);
614 break;
615 }
616 timestamp =
617 static_cast<std::time_t>(*usecsTimeStamp);
618 break;
619 }
620 }
621 }
622 }
623
624 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500625 "#LogEntry.v1_7_0.LogEntry";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500626 asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID;
627 asyncResp->res.jsonValue["Id"] = entryID;
628 asyncResp->res.jsonValue["EntryType"] = "Event";
629 asyncResp->res.jsonValue["Created"] =
630 crow::utility::getDateTime(timestamp);
631 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
632
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500633 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500634
635 if (dumpType == "BMC")
636 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500637 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
638 asyncResp->res.jsonValue["AdditionalDataURI"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500639 "/redfish/v1/Managers/bmc/LogServices/Dump/"
640 "attachment/" +
641 entryID;
642 }
643 else if (dumpType == "System")
644 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500645 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
646 asyncResp->res.jsonValue["OEMDiagnosticDataType"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500647 "System";
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500648 asyncResp->res.jsonValue["AdditionalDataURI"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500649 "/redfish/v1/Systems/system/LogServices/Dump/"
650 "attachment/" +
651 entryID;
652 }
653 }
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500654 if (foundDumpEntry == false)
655 {
656 BMCWEB_LOG_ERROR << "Can't find Dump Entry";
657 messages::internalError(asyncResp->res);
658 return;
659 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500660 },
661 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
662 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
663}
664
zhanghch058d1b46d2021-04-01 11:18:24 +0800665inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
Stanley Chu98782562020-11-04 16:10:24 +0800666 const std::string& entryID,
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500667 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500668{
George Liu3de8d8b2021-03-22 17:49:39 +0800669 auto respHandler = [asyncResp,
670 entryID](const boost::system::error_code ec) {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500671 BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
672 if (ec)
673 {
George Liu3de8d8b2021-03-22 17:49:39 +0800674 if (ec.value() == EBADR)
675 {
676 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
677 return;
678 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500679 BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
680 << ec;
681 messages::internalError(asyncResp->res);
682 return;
683 }
684 };
685 crow::connections::systemBus->async_method_call(
686 respHandler, "xyz.openbmc_project.Dump.Manager",
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500687 "/xyz/openbmc_project/dump/" +
688 std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" +
689 entryID,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500690 "xyz.openbmc_project.Object.Delete", "Delete");
691}
692
zhanghch058d1b46d2021-04-01 11:18:24 +0800693inline void
694 createDumpTaskCallback(const crow::Request& req,
695 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
696 const uint32_t& dumpId, const std::string& dumpPath,
697 const std::string& dumpType)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500698{
699 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500700 [dumpId, dumpPath, dumpType](
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500701 boost::system::error_code err, sdbusplus::message::message& m,
702 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000703 if (err)
704 {
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500705 BMCWEB_LOG_ERROR << "Error in creating a dump";
706 taskData->state = "Cancelled";
707 return task::completed;
Ed Tanouscb13a392020-07-25 19:02:03 +0000708 }
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500709 std::vector<std::pair<
710 std::string,
711 std::vector<std::pair<std::string, std::variant<std::string>>>>>
712 interfacesList;
713
714 sdbusplus::message::object_path objPath;
715
716 m.read(objPath, interfacesList);
717
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500718 if (objPath.str ==
719 "/xyz/openbmc_project/dump/" +
720 std::string(boost::algorithm::to_lower_copy(dumpType)) +
721 "/entry/" + std::to_string(dumpId))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500722 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500723 nlohmann::json retMessage = messages::success();
724 taskData->messages.emplace_back(retMessage);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500725
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500726 std::string headerLoc =
727 "Location: " + dumpPath + std::to_string(dumpId);
728 taskData->payload->httpHeaders.emplace_back(
729 std::move(headerLoc));
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500730
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500731 taskData->state = "Completed";
732 return task::completed;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500733 }
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500734 return task::completed;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500735 },
736 "type='signal',interface='org.freedesktop.DBus."
737 "ObjectManager',"
738 "member='InterfacesAdded', "
739 "path='/xyz/openbmc_project/dump'");
740
741 task->startTimer(std::chrono::minutes(3));
742 task->populateResp(asyncResp->res);
743 task->payload.emplace(req);
744}
745
zhanghch058d1b46d2021-04-01 11:18:24 +0800746inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
747 const crow::Request& req, const std::string& dumpType)
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500748{
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500749
750 std::string dumpPath;
751 if (dumpType == "BMC")
752 {
753 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
754 }
755 else if (dumpType == "System")
756 {
757 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
758 }
759 else
760 {
761 BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
762 messages::internalError(asyncResp->res);
763 return;
764 }
765
766 std::optional<std::string> diagnosticDataType;
767 std::optional<std::string> oemDiagnosticDataType;
768
769 if (!redfish::json_util::readJson(
770 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
771 "OEMDiagnosticDataType", oemDiagnosticDataType))
772 {
773 return;
774 }
775
776 if (dumpType == "System")
777 {
778 if (!oemDiagnosticDataType || !diagnosticDataType)
779 {
780 BMCWEB_LOG_ERROR << "CreateDump action parameter "
781 "'DiagnosticDataType'/"
782 "'OEMDiagnosticDataType' value not found!";
783 messages::actionParameterMissing(
784 asyncResp->res, "CollectDiagnosticData",
785 "DiagnosticDataType & OEMDiagnosticDataType");
786 return;
787 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700788 if ((*oemDiagnosticDataType != "System") ||
789 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500790 {
791 BMCWEB_LOG_ERROR << "Wrong parameter values passed";
792 messages::invalidObject(asyncResp->res,
793 "System Dump creation parameters");
794 return;
795 }
796 }
797 else if (dumpType == "BMC")
798 {
799 if (!diagnosticDataType)
800 {
801 BMCWEB_LOG_ERROR << "CreateDump action parameter "
802 "'DiagnosticDataType' not found!";
803 messages::actionParameterMissing(
804 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
805 return;
806 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700807 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500808 {
809 BMCWEB_LOG_ERROR
810 << "Wrong parameter value passed for 'DiagnosticDataType'";
811 messages::invalidObject(asyncResp->res,
812 "BMC Dump creation parameters");
813 return;
814 }
815 }
816
817 crow::connections::systemBus->async_method_call(
818 [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
819 const uint32_t& dumpId) {
820 if (ec)
821 {
822 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
823 messages::internalError(asyncResp->res);
824 return;
825 }
826 BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
827
828 createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
829 },
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500830 "xyz.openbmc_project.Dump.Manager",
831 "/xyz/openbmc_project/dump/" +
832 std::string(boost::algorithm::to_lower_copy(dumpType)),
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500833 "xyz.openbmc_project.Dump.Create", "CreateDump");
834}
835
zhanghch058d1b46d2021-04-01 11:18:24 +0800836inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
837 const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500838{
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500839 std::string dumpTypeLowerCopy =
840 std::string(boost::algorithm::to_lower_copy(dumpType));
zhanghch058d1b46d2021-04-01 11:18:24 +0800841
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500842 crow::connections::systemBus->async_method_call(
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500843 [asyncResp, dumpType](const boost::system::error_code ec,
844 const std::vector<std::string>& subTreePaths) {
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500845 if (ec)
846 {
847 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
848 messages::internalError(asyncResp->res);
849 return;
850 }
851
852 for (const std::string& path : subTreePaths)
853 {
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000854 sdbusplus::message::object_path objPath(path);
855 std::string logID = objPath.filename();
856 if (logID.empty())
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500857 {
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000858 continue;
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500859 }
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000860 deleteDumpEntry(asyncResp, logID, dumpType);
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500861 }
862 },
863 "xyz.openbmc_project.ObjectMapper",
864 "/xyz/openbmc_project/object_mapper",
865 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500866 "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0,
867 std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." +
868 dumpType});
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500869}
870
Ed Tanous2c70f802020-09-28 14:29:23 -0700871static void parseCrashdumpParameters(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500872 const std::vector<std::pair<std::string, VariantType>>& params,
873 std::string& filename, std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -0700874{
875 for (auto property : params)
876 {
877 if (property.first == "Timestamp")
878 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500879 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500880 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700881 if (value != nullptr)
882 {
883 timestamp = *value;
884 }
885 }
886 else if (property.first == "Filename")
887 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500888 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500889 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700890 if (value != nullptr)
891 {
892 filename = *value;
893 }
894 }
895 else if (property.first == "Log")
896 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500897 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500898 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700899 if (value != nullptr)
900 {
901 logfile = *value;
902 }
903 }
904 }
905}
906
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500907constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800908class SystemLogServiceCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -0700909{
910 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700911 SystemLogServiceCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800912 Node(app, "/redfish/v1/Systems/system/LogServices/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800913 {
914 entityPrivileges = {
915 {boost::beast::http::verb::get, {{"Login"}}},
916 {boost::beast::http::verb::head, {{"Login"}}},
917 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
918 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
919 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
920 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
921 }
922
923 private:
924 /**
925 * Functions triggers appropriate requests on DBus
926 */
zhanghch058d1b46d2021-04-01 11:18:24 +0800927 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
928 const crow::Request&, const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800929 {
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800930 // Collections don't include the static data added by SubRoute because
931 // it has a duplicate entry for members
932 asyncResp->res.jsonValue["@odata.type"] =
933 "#LogServiceCollection.LogServiceCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800934 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800935 "/redfish/v1/Systems/system/LogServices";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800936 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
937 asyncResp->res.jsonValue["Description"] =
938 "Collection of LogServices for this Computer System";
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500939 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800940 logServiceArray = nlohmann::json::array();
Ed Tanous029573d2019-02-01 10:57:49 -0800941 logServiceArray.push_back(
942 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500943#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
raviteja-bc9bb6862020-02-03 11:53:32 -0600944 logServiceArray.push_back(
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500945 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
raviteja-bc9bb6862020-02-03 11:53:32 -0600946#endif
947
Jason M. Billsd53dd412019-02-12 17:16:22 -0800948#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
949 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -0500950 {{"@odata.id",
951 "/redfish/v1/Systems/system/LogServices/Crashdump"}});
Jason M. Billsd53dd412019-02-12 17:16:22 -0800952#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800953 asyncResp->res.jsonValue["Members@odata.count"] =
954 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800955
956 crow::connections::systemBus->async_method_call(
957 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500958 const std::vector<std::string>& subtreePath) {
ZhikuiRena3316fc2020-01-29 14:58:08 -0800959 if (ec)
960 {
961 BMCWEB_LOG_ERROR << ec;
962 return;
963 }
964
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500965 for (auto& pathStr : subtreePath)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800966 {
967 if (pathStr.find("PostCode") != std::string::npos)
968 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000969 nlohmann::json& logServiceArrayLocal =
ZhikuiRena3316fc2020-01-29 14:58:08 -0800970 asyncResp->res.jsonValue["Members"];
Ed Tanous23a21a12020-07-25 04:45:05 +0000971 logServiceArrayLocal.push_back(
ZhikuiRena3316fc2020-01-29 14:58:08 -0800972 {{"@odata.id", "/redfish/v1/Systems/system/"
973 "LogServices/PostCodes"}});
974 asyncResp->res.jsonValue["Members@odata.count"] =
Ed Tanous23a21a12020-07-25 04:45:05 +0000975 logServiceArrayLocal.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800976 return;
977 }
978 }
979 },
980 "xyz.openbmc_project.ObjectMapper",
981 "/xyz/openbmc_project/object_mapper",
982 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500983 std::array<const char*, 1>{postCodeIface});
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800984 }
985};
986
987class EventLogService : public Node
988{
989 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700990 EventLogService(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800991 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800992 {
993 entityPrivileges = {
994 {boost::beast::http::verb::get, {{"Login"}}},
995 {boost::beast::http::verb::head, {{"Login"}}},
996 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
997 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
998 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
999 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1000 }
1001
1002 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08001003 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1004 const crow::Request&, const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001005 {
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001006 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001007 "/redfish/v1/Systems/system/LogServices/EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001008 asyncResp->res.jsonValue["@odata.type"] =
1009 "#LogService.v1_1_0.LogService";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001010 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1011 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
Gunnar Mills73ec8302020-04-14 16:02:42 -05001012 asyncResp->res.jsonValue["Id"] = "EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001013 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1014 asyncResp->res.jsonValue["Entries"] = {
1015 {"@odata.id",
Ed Tanous029573d2019-02-01 10:57:49 -08001016 "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
Gunnar Millse7d6c8b2019-07-03 11:30:01 -05001017 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1018
1019 {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1020 "Actions/LogService.ClearLog"}};
Jason M. Bills489640c2019-05-17 09:56:36 -07001021 }
1022};
1023
Tim Lee1f56a3a2019-10-09 10:17:57 +08001024class JournalEventLogClear : public Node
Jason M. Bills489640c2019-05-17 09:56:36 -07001025{
1026 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001027 JournalEventLogClear(App& app) :
Jason M. Bills489640c2019-05-17 09:56:36 -07001028 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1029 "LogService.ClearLog/")
1030 {
1031 entityPrivileges = {
1032 {boost::beast::http::verb::get, {{"Login"}}},
1033 {boost::beast::http::verb::head, {{"Login"}}},
1034 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1035 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1036 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1037 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1038 }
1039
1040 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08001041 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1042 const crow::Request&, const std::vector<std::string>&) override
Jason M. Bills489640c2019-05-17 09:56:36 -07001043 {
Jason M. Bills489640c2019-05-17 09:56:36 -07001044
1045 // Clear the EventLog by deleting the log files
1046 std::vector<std::filesystem::path> redfishLogFiles;
1047 if (getRedfishLogFiles(redfishLogFiles))
1048 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001049 for (const std::filesystem::path& file : redfishLogFiles)
Jason M. Bills489640c2019-05-17 09:56:36 -07001050 {
1051 std::error_code ec;
1052 std::filesystem::remove(file, ec);
1053 }
1054 }
1055
1056 // Reload rsyslog so it knows to start new log files
1057 crow::connections::systemBus->async_method_call(
1058 [asyncResp](const boost::system::error_code ec) {
1059 if (ec)
1060 {
1061 BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1062 messages::internalError(asyncResp->res);
1063 return;
1064 }
1065
1066 messages::success(asyncResp->res);
1067 },
1068 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1069 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1070 "replace");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001071 }
1072};
1073
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001074static int fillEventLogEntryJson(const std::string& logEntryID,
Ed Tanousb5a76932020-09-29 16:16:58 -07001075 const std::string& logEntry,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001076 nlohmann::json& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001077{
Jason M. Bills95820182019-04-22 16:25:34 -07001078 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001079 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001080 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001081 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001082 {
1083 return 1;
1084 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001085 std::string timestamp = logEntry.substr(0, space);
1086 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001087 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001088 if (entryStart == std::string::npos)
1089 {
1090 return 1;
1091 }
1092 std::string_view entry(logEntry);
1093 entry.remove_prefix(entryStart);
1094 // Use split to separate the entry into its fields
1095 std::vector<std::string> logEntryFields;
1096 boost::split(logEntryFields, entry, boost::is_any_of(","),
1097 boost::token_compress_on);
1098 // We need at least a MessageId to be valid
1099 if (logEntryFields.size() < 1)
1100 {
1101 return 1;
1102 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001103 std::string& messageID = logEntryFields[0];
Jason M. Bills95820182019-04-22 16:25:34 -07001104
Jason M. Bills4851d452019-03-28 11:27:48 -07001105 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001106 const message_registries::Message* message =
Jason M. Bills4851d452019-03-28 11:27:48 -07001107 message_registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001108
Jason M. Bills4851d452019-03-28 11:27:48 -07001109 std::string msg;
1110 std::string severity;
1111 if (message != nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001112 {
Jason M. Bills4851d452019-03-28 11:27:48 -07001113 msg = message->message;
1114 severity = message->severity;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001115 }
1116
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001117 // Get the MessageArgs from the log if there are any
1118 boost::beast::span<std::string> messageArgs;
1119 if (logEntryFields.size() > 1)
Jason M. Bills4851d452019-03-28 11:27:48 -07001120 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001121 std::string& messageArgsStart = logEntryFields[1];
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001122 // If the first string is empty, assume there are no MessageArgs
1123 std::size_t messageArgsSize = 0;
1124 if (!messageArgsStart.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001125 {
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001126 messageArgsSize = logEntryFields.size() - 1;
1127 }
1128
Ed Tanous23a21a12020-07-25 04:45:05 +00001129 messageArgs = {&messageArgsStart, messageArgsSize};
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001130
1131 // Fill the MessageArgs into the Message
1132 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001133 for (const std::string& messageArg : messageArgs)
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001134 {
1135 std::string argStr = "%" + std::to_string(++i);
1136 size_t argPos = msg.find(argStr);
1137 if (argPos != std::string::npos)
1138 {
1139 msg.replace(argPos, argStr.length(), messageArg);
1140 }
Jason M. Bills4851d452019-03-28 11:27:48 -07001141 }
1142 }
1143
Jason M. Bills95820182019-04-22 16:25:34 -07001144 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1145 // format which matches the Redfish format except for the fractional seconds
1146 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001147 std::size_t dot = timestamp.find_first_of('.');
1148 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001149 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001150 {
Jason M. Bills95820182019-04-22 16:25:34 -07001151 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001152 }
1153
1154 // Fill in the log entry with the gathered data
Jason M. Bills95820182019-04-22 16:25:34 -07001155 logEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001156 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Ed Tanous029573d2019-02-01 10:57:49 -08001157 {"@odata.id",
Jason M. Bills897967d2019-07-29 17:05:30 -07001158 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
Jason M. Bills95820182019-04-22 16:25:34 -07001159 logEntryID},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001160 {"Name", "System Event Log Entry"},
Jason M. Bills95820182019-04-22 16:25:34 -07001161 {"Id", logEntryID},
1162 {"Message", std::move(msg)},
1163 {"MessageId", std::move(messageID)},
Ed Tanousf23b7292020-10-15 09:41:17 -07001164 {"MessageArgs", messageArgs},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001165 {"EntryType", "Event"},
Jason M. Bills95820182019-04-22 16:25:34 -07001166 {"Severity", std::move(severity)},
1167 {"Created", std::move(timestamp)}};
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001168 return 0;
1169}
1170
Anthony Wilson27062602019-04-22 02:10:09 -05001171class JournalEventLogEntryCollection : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001172{
1173 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001174 JournalEventLogEntryCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001175 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001176 {
1177 entityPrivileges = {
1178 {boost::beast::http::verb::get, {{"Login"}}},
1179 {boost::beast::http::verb::head, {{"Login"}}},
1180 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1181 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1182 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1183 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1184 }
1185
1186 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08001187 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1188 const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001189 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001190 {
Ed Tanous271584a2019-07-09 16:24:22 -07001191 uint64_t skip = 0;
1192 uint64_t top = maxEntriesPerPage; // Show max entries by default
zhanghch058d1b46d2021-04-01 11:18:24 +08001193 if (!getSkipParam(asyncResp, req, skip))
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001194 {
1195 return;
1196 }
zhanghch058d1b46d2021-04-01 11:18:24 +08001197 if (!getTopParam(asyncResp, req, top))
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001198 {
1199 return;
1200 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001201 // Collections don't include the static data added by SubRoute because
1202 // it has a duplicate entry for members
1203 asyncResp->res.jsonValue["@odata.type"] =
1204 "#LogEntryCollection.LogEntryCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001205 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001206 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001207 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1208 asyncResp->res.jsonValue["Description"] =
1209 "Collection of System Event Log Entries";
Andrew Geisslercb92c032018-08-17 07:56:14 -07001210
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001211 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001212 logEntryArray = nlohmann::json::array();
Jason M. Bills95820182019-04-22 16:25:34 -07001213 // Go through the log files and create a unique ID for each entry
1214 std::vector<std::filesystem::path> redfishLogFiles;
1215 getRedfishLogFiles(redfishLogFiles);
Ed Tanousb01bf292019-03-25 19:25:26 +00001216 uint64_t entryCount = 0;
Jason M. Billscd225da2019-05-08 15:31:57 -07001217 std::string logEntry;
Jason M. Bills95820182019-04-22 16:25:34 -07001218
1219 // Oldest logs are in the last file, so start there and loop backwards
Jason M. Billscd225da2019-05-08 15:31:57 -07001220 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1221 it++)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001222 {
Jason M. Billscd225da2019-05-08 15:31:57 -07001223 std::ifstream logStream(*it);
Jason M. Bills95820182019-04-22 16:25:34 -07001224 if (!logStream.is_open())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001225 {
1226 continue;
1227 }
1228
Jason M. Billse85d6b12019-07-29 17:01:15 -07001229 // Reset the unique ID on the first entry
1230 bool firstEntry = true;
Jason M. Bills95820182019-04-22 16:25:34 -07001231 while (std::getline(logStream, logEntry))
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001232 {
Jason M. Bills95820182019-04-22 16:25:34 -07001233 entryCount++;
1234 // Handle paging using skip (number of entries to skip from the
1235 // start) and top (number of entries to display)
1236 if (entryCount <= skip || entryCount > skip + top)
1237 {
1238 continue;
1239 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001240
Jason M. Bills95820182019-04-22 16:25:34 -07001241 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001242 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Jason M. Bills95820182019-04-22 16:25:34 -07001243 {
1244 continue;
1245 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001246
Jason M. Billse85d6b12019-07-29 17:01:15 -07001247 if (firstEntry)
1248 {
1249 firstEntry = false;
1250 }
1251
Jason M. Bills95820182019-04-22 16:25:34 -07001252 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001253 nlohmann::json& bmcLogEntry = logEntryArray.back();
Jason M. Bills95820182019-04-22 16:25:34 -07001254 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
1255 {
1256 messages::internalError(asyncResp->res);
1257 return;
1258 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001259 }
1260 }
1261 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1262 if (skip + top < entryCount)
1263 {
1264 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Bills95820182019-04-22 16:25:34 -07001265 "/redfish/v1/Systems/system/LogServices/EventLog/"
1266 "Entries?$skip=" +
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001267 std::to_string(skip + top);
1268 }
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001269 }
1270};
1271
Jason M. Bills897967d2019-07-29 17:05:30 -07001272class JournalEventLogEntry : public Node
1273{
1274 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001275 JournalEventLogEntry(App& app) :
Jason M. Bills897967d2019-07-29 17:05:30 -07001276 Node(app,
1277 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1278 std::string())
1279 {
1280 entityPrivileges = {
1281 {boost::beast::http::verb::get, {{"Login"}}},
1282 {boost::beast::http::verb::head, {{"Login"}}},
1283 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1284 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1285 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1286 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1287 }
1288
1289 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08001290 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1291 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001292 const std::vector<std::string>& params) override
Jason M. Bills897967d2019-07-29 17:05:30 -07001293 {
zhanghch058d1b46d2021-04-01 11:18:24 +08001294
Jason M. Bills897967d2019-07-29 17:05:30 -07001295 if (params.size() != 1)
1296 {
1297 messages::internalError(asyncResp->res);
1298 return;
1299 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001300 const std::string& targetID = params[0];
Jason M. Bills897967d2019-07-29 17:05:30 -07001301
1302 // Go through the log files and check the unique ID for each entry to
1303 // find the target entry
1304 std::vector<std::filesystem::path> redfishLogFiles;
1305 getRedfishLogFiles(redfishLogFiles);
1306 std::string logEntry;
1307
1308 // Oldest logs are in the last file, so start there and loop backwards
1309 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1310 it++)
1311 {
1312 std::ifstream logStream(*it);
1313 if (!logStream.is_open())
1314 {
1315 continue;
1316 }
1317
1318 // Reset the unique ID on the first entry
1319 bool firstEntry = true;
1320 while (std::getline(logStream, logEntry))
1321 {
1322 std::string idStr;
1323 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1324 {
1325 continue;
1326 }
1327
1328 if (firstEntry)
1329 {
1330 firstEntry = false;
1331 }
1332
1333 if (idStr == targetID)
1334 {
1335 if (fillEventLogEntryJson(idStr, logEntry,
1336 asyncResp->res.jsonValue) != 0)
1337 {
1338 messages::internalError(asyncResp->res);
1339 return;
1340 }
1341 return;
1342 }
1343 }
1344 }
1345 // Requested ID was not found
1346 messages::resourceMissingAtURI(asyncResp->res, targetID);
1347 }
1348};
1349
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001350class DBusEventLogEntryCollection : public Node
1351{
1352 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001353 DBusEventLogEntryCollection(App& app) :
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001354 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1355 {
1356 entityPrivileges = {
1357 {boost::beast::http::verb::get, {{"Login"}}},
1358 {boost::beast::http::verb::head, {{"Login"}}},
1359 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1360 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1361 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1362 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1363 }
1364
1365 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08001366 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1367 const crow::Request&, const std::vector<std::string>&) override
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001368 {
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001369
1370 // Collections don't include the static data added by SubRoute because
1371 // it has a duplicate entry for members
1372 asyncResp->res.jsonValue["@odata.type"] =
1373 "#LogEntryCollection.LogEntryCollection";
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001374 asyncResp->res.jsonValue["@odata.id"] =
1375 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1376 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1377 asyncResp->res.jsonValue["Description"] =
1378 "Collection of System Event Log Entries";
1379
Andrew Geisslercb92c032018-08-17 07:56:14 -07001380 // DBus implementation of EventLog/Entries
1381 // Make call to Logging Service to find all log entry objects
1382 crow::connections::systemBus->async_method_call(
1383 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001384 GetManagedObjectsType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001385 if (ec)
1386 {
1387 // TODO Handle for specific error code
1388 BMCWEB_LOG_ERROR
1389 << "getLogEntriesIfaceData resp_handler got error "
1390 << ec;
1391 messages::internalError(asyncResp->res);
1392 return;
1393 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001394 nlohmann::json& entriesArray =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001395 asyncResp->res.jsonValue["Members"];
1396 entriesArray = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001397 for (auto& objectPath : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001398 {
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001399 uint32_t* id = nullptr;
1400 std::time_t timestamp{};
1401 std::time_t updateTimestamp{};
1402 std::string* severity = nullptr;
1403 std::string* message = nullptr;
1404 std::string* filePath = nullptr;
1405 bool resolved = false;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001406 for (auto& interfaceMap : objectPath.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001407 {
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001408 if (interfaceMap.first ==
Andrew Geisslercb92c032018-08-17 07:56:14 -07001409 "xyz.openbmc_project.Logging.Entry")
1410 {
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001411 for (auto& propertyMap : interfaceMap.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001412 {
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001413 if (propertyMap.first == "Id")
George Liuebd45902020-08-26 14:21:10 +08001414 {
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001415 id = std::get_if<uint32_t>(
1416 &propertyMap.second);
George Liuebd45902020-08-26 14:21:10 +08001417 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001418 else if (propertyMap.first == "Timestamp")
George Liuebd45902020-08-26 14:21:10 +08001419 {
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001420 const uint64_t* millisTimeStamp =
1421 std::get_if<uint64_t>(
1422 &propertyMap.second);
1423 if (millisTimeStamp != nullptr)
1424 {
1425 timestamp = crow::utility::getTimestamp(
George Liuebd45902020-08-26 14:21:10 +08001426 *millisTimeStamp);
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001427 }
George Liuebd45902020-08-26 14:21:10 +08001428 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001429 else if (propertyMap.first == "UpdateTimestamp")
Xiaochao Ma75710de2021-01-21 17:56:02 +08001430 {
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001431 const uint64_t* millisTimeStamp =
1432 std::get_if<uint64_t>(
1433 &propertyMap.second);
1434 if (millisTimeStamp != nullptr)
1435 {
1436 updateTimestamp =
1437 crow::utility::getTimestamp(
1438 *millisTimeStamp);
1439 }
Xiaochao Ma75710de2021-01-21 17:56:02 +08001440 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001441 else if (propertyMap.first == "Severity")
1442 {
1443 severity = std::get_if<std::string>(
1444 &propertyMap.second);
1445 }
1446 else if (propertyMap.first == "Message")
1447 {
1448 message = std::get_if<std::string>(
1449 &propertyMap.second);
1450 }
1451 else if (propertyMap.first == "Resolved")
1452 {
1453 bool* resolveptr =
1454 std::get_if<bool>(&propertyMap.second);
1455 if (resolveptr == nullptr)
1456 {
1457 messages::internalError(asyncResp->res);
1458 return;
1459 }
1460 resolved = *resolveptr;
1461 }
1462 }
1463 if (id == nullptr || message == nullptr ||
1464 severity == nullptr)
1465 {
1466 messages::internalError(asyncResp->res);
1467 return;
Xiaochao Ma75710de2021-01-21 17:56:02 +08001468 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001469 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001470 else if (interfaceMap.first ==
1471 "xyz.openbmc_project.Common.FilePath")
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001472 {
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001473 for (auto& propertyMap : interfaceMap.second)
1474 {
1475 if (propertyMap.first == "Path")
1476 {
1477 filePath = std::get_if<std::string>(
1478 &propertyMap.second);
1479 }
1480 }
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001481 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001482 }
1483 // Object path without the xyz.openbmc_project.Logging.Entry
1484 // interface, ignore and continue.
1485 if (id == nullptr || message == nullptr ||
1486 severity == nullptr)
1487 {
1488 continue;
1489 }
1490 entriesArray.push_back({});
1491 nlohmann::json& thisEntry = entriesArray.back();
1492 thisEntry["@odata.type"] = "#LogEntry.v1_8_0.LogEntry";
1493 thisEntry["@odata.id"] = "/redfish/v1/Systems/system/"
1494 "LogServices/EventLog/Entries/" +
1495 std::to_string(*id);
1496 thisEntry["Name"] = "System Event Log Entry";
1497 thisEntry["Id"] = std::to_string(*id);
1498 thisEntry["Message"] = *message;
1499 thisEntry["Resolved"] = resolved;
1500 thisEntry["EntryType"] = "Event";
1501 thisEntry["Severity"] =
1502 translateSeverityDbusToRedfish(*severity);
1503 thisEntry["Created"] =
1504 crow::utility::getDateTime(timestamp);
1505 thisEntry["Modified"] =
1506 crow::utility::getDateTime(updateTimestamp);
1507 if (filePath != nullptr)
1508 {
1509 thisEntry["AdditionalDataURI"] =
1510 "/redfish/v1/Systems/system/LogServices/EventLog/"
1511 "attachment/" +
1512 std::to_string(*id);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001513 }
1514 }
1515 std::sort(entriesArray.begin(), entriesArray.end(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001516 [](const nlohmann::json& left,
1517 const nlohmann::json& right) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001518 return (left["Id"] <= right["Id"]);
1519 });
1520 asyncResp->res.jsonValue["Members@odata.count"] =
1521 entriesArray.size();
1522 },
1523 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
1524 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001525 }
1526};
1527
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001528class DBusEventLogEntry : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001529{
1530 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001531 DBusEventLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001532 Node(app,
Ed Tanous029573d2019-02-01 10:57:49 -08001533 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1534 std::string())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001535 {
1536 entityPrivileges = {
1537 {boost::beast::http::verb::get, {{"Login"}}},
1538 {boost::beast::http::verb::head, {{"Login"}}},
1539 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1540 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1541 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1542 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1543 }
1544
1545 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08001546 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1547 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001548 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001549 {
zhanghch058d1b46d2021-04-01 11:18:24 +08001550
Ed Tanous029573d2019-02-01 10:57:49 -08001551 if (params.size() != 1)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001552 {
1553 messages::internalError(asyncResp->res);
1554 return;
1555 }
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001556 std::string entryID = params[0];
1557 dbus::utility::escapePathForDbus(entryID);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001558
Andrew Geisslercb92c032018-08-17 07:56:14 -07001559 // DBus implementation of EventLog/Entries
1560 // Make call to Logging Service to find all log entry objects
1561 crow::connections::systemBus->async_method_call(
1562 [asyncResp, entryID](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001563 GetManagedPropertyType& resp) {
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001564 if (ec.value() == EBADR)
1565 {
1566 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1567 entryID);
1568 return;
1569 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001570 if (ec)
1571 {
1572 BMCWEB_LOG_ERROR
1573 << "EventLogEntry (DBus) resp_handler got error " << ec;
1574 messages::internalError(asyncResp->res);
1575 return;
1576 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001577 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001578 std::time_t timestamp{};
George Liud139c232020-08-18 18:48:57 +08001579 std::time_t updateTimestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001580 std::string* severity = nullptr;
1581 std::string* message = nullptr;
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001582 std::string* filePath = nullptr;
Xiaochao Ma75710de2021-01-21 17:56:02 +08001583 bool resolved = false;
George Liud139c232020-08-18 18:48:57 +08001584
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001585 for (auto& propertyMap : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001586 {
1587 if (propertyMap.first == "Id")
1588 {
1589 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001590 }
1591 else if (propertyMap.first == "Timestamp")
1592 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001593 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001594 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001595 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001596 {
1597 timestamp =
1598 crow::utility::getTimestamp(*millisTimeStamp);
1599 }
George Liud139c232020-08-18 18:48:57 +08001600 }
1601 else if (propertyMap.first == "UpdateTimestamp")
1602 {
1603 const uint64_t* millisTimeStamp =
1604 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001605 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001606 {
1607 updateTimestamp =
1608 crow::utility::getTimestamp(*millisTimeStamp);
1609 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001610 }
1611 else if (propertyMap.first == "Severity")
1612 {
1613 severity =
1614 std::get_if<std::string>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001615 }
1616 else if (propertyMap.first == "Message")
1617 {
1618 message = std::get_if<std::string>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001619 }
Xiaochao Ma75710de2021-01-21 17:56:02 +08001620 else if (propertyMap.first == "Resolved")
1621 {
1622 bool* resolveptr =
1623 std::get_if<bool>(&propertyMap.second);
1624 if (resolveptr == nullptr)
1625 {
1626 messages::internalError(asyncResp->res);
1627 return;
1628 }
1629 resolved = *resolveptr;
1630 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001631 else if (propertyMap.first == "Path")
1632 {
1633 filePath =
1634 std::get_if<std::string>(&propertyMap.second);
1635 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001636 }
Ed Tanous271584a2019-07-09 16:24:22 -07001637 if (id == nullptr || message == nullptr || severity == nullptr)
1638 {
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001639 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001640 return;
1641 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001642 asyncResp->res.jsonValue["@odata.type"] =
1643 "#LogEntry.v1_8_0.LogEntry";
1644 asyncResp->res.jsonValue["@odata.id"] =
1645 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
1646 std::to_string(*id);
1647 asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
1648 asyncResp->res.jsonValue["Id"] = std::to_string(*id);
1649 asyncResp->res.jsonValue["Message"] = *message;
1650 asyncResp->res.jsonValue["Resolved"] = resolved;
1651 asyncResp->res.jsonValue["EntryType"] = "Event";
1652 asyncResp->res.jsonValue["Severity"] =
1653 translateSeverityDbusToRedfish(*severity);
1654 asyncResp->res.jsonValue["Created"] =
1655 crow::utility::getDateTime(timestamp);
1656 asyncResp->res.jsonValue["Modified"] =
1657 crow::utility::getDateTime(updateTimestamp);
1658 if (filePath != nullptr)
1659 {
1660 asyncResp->res.jsonValue["AdditionalDataURI"] =
1661 "/redfish/v1/Systems/system/LogServices/EventLog/"
1662 "attachment/" +
1663 std::to_string(*id);
1664 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001665 },
1666 "xyz.openbmc_project.Logging",
1667 "/xyz/openbmc_project/logging/entry/" + entryID,
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001668 "org.freedesktop.DBus.Properties", "GetAll", "");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001669 }
Chicago Duan336e96c2019-07-15 14:22:08 +08001670
zhanghch058d1b46d2021-04-01 11:18:24 +08001671 void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1672 const crow::Request& req,
Xiaochao Ma75710de2021-01-21 17:56:02 +08001673 const std::vector<std::string>& params) override
1674 {
Xiaochao Ma75710de2021-01-21 17:56:02 +08001675
1676 if (params.size() != 1)
1677 {
1678 messages::internalError(asyncResp->res);
1679 return;
1680 }
1681 std::string entryId = params[0];
1682
1683 std::optional<bool> resolved;
1684
zhanghch058d1b46d2021-04-01 11:18:24 +08001685 if (!json_util::readJson(req, asyncResp->res, "Resolved", resolved))
Xiaochao Ma75710de2021-01-21 17:56:02 +08001686 {
1687 return;
1688 }
1689
1690 if (resolved)
1691 {
1692 BMCWEB_LOG_DEBUG << "Set Resolved";
1693
1694 crow::connections::systemBus->async_method_call(
1695 [asyncResp, resolved,
1696 entryId](const boost::system::error_code ec) {
1697 if (ec)
1698 {
1699 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1700 messages::internalError(asyncResp->res);
1701 return;
1702 }
1703 },
1704 "xyz.openbmc_project.Logging",
1705 "/xyz/openbmc_project/logging/entry/" + entryId,
1706 "org.freedesktop.DBus.Properties", "Set",
1707 "xyz.openbmc_project.Logging.Entry", "Resolved",
1708 std::variant<bool>(*resolved));
1709 }
1710 }
1711
zhanghch058d1b46d2021-04-01 11:18:24 +08001712 void doDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1713 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001714 const std::vector<std::string>& params) override
Chicago Duan336e96c2019-07-15 14:22:08 +08001715 {
1716
1717 BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1718
Chicago Duan336e96c2019-07-15 14:22:08 +08001719 if (params.size() != 1)
1720 {
1721 messages::internalError(asyncResp->res);
1722 return;
1723 }
1724 std::string entryID = params[0];
1725
1726 dbus::utility::escapePathForDbus(entryID);
1727
1728 // Process response from Logging service.
George Liu3de8d8b2021-03-22 17:49:39 +08001729 auto respHandler = [asyncResp,
1730 entryID](const boost::system::error_code ec) {
Chicago Duan336e96c2019-07-15 14:22:08 +08001731 BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1732 if (ec)
1733 {
George Liu3de8d8b2021-03-22 17:49:39 +08001734 if (ec.value() == EBADR)
1735 {
1736 messages::resourceNotFound(asyncResp->res, "LogEntry",
1737 entryID);
1738 return;
1739 }
Chicago Duan336e96c2019-07-15 14:22:08 +08001740 // TODO Handle for specific error code
1741 BMCWEB_LOG_ERROR
1742 << "EventLogEntry (DBus) doDelete respHandler got error "
1743 << ec;
1744 asyncResp->res.result(
1745 boost::beast::http::status::internal_server_error);
1746 return;
1747 }
1748
1749 asyncResp->res.result(boost::beast::http::status::ok);
1750 };
1751
1752 // Make call to Logging service to request Delete Log
1753 crow::connections::systemBus->async_method_call(
1754 respHandler, "xyz.openbmc_project.Logging",
1755 "/xyz/openbmc_project/logging/entry/" + entryID,
1756 "xyz.openbmc_project.Object.Delete", "Delete");
1757 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001758};
1759
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001760class DBusEventLogEntryDownload : public Node
1761{
1762 public:
1763 DBusEventLogEntryDownload(App& app) :
1764 Node(
1765 app,
1766 "/redfish/v1/Systems/system/LogServices/EventLog/attachment/<str>/",
1767 std::string())
1768 {
1769 entityPrivileges = {
1770 {boost::beast::http::verb::get, {{"Login"}}},
1771 {boost::beast::http::verb::head, {{"Login"}}},
1772 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1773 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1774 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1775 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1776 }
1777
1778 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08001779 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1780 const crow::Request& req,
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001781 const std::vector<std::string>& params) override
1782 {
Adriana Kobylak400fd1f2021-01-29 09:01:30 -06001783 if (params.size() != 1)
1784 {
1785 messages::internalError(asyncResp->res);
1786 return;
1787 }
1788
1789 std::string_view acceptHeader = req.getHeaderValue("Accept");
1790 // The iterators in boost/http/rfc7230.hpp end the string if '/' is
1791 // found, so replace it with arbitrary character '|' which is not part
1792 // of the Accept header syntax.
1793 std::string acceptStr =
1794 boost::replace_all_copy(std::string(acceptHeader), "/", "|");
1795 boost::beast::http::ext_list acceptTypes{acceptStr};
1796 bool supported = false;
1797 for (const auto& type : acceptTypes)
1798 {
1799 if ((type.first == "*|*") ||
1800 (type.first == "application|octet-stream"))
1801 {
1802 supported = true;
1803 break;
1804 }
1805 }
1806 if (!supported)
1807 {
1808 asyncResp->res.result(boost::beast::http::status::bad_request);
1809 return;
1810 }
1811
1812 std::string entryID = params[0];
1813 dbus::utility::escapePathForDbus(entryID);
1814
1815 crow::connections::systemBus->async_method_call(
1816 [asyncResp, entryID](const boost::system::error_code ec,
1817 const sdbusplus::message::unix_fd& unixfd) {
1818 if (ec.value() == EBADR)
1819 {
1820 messages::resourceNotFound(asyncResp->res,
1821 "EventLogAttachment", entryID);
1822 return;
1823 }
1824 if (ec)
1825 {
1826 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1827 messages::internalError(asyncResp->res);
1828 return;
1829 }
1830
1831 int fd = -1;
1832 fd = dup(unixfd);
1833 if (fd == -1)
1834 {
1835 messages::internalError(asyncResp->res);
1836 return;
1837 }
1838
1839 long long int size = lseek(fd, 0, SEEK_END);
1840 if (size == -1)
1841 {
1842 messages::internalError(asyncResp->res);
1843 return;
1844 }
1845
1846 // Arbitrary max size of 64kb
1847 constexpr int maxFileSize = 65536;
1848 if (size > maxFileSize)
1849 {
1850 BMCWEB_LOG_ERROR
1851 << "File size exceeds maximum allowed size of "
1852 << maxFileSize;
1853 messages::internalError(asyncResp->res);
1854 return;
1855 }
1856 std::vector<char> data(static_cast<size_t>(size));
1857 long long int rc = lseek(fd, 0, SEEK_SET);
1858 if (rc == -1)
1859 {
1860 messages::internalError(asyncResp->res);
1861 return;
1862 }
1863 rc = read(fd, data.data(), data.size());
1864 if ((rc == -1) || (rc != size))
1865 {
1866 messages::internalError(asyncResp->res);
1867 return;
1868 }
1869 close(fd);
1870
1871 std::string_view strData(data.data(), data.size());
1872 std::string output = crow::utility::base64encode(strData);
1873
1874 asyncResp->res.addHeader("Content-Type",
1875 "application/octet-stream");
1876 asyncResp->res.addHeader("Content-Transfer-Encoding", "Base64");
1877 asyncResp->res.body() = std::move(output);
1878 },
1879 "xyz.openbmc_project.Logging",
1880 "/xyz/openbmc_project/logging/entry/" + entryID,
1881 "xyz.openbmc_project.Logging.Entry", "GetEntry");
1882 }
1883};
1884
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001885class BMCLogServiceCollection : public Node
1886{
1887 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001888 BMCLogServiceCollection(App& app) :
Ed Tanous4ed77cd2018-10-15 08:08:07 -07001889 Node(app, "/redfish/v1/Managers/bmc/LogServices/")
Ed Tanous1da66f72018-07-27 16:13:37 -07001890 {
Ed Tanous1da66f72018-07-27 16:13:37 -07001891 entityPrivileges = {
Jason M. Billse1f26342018-07-18 12:12:00 -07001892 {boost::beast::http::verb::get, {{"Login"}}},
1893 {boost::beast::http::verb::head, {{"Login"}}},
1894 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1895 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1896 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1897 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07001898 }
1899
1900 private:
1901 /**
1902 * Functions triggers appropriate requests on DBus
1903 */
zhanghch058d1b46d2021-04-01 11:18:24 +08001904 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1905 const crow::Request&, const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07001906 {
zhanghch058d1b46d2021-04-01 11:18:24 +08001907
Ed Tanous1da66f72018-07-27 16:13:37 -07001908 // Collections don't include the static data added by SubRoute because
1909 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07001910 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001911 "#LogServiceCollection.LogServiceCollection";
Jason M. Billse1f26342018-07-18 12:12:00 -07001912 asyncResp->res.jsonValue["@odata.id"] =
1913 "/redfish/v1/Managers/bmc/LogServices";
1914 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1915 asyncResp->res.jsonValue["Description"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001916 "Collection of LogServices for this Manager";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001917 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001918 logServiceArray = nlohmann::json::array();
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001919#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
1920 logServiceArray.push_back(
1921 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}});
1922#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001923#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
1924 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001925 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001926#endif
Jason M. Billse1f26342018-07-18 12:12:00 -07001927 asyncResp->res.jsonValue["Members@odata.count"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001928 logServiceArray.size();
Ed Tanous1da66f72018-07-27 16:13:37 -07001929 }
1930};
1931
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001932class BMCJournalLogService : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07001933{
1934 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001935 BMCJournalLogService(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001936 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001937 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001938 entityPrivileges = {
1939 {boost::beast::http::verb::get, {{"Login"}}},
1940 {boost::beast::http::verb::head, {{"Login"}}},
1941 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1942 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1943 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1944 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1945 }
1946
1947 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08001948 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1949 const crow::Request&, const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001950 {
zhanghch058d1b46d2021-04-01 11:18:24 +08001951
Jason M. Billse1f26342018-07-18 12:12:00 -07001952 asyncResp->res.jsonValue["@odata.type"] =
1953 "#LogService.v1_1_0.LogService";
Ed Tanous0f74e642018-11-12 15:17:05 -08001954 asyncResp->res.jsonValue["@odata.id"] =
1955 "/redfish/v1/Managers/bmc/LogServices/Journal";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001956 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1957 asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1958 asyncResp->res.jsonValue["Id"] = "BMC Journal";
Jason M. Billse1f26342018-07-18 12:12:00 -07001959 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
Jason M. Billscd50aa42019-02-12 17:09:02 -08001960 asyncResp->res.jsonValue["Entries"] = {
1961 {"@odata.id",
Ed Tanous086be232019-05-23 11:47:09 -07001962 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07001963 }
1964};
1965
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001966static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1967 sd_journal* journal,
1968 nlohmann::json& bmcJournalLogEntryJson)
Jason M. Billse1f26342018-07-18 12:12:00 -07001969{
1970 // Get the Log Entry contents
1971 int ret = 0;
Jason M. Billse1f26342018-07-18 12:12:00 -07001972
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001973 std::string message;
1974 std::string_view syslogID;
1975 ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID);
1976 if (ret < 0)
1977 {
1978 BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: "
1979 << strerror(-ret);
1980 }
1981 if (!syslogID.empty())
1982 {
1983 message += std::string(syslogID) + ": ";
1984 }
1985
Ed Tanous39e77502019-03-04 17:35:53 -08001986 std::string_view msg;
Jason M. Bills16428a12018-11-02 12:42:29 -07001987 ret = getJournalMetadata(journal, "MESSAGE", msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001988 if (ret < 0)
1989 {
1990 BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1991 return 1;
1992 }
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001993 message += std::string(msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001994
1995 // Get the severity from the PRIORITY field
Ed Tanous271584a2019-07-09 16:24:22 -07001996 long int severity = 8; // Default to an invalid priority
Jason M. Bills16428a12018-11-02 12:42:29 -07001997 ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
Jason M. Billse1f26342018-07-18 12:12:00 -07001998 if (ret < 0)
1999 {
2000 BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
Jason M. Billse1f26342018-07-18 12:12:00 -07002001 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002002
2003 // Get the Created time from the timestamp
Jason M. Bills16428a12018-11-02 12:42:29 -07002004 std::string entryTimeStr;
2005 if (!getEntryTimestamp(journal, entryTimeStr))
Jason M. Billse1f26342018-07-18 12:12:00 -07002006 {
Jason M. Bills16428a12018-11-02 12:42:29 -07002007 return 1;
Jason M. Billse1f26342018-07-18 12:12:00 -07002008 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002009
2010 // Fill in the log entry with the gathered data
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002011 bmcJournalLogEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07002012 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002013 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
2014 bmcJournalLogEntryID},
Jason M. Billse1f26342018-07-18 12:12:00 -07002015 {"Name", "BMC Journal Entry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002016 {"Id", bmcJournalLogEntryID},
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08002017 {"Message", std::move(message)},
Jason M. Billse1f26342018-07-18 12:12:00 -07002018 {"EntryType", "Oem"},
Patrick Williams738c1e62021-02-22 17:14:25 -06002019 {"Severity", severity <= 2 ? "Critical"
2020 : severity <= 4 ? "Warning"
2021 : "OK"},
Ed Tanous086be232019-05-23 11:47:09 -07002022 {"OemRecordFormat", "BMC Journal Entry"},
Jason M. Billse1f26342018-07-18 12:12:00 -07002023 {"Created", std::move(entryTimeStr)}};
2024 return 0;
2025}
2026
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002027class BMCJournalLogEntryCollection : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002028{
2029 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002030 BMCJournalLogEntryCollection(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002031 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
Jason M. Billse1f26342018-07-18 12:12:00 -07002032 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002033 entityPrivileges = {
2034 {boost::beast::http::verb::get, {{"Login"}}},
2035 {boost::beast::http::verb::head, {{"Login"}}},
2036 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2037 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2038 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2039 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2040 }
2041
2042 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002043 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2044 const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002045 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07002046 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002047
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002048 static constexpr const long maxEntriesPerPage = 1000;
Ed Tanous271584a2019-07-09 16:24:22 -07002049 uint64_t skip = 0;
2050 uint64_t top = maxEntriesPerPage; // Show max entries by default
zhanghch058d1b46d2021-04-01 11:18:24 +08002051 if (!getSkipParam(asyncResp, req, skip))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002052 {
Jason M. Bills16428a12018-11-02 12:42:29 -07002053 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002054 }
zhanghch058d1b46d2021-04-01 11:18:24 +08002055 if (!getTopParam(asyncResp, req, top))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002056 {
Jason M. Bills16428a12018-11-02 12:42:29 -07002057 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002058 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002059 // Collections don't include the static data added by SubRoute because
2060 // it has a duplicate entry for members
2061 asyncResp->res.jsonValue["@odata.type"] =
2062 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08002063 asyncResp->res.jsonValue["@odata.id"] =
2064 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002065 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002066 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002067 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
2068 asyncResp->res.jsonValue["Description"] =
2069 "Collection of BMC Journal Entries";
Ed Tanous0f74e642018-11-12 15:17:05 -08002070 asyncResp->res.jsonValue["@odata.id"] =
2071 "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002072 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07002073 logEntryArray = nlohmann::json::array();
2074
2075 // Go through the journal and use the timestamp to create a unique ID
2076 // for each entry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002077 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07002078 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
2079 if (ret < 0)
2080 {
2081 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07002082 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002083 return;
2084 }
2085 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
2086 journalTmp, sd_journal_close);
2087 journalTmp = nullptr;
Ed Tanousb01bf292019-03-25 19:25:26 +00002088 uint64_t entryCount = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -07002089 // Reset the unique ID on the first entry
2090 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07002091 SD_JOURNAL_FOREACH(journal.get())
2092 {
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002093 entryCount++;
2094 // Handle paging using skip (number of entries to skip from the
2095 // start) and top (number of entries to display)
2096 if (entryCount <= skip || entryCount > skip + top)
2097 {
2098 continue;
2099 }
2100
Jason M. Bills16428a12018-11-02 12:42:29 -07002101 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07002102 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
Jason M. Billse1f26342018-07-18 12:12:00 -07002103 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002104 continue;
2105 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002106
Jason M. Billse85d6b12019-07-29 17:01:15 -07002107 if (firstEntry)
2108 {
2109 firstEntry = false;
2110 }
2111
Jason M. Billse1f26342018-07-18 12:12:00 -07002112 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002113 nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002114 if (fillBMCJournalLogEntryJson(idStr, journal.get(),
2115 bmcJournalLogEntry) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07002116 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002117 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002118 return;
2119 }
2120 }
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002121 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
2122 if (skip + top < entryCount)
2123 {
2124 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002125 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002126 std::to_string(skip + top);
2127 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002128 }
2129};
2130
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002131class BMCJournalLogEntry : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002132{
2133 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002134 BMCJournalLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002135 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
Jason M. Billse1f26342018-07-18 12:12:00 -07002136 std::string())
2137 {
2138 entityPrivileges = {
2139 {boost::beast::http::verb::get, {{"Login"}}},
2140 {boost::beast::http::verb::head, {{"Login"}}},
2141 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2142 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2143 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2144 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2145 }
2146
2147 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002148 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2149 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002150 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07002151 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002152
Jason M. Billse1f26342018-07-18 12:12:00 -07002153 if (params.size() != 1)
2154 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002155 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002156 return;
2157 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002158 const std::string& entryID = params[0];
Jason M. Billse1f26342018-07-18 12:12:00 -07002159 // Convert the unique ID back to a timestamp to find the entry
Jason M. Billse1f26342018-07-18 12:12:00 -07002160 uint64_t ts = 0;
Ed Tanous271584a2019-07-09 16:24:22 -07002161 uint64_t index = 0;
zhanghch058d1b46d2021-04-01 11:18:24 +08002162 if (!getTimestampFromID(asyncResp, entryID, ts, index))
Jason M. Billse1f26342018-07-18 12:12:00 -07002163 {
Jason M. Bills16428a12018-11-02 12:42:29 -07002164 return;
Jason M. Billse1f26342018-07-18 12:12:00 -07002165 }
2166
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002167 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07002168 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
2169 if (ret < 0)
2170 {
2171 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07002172 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002173 return;
2174 }
2175 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
2176 journalTmp, sd_journal_close);
2177 journalTmp = nullptr;
2178 // Go to the timestamp in the log and move to the entry at the index
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002179 // tracking the unique ID
2180 std::string idStr;
2181 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07002182 ret = sd_journal_seek_realtime_usec(journal.get(), ts);
Manojkiran Eda2056b6d2020-05-28 08:57:36 +05302183 if (ret < 0)
2184 {
2185 BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
2186 << strerror(-ret);
2187 messages::internalError(asyncResp->res);
2188 return;
2189 }
Ed Tanous271584a2019-07-09 16:24:22 -07002190 for (uint64_t i = 0; i <= index; i++)
Jason M. Billse1f26342018-07-18 12:12:00 -07002191 {
2192 sd_journal_next(journal.get());
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002193 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
2194 {
2195 messages::internalError(asyncResp->res);
2196 return;
2197 }
2198 if (firstEntry)
2199 {
2200 firstEntry = false;
2201 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002202 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002203 // Confirm that the entry ID matches what was requested
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002204 if (idStr != entryID)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002205 {
2206 messages::resourceMissingAtURI(asyncResp->res, entryID);
2207 return;
2208 }
2209
2210 if (fillBMCJournalLogEntryJson(entryID, journal.get(),
2211 asyncResp->res.jsonValue) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07002212 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002213 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002214 return;
2215 }
2216 }
2217};
2218
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002219class BMCDumpService : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002220{
2221 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002222 BMCDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002223 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002224 {
2225 entityPrivileges = {
2226 {boost::beast::http::verb::get, {{"Login"}}},
2227 {boost::beast::http::verb::head, {{"Login"}}},
2228 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2229 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2230 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2231 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2232 }
2233
2234 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002235 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2236 const crow::Request&, const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002237 {
raviteja-bc9bb6862020-02-03 11:53:32 -06002238
2239 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002240 "/redfish/v1/Managers/bmc/LogServices/Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002241 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002242 "#LogService.v1_2_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002243 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2244 asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
2245 asyncResp->res.jsonValue["Id"] = "Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002246 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
raviteja-bc9bb6862020-02-03 11:53:32 -06002247 asyncResp->res.jsonValue["Entries"] = {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002248 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
2249 asyncResp->res.jsonValue["Actions"] = {
2250 {"#LogService.ClearLog",
2251 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2252 "Actions/LogService.ClearLog"}}},
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002253 {"#LogService.CollectDiagnosticData",
2254 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2255 "Actions/LogService.CollectDiagnosticData"}}}};
raviteja-bc9bb6862020-02-03 11:53:32 -06002256 }
2257};
2258
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002259class BMCDumpEntryCollection : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002260{
2261 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002262 BMCDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002263 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002264 {
2265 entityPrivileges = {
2266 {boost::beast::http::verb::get, {{"Login"}}},
2267 {boost::beast::http::verb::head, {{"Login"}}},
2268 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2269 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2270 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2271 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2272 }
2273
2274 private:
2275 /**
2276 * Functions triggers appropriate requests on DBus
2277 */
zhanghch058d1b46d2021-04-01 11:18:24 +08002278 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2279 const crow::Request&, const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002280 {
raviteja-bc9bb6862020-02-03 11:53:32 -06002281
2282 asyncResp->res.jsonValue["@odata.type"] =
2283 "#LogEntryCollection.LogEntryCollection";
2284 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002285 "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
2286 asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002287 asyncResp->res.jsonValue["Description"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002288 "Collection of BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002289
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002290 getDumpEntryCollection(asyncResp, "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002291 }
2292};
2293
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002294class BMCDumpEntry : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002295{
2296 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002297 BMCDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002298 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
raviteja-bc9bb6862020-02-03 11:53:32 -06002299 std::string())
2300 {
2301 entityPrivileges = {
2302 {boost::beast::http::verb::get, {{"Login"}}},
2303 {boost::beast::http::verb::head, {{"Login"}}},
2304 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2305 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2306 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2307 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2308 }
2309
2310 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002311 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2312 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002313 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002314 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002315
raviteja-bc9bb6862020-02-03 11:53:32 -06002316 if (params.size() != 1)
2317 {
2318 messages::internalError(asyncResp->res);
2319 return;
2320 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002321 getDumpEntryById(asyncResp, params[0], "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002322 }
2323
zhanghch058d1b46d2021-04-01 11:18:24 +08002324 void doDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2325 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002326 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002327 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002328
raviteja-bc9bb6862020-02-03 11:53:32 -06002329 if (params.size() != 1)
2330 {
2331 messages::internalError(asyncResp->res);
2332 return;
2333 }
Stanley Chu98782562020-11-04 16:10:24 +08002334 deleteDumpEntry(asyncResp, params[0], "bmc");
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002335 }
2336};
raviteja-bc9bb6862020-02-03 11:53:32 -06002337
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002338class BMCDumpCreate : public Node
2339{
2340 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002341 BMCDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002342 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002343 "Actions/"
2344 "LogService.CollectDiagnosticData/")
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002345 {
2346 entityPrivileges = {
2347 {boost::beast::http::verb::get, {{"Login"}}},
2348 {boost::beast::http::verb::head, {{"Login"}}},
2349 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2350 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2351 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2352 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2353 }
2354
2355 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002356 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2357 const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002358 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002359 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002360 createDump(asyncResp, req, "BMC");
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002361 }
2362};
2363
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002364class BMCDumpClear : public Node
2365{
2366 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002367 BMCDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002368 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2369 "Actions/"
2370 "LogService.ClearLog/")
2371 {
2372 entityPrivileges = {
2373 {boost::beast::http::verb::get, {{"Login"}}},
2374 {boost::beast::http::verb::head, {{"Login"}}},
2375 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2376 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2377 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2378 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2379 }
2380
2381 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002382 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2383 const crow::Request&, const std::vector<std::string>&) override
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002384 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002385 clearDump(asyncResp, "BMC");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002386 }
2387};
2388
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002389class SystemDumpService : public Node
2390{
2391 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002392 SystemDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002393 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
2394 {
2395 entityPrivileges = {
2396 {boost::beast::http::verb::get, {{"Login"}}},
2397 {boost::beast::http::verb::head, {{"Login"}}},
2398 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2399 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2400 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2401 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2402 }
raviteja-bc9bb6862020-02-03 11:53:32 -06002403
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002404 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002405 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2406 const crow::Request&, const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002407 {
raviteja-bc9bb6862020-02-03 11:53:32 -06002408
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002409 asyncResp->res.jsonValue["@odata.id"] =
2410 "/redfish/v1/Systems/system/LogServices/Dump";
2411 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002412 "#LogService.v1_2_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002413 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2414 asyncResp->res.jsonValue["Description"] = "System Dump LogService";
2415 asyncResp->res.jsonValue["Id"] = "Dump";
2416 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2417 asyncResp->res.jsonValue["Entries"] = {
2418 {"@odata.id",
2419 "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
2420 asyncResp->res.jsonValue["Actions"] = {
2421 {"#LogService.ClearLog",
2422 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2423 "LogService.ClearLog"}}},
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002424 {"#LogService.CollectDiagnosticData",
2425 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2426 "LogService.CollectDiagnosticData"}}}};
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002427 }
2428};
2429
2430class SystemDumpEntryCollection : public Node
2431{
2432 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002433 SystemDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002434 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
2435 {
2436 entityPrivileges = {
2437 {boost::beast::http::verb::get, {{"Login"}}},
2438 {boost::beast::http::verb::head, {{"Login"}}},
2439 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2440 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2441 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2442 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2443 }
2444
2445 private:
2446 /**
2447 * Functions triggers appropriate requests on DBus
2448 */
zhanghch058d1b46d2021-04-01 11:18:24 +08002449 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2450 const crow::Request&, const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002451 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002452
2453 asyncResp->res.jsonValue["@odata.type"] =
2454 "#LogEntryCollection.LogEntryCollection";
2455 asyncResp->res.jsonValue["@odata.id"] =
2456 "/redfish/v1/Systems/system/LogServices/Dump/Entries";
2457 asyncResp->res.jsonValue["Name"] = "System Dump Entries";
2458 asyncResp->res.jsonValue["Description"] =
2459 "Collection of System Dump Entries";
2460
2461 getDumpEntryCollection(asyncResp, "System");
2462 }
2463};
2464
2465class SystemDumpEntry : public Node
2466{
2467 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002468 SystemDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002469 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
2470 std::string())
2471 {
2472 entityPrivileges = {
2473 {boost::beast::http::verb::get, {{"Login"}}},
2474 {boost::beast::http::verb::head, {{"Login"}}},
2475 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2476 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2477 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2478 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2479 }
2480
2481 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002482 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2483 const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002484 const std::vector<std::string>& params) override
2485 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002486
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002487 if (params.size() != 1)
2488 {
2489 messages::internalError(asyncResp->res);
2490 return;
2491 }
2492 getDumpEntryById(asyncResp, params[0], "System");
2493 }
2494
zhanghch058d1b46d2021-04-01 11:18:24 +08002495 void doDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2496 const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002497 const std::vector<std::string>& params) override
2498 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002499
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002500 if (params.size() != 1)
2501 {
2502 messages::internalError(asyncResp->res);
2503 return;
2504 }
Stanley Chu98782562020-11-04 16:10:24 +08002505 deleteDumpEntry(asyncResp, params[0], "system");
raviteja-bc9bb6862020-02-03 11:53:32 -06002506 }
2507};
2508
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002509class SystemDumpCreate : public Node
2510{
2511 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002512 SystemDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002513 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002514 "Actions/"
2515 "LogService.CollectDiagnosticData/")
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002516 {
2517 entityPrivileges = {
2518 {boost::beast::http::verb::get, {{"Login"}}},
2519 {boost::beast::http::verb::head, {{"Login"}}},
2520 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2521 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2522 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2523 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2524 }
2525
2526 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002527 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2528 const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002529 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002530 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002531 createDump(asyncResp, req, "System");
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002532 }
2533};
2534
raviteja-b013487e2020-03-03 03:20:48 -06002535class SystemDumpClear : public Node
2536{
2537 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002538 SystemDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002539 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
raviteja-b013487e2020-03-03 03:20:48 -06002540 "Actions/"
2541 "LogService.ClearLog/")
2542 {
2543 entityPrivileges = {
2544 {boost::beast::http::verb::get, {{"Login"}}},
2545 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002546 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2547 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2548 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b013487e2020-03-03 03:20:48 -06002549 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2550 }
2551
2552 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002553 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2554 const crow::Request&, const std::vector<std::string>&) override
raviteja-b013487e2020-03-03 03:20:48 -06002555 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002556 clearDump(asyncResp, "System");
raviteja-b013487e2020-03-03 03:20:48 -06002557 }
2558};
2559
Jason M. Bills424c4172019-03-21 13:50:33 -07002560class CrashdumpService : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002561{
2562 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002563 CrashdumpService(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002564 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002565 {
AppaRao Puli39460282020-04-07 17:03:04 +05302566 // Note: Deviated from redfish privilege registry for GET & HEAD
2567 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002568 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302569 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2570 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002571 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2572 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2573 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2574 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002575 }
2576
2577 private:
2578 /**
2579 * Functions triggers appropriate requests on DBus
2580 */
zhanghch058d1b46d2021-04-01 11:18:24 +08002581 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2582 const crow::Request&, const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002583 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002584
Ed Tanous1da66f72018-07-27 16:13:37 -07002585 // Copy over the static data to include the entries added by SubRoute
Ed Tanous0f74e642018-11-12 15:17:05 -08002586 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002587 "/redfish/v1/Systems/system/LogServices/Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002588 asyncResp->res.jsonValue["@odata.type"] =
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002589 "#LogService.v1_2_0.LogService";
Gunnar Mills4f50ae42020-02-06 15:29:57 -06002590 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2591 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2592 asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002593 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2594 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Jason M. Billscd50aa42019-02-12 17:09:02 -08002595 asyncResp->res.jsonValue["Entries"] = {
2596 {"@odata.id",
Jason M. Bills424c4172019-03-21 13:50:33 -07002597 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07002598 asyncResp->res.jsonValue["Actions"] = {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002599 {"#LogService.ClearLog",
2600 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2601 "Actions/LogService.ClearLog"}}},
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002602 {"#LogService.CollectDiagnosticData",
2603 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2604 "Actions/LogService.CollectDiagnosticData"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002605 }
2606};
2607
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002608class CrashdumpClear : public Node
2609{
2610 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002611 CrashdumpClear(App& app) :
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002612 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2613 "LogService.ClearLog/")
2614 {
AppaRao Puli39460282020-04-07 17:03:04 +05302615 // Note: Deviated from redfish privilege registry for GET & HEAD
2616 // method for security reasons.
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002617 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302618 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2619 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002620 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2621 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2622 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2623 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2624 }
2625
2626 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002627 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2628 const crow::Request&, const std::vector<std::string>&) override
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002629 {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002630
2631 crow::connections::systemBus->async_method_call(
2632 [asyncResp](const boost::system::error_code ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002633 const std::string&) {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002634 if (ec)
2635 {
2636 messages::internalError(asyncResp->res);
2637 return;
2638 }
2639 messages::success(asyncResp->res);
2640 },
2641 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
2642 }
2643};
2644
zhanghch058d1b46d2021-04-01 11:18:24 +08002645static void
2646 logCrashdumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2647 const std::string& logID, nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002648{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002649 auto getStoredLogCallback =
2650 [asyncResp, logID, &logEntryJson](
2651 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002652 const std::vector<std::pair<std::string, VariantType>>& params) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002653 if (ec)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002654 {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002655 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
2656 if (ec.value() ==
2657 boost::system::linux_error::bad_request_descriptor)
2658 {
2659 messages::resourceNotFound(asyncResp->res, "LogEntry",
2660 logID);
2661 }
2662 else
2663 {
2664 messages::internalError(asyncResp->res);
2665 }
2666 return;
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002667 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002668
Johnathan Mantey043a0532020-03-10 17:15:28 -07002669 std::string timestamp{};
2670 std::string filename{};
2671 std::string logfile{};
Ed Tanous2c70f802020-09-28 14:29:23 -07002672 parseCrashdumpParameters(params, filename, timestamp, logfile);
Johnathan Mantey043a0532020-03-10 17:15:28 -07002673
2674 if (filename.empty() || timestamp.empty())
2675 {
2676 messages::resourceMissingAtURI(asyncResp->res, logID);
2677 return;
2678 }
2679
2680 std::string crashdumpURI =
2681 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2682 logID + "/" + filename;
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002683 logEntryJson = {{"@odata.type", "#LogEntry.v1_7_0.LogEntry"},
Johnathan Mantey043a0532020-03-10 17:15:28 -07002684 {"@odata.id", "/redfish/v1/Systems/system/"
2685 "LogServices/Crashdump/Entries/" +
2686 logID},
2687 {"Name", "CPU Crashdump"},
2688 {"Id", logID},
2689 {"EntryType", "Oem"},
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002690 {"AdditionalDataURI", std::move(crashdumpURI)},
2691 {"DiagnosticDataType", "OEM"},
2692 {"OEMDiagnosticDataType", "PECICrashdump"},
Johnathan Mantey043a0532020-03-10 17:15:28 -07002693 {"Created", std::move(timestamp)}};
2694 };
Jason M. Billse855dd22019-10-08 11:37:48 -07002695 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002696 std::move(getStoredLogCallback), crashdumpObject,
2697 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002698 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Jason M. Billse855dd22019-10-08 11:37:48 -07002699}
2700
Jason M. Bills424c4172019-03-21 13:50:33 -07002701class CrashdumpEntryCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002702{
2703 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002704 CrashdumpEntryCollection(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002705 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002706 {
AppaRao Puli39460282020-04-07 17:03:04 +05302707 // Note: Deviated from redfish privilege registry for GET & HEAD
2708 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002709 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302710 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2711 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002712 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2713 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2714 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2715 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002716 }
2717
2718 private:
2719 /**
2720 * Functions triggers appropriate requests on DBus
2721 */
zhanghch058d1b46d2021-04-01 11:18:24 +08002722 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2723 const crow::Request&, const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002724 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002725
Ed Tanous1da66f72018-07-27 16:13:37 -07002726 // Collections don't include the static data added by SubRoute because
2727 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07002728 auto getLogEntriesCallback = [asyncResp](
2729 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002730 const std::vector<std::string>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002731 if (ec)
2732 {
2733 if (ec.value() !=
2734 boost::system::errc::no_such_file_or_directory)
Ed Tanous1da66f72018-07-27 16:13:37 -07002735 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002736 BMCWEB_LOG_DEBUG << "failed to get entries ec: "
2737 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002738 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002739 return;
Ed Tanous1da66f72018-07-27 16:13:37 -07002740 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002741 }
2742 asyncResp->res.jsonValue["@odata.type"] =
2743 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08002744 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002745 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
Jason M. Bills424c4172019-03-21 13:50:33 -07002746 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002747 asyncResp->res.jsonValue["Description"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002748 "Collection of Crashdump Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002749 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07002750 logEntryArray = nlohmann::json::array();
Jason M. Billse855dd22019-10-08 11:37:48 -07002751 std::vector<std::string> logIDs;
2752 // Get the list of log entries and build up an empty array big
2753 // enough to hold them
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002754 for (const std::string& objpath : resp)
Jason M. Billse1f26342018-07-18 12:12:00 -07002755 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002756 // Get the log ID
Ed Tanousf23b7292020-10-15 09:41:17 -07002757 std::size_t lastPos = objpath.rfind('/');
Jason M. Billse855dd22019-10-08 11:37:48 -07002758 if (lastPos == std::string::npos)
Jason M. Billse1f26342018-07-18 12:12:00 -07002759 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002760 continue;
Jason M. Billse1f26342018-07-18 12:12:00 -07002761 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002762 logIDs.emplace_back(objpath.substr(lastPos + 1));
2763
2764 // Add a space for the log entry to the array
2765 logEntryArray.push_back({});
2766 }
2767 // Now go through and set up async calls to fill in the entries
2768 size_t index = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002769 for (const std::string& logID : logIDs)
Jason M. Billse855dd22019-10-08 11:37:48 -07002770 {
2771 // Add the log entry to the array
2772 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
Jason M. Billse1f26342018-07-18 12:12:00 -07002773 }
2774 asyncResp->res.jsonValue["Members@odata.count"] =
2775 logEntryArray.size();
2776 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002777 crow::connections::systemBus->async_method_call(
2778 std::move(getLogEntriesCallback),
2779 "xyz.openbmc_project.ObjectMapper",
2780 "/xyz/openbmc_project/object_mapper",
2781 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002782 std::array<const char*, 1>{crashdumpInterface});
Ed Tanous1da66f72018-07-27 16:13:37 -07002783 }
2784};
2785
Jason M. Bills424c4172019-03-21 13:50:33 -07002786class CrashdumpEntry : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002787{
2788 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002789 CrashdumpEntry(App& app) :
Jason M. Billsd53dd412019-02-12 17:16:22 -08002790 Node(app,
Jason M. Bills424c4172019-03-21 13:50:33 -07002791 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
Ed Tanous1da66f72018-07-27 16:13:37 -07002792 std::string())
2793 {
AppaRao Puli39460282020-04-07 17:03:04 +05302794 // Note: Deviated from redfish privilege registry for GET & HEAD
2795 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002796 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302797 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2798 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002799 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2800 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2801 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2802 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002803 }
2804
2805 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002806 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2807 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002808 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002809 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002810
Ed Tanous1da66f72018-07-27 16:13:37 -07002811 if (params.size() != 1)
2812 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002813 messages::internalError(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002814 return;
2815 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002816 const std::string& logID = params[0];
Jason M. Billse855dd22019-10-08 11:37:48 -07002817 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2818 }
2819};
2820
2821class CrashdumpFile : public Node
2822{
2823 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002824 CrashdumpFile(App& app) :
Jason M. Billse855dd22019-10-08 11:37:48 -07002825 Node(app,
2826 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2827 "<str>/",
2828 std::string(), std::string())
2829 {
AppaRao Puli39460282020-04-07 17:03:04 +05302830 // Note: Deviated from redfish privilege registry for GET & HEAD
2831 // method for security reasons.
Jason M. Billse855dd22019-10-08 11:37:48 -07002832 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302833 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2834 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse855dd22019-10-08 11:37:48 -07002835 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2836 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2837 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2838 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2839 }
2840
2841 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002842 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2843 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002844 const std::vector<std::string>& params) override
Jason M. Billse855dd22019-10-08 11:37:48 -07002845 {
zhanghch058d1b46d2021-04-01 11:18:24 +08002846
Jason M. Billse855dd22019-10-08 11:37:48 -07002847 if (params.size() != 2)
2848 {
2849 messages::internalError(asyncResp->res);
2850 return;
2851 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002852 const std::string& logID = params[0];
2853 const std::string& fileName = params[1];
Jason M. Billse855dd22019-10-08 11:37:48 -07002854
Johnathan Mantey043a0532020-03-10 17:15:28 -07002855 auto getStoredLogCallback =
2856 [asyncResp, logID, fileName](
2857 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002858 const std::vector<std::pair<std::string, VariantType>>& resp) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002859 if (ec)
2860 {
2861 BMCWEB_LOG_DEBUG << "failed to get log ec: "
2862 << ec.message();
2863 messages::internalError(asyncResp->res);
2864 return;
2865 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002866
Johnathan Mantey043a0532020-03-10 17:15:28 -07002867 std::string dbusFilename{};
2868 std::string dbusTimestamp{};
2869 std::string dbusFilepath{};
Jason M. Billse855dd22019-10-08 11:37:48 -07002870
Ed Tanous2c70f802020-09-28 14:29:23 -07002871 parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002872 dbusFilepath);
2873
2874 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2875 dbusFilepath.empty())
2876 {
2877 messages::resourceMissingAtURI(asyncResp->res, fileName);
2878 return;
2879 }
2880
2881 // Verify the file name parameter is correct
2882 if (fileName != dbusFilename)
2883 {
2884 messages::resourceMissingAtURI(asyncResp->res, fileName);
2885 return;
2886 }
2887
2888 if (!std::filesystem::exists(dbusFilepath))
2889 {
2890 messages::resourceMissingAtURI(asyncResp->res, fileName);
2891 return;
2892 }
2893 std::ifstream ifs(dbusFilepath, std::ios::in |
2894 std::ios::binary |
2895 std::ios::ate);
2896 std::ifstream::pos_type fileSize = ifs.tellg();
2897 if (fileSize < 0)
2898 {
2899 messages::generalError(asyncResp->res);
2900 return;
2901 }
2902 ifs.seekg(0, std::ios::beg);
2903
2904 auto crashData = std::make_unique<char[]>(
2905 static_cast<unsigned int>(fileSize));
2906
2907 ifs.read(crashData.get(), static_cast<int>(fileSize));
2908
2909 // The cast to std::string is intentional in order to use the
2910 // assign() that applies move mechanics
2911 asyncResp->res.body().assign(
2912 static_cast<std::string>(crashData.get()));
2913
2914 // Configure this to be a file download when accessed from
2915 // a browser
2916 asyncResp->res.addHeader("Content-Disposition", "attachment");
2917 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002918 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002919 std::move(getStoredLogCallback), crashdumpObject,
2920 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002921 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Ed Tanous1da66f72018-07-27 16:13:37 -07002922 }
2923};
2924
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002925class CrashdumpCollect : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002926{
2927 public:
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002928 CrashdumpCollect(App& app) :
2929 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2930 "LogService.CollectDiagnosticData/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002931 {
AppaRao Puli39460282020-04-07 17:03:04 +05302932 // Note: Deviated from redfish privilege registry for GET & HEAD
2933 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002934 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302935 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2936 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2937 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2938 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2939 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2940 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002941 }
2942
2943 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08002944 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2945 const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002946 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002947 {
Ed Tanous1da66f72018-07-27 16:13:37 -07002948
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002949 std::string diagnosticDataType;
2950 std::string oemDiagnosticDataType;
2951 if (!redfish::json_util::readJson(
2952 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
2953 "OEMDiagnosticDataType", oemDiagnosticDataType))
2954 {
2955 return;
2956 }
2957
2958 if (diagnosticDataType != "OEM")
2959 {
2960 BMCWEB_LOG_ERROR
2961 << "Only OEM DiagnosticDataType supported for Crashdump";
2962 messages::actionParameterValueFormatError(
2963 asyncResp->res, diagnosticDataType, "DiagnosticDataType",
2964 "CollectDiagnosticData");
2965 return;
2966 }
2967
2968 auto collectCrashdumpCallback = [asyncResp, req](
2969 const boost::system::error_code ec,
2970 const std::string&) {
James Feist46229572020-02-19 15:11:58 -08002971 if (ec)
2972 {
2973 if (ec.value() == boost::system::errc::operation_not_supported)
Ed Tanous1da66f72018-07-27 16:13:37 -07002974 {
James Feist46229572020-02-19 15:11:58 -08002975 messages::resourceInStandby(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002976 }
James Feist46229572020-02-19 15:11:58 -08002977 else if (ec.value() ==
2978 boost::system::errc::device_or_resource_busy)
2979 {
2980 messages::serviceTemporarilyUnavailable(asyncResp->res,
2981 "60");
2982 }
2983 else
2984 {
2985 messages::internalError(asyncResp->res);
2986 }
2987 return;
2988 }
2989 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002990 [](boost::system::error_code err, sdbusplus::message::message&,
2991 const std::shared_ptr<task::TaskData>& taskData) {
James Feist66afe4f2020-02-24 13:09:58 -08002992 if (!err)
2993 {
James Feiste5d50062020-05-11 17:29:00 -07002994 taskData->messages.emplace_back(
2995 messages::taskCompletedOK(
2996 std::to_string(taskData->index)));
James Feist831d6b02020-03-12 16:31:30 -07002997 taskData->state = "Completed";
James Feist66afe4f2020-02-24 13:09:58 -08002998 }
James Feist32898ce2020-03-10 16:16:52 -07002999 return task::completed;
James Feist66afe4f2020-02-24 13:09:58 -08003000 },
James Feist46229572020-02-19 15:11:58 -08003001 "type='signal',interface='org.freedesktop.DBus.Properties',"
3002 "member='PropertiesChanged',arg0namespace='com.intel."
3003 "crashdump'");
3004 task->startTimer(std::chrono::minutes(5));
3005 task->populateResp(asyncResp->res);
James Feistfe306722020-03-12 16:32:08 -07003006 task->payload.emplace(req);
James Feist46229572020-02-19 15:11:58 -08003007 };
Ed Tanous1da66f72018-07-27 16:13:37 -07003008
Jason M. Bills8e6c0992021-03-11 16:26:53 -08003009 if (oemDiagnosticDataType == "OnDemand")
3010 {
3011 crow::connections::systemBus->async_method_call(
3012 std::move(collectCrashdumpCallback), crashdumpObject,
3013 crashdumpPath, crashdumpOnDemandInterface,
3014 "GenerateOnDemandLog");
3015 }
3016 else if (oemDiagnosticDataType == "Telemetry")
3017 {
3018 crow::connections::systemBus->async_method_call(
3019 std::move(collectCrashdumpCallback), crashdumpObject,
3020 crashdumpPath, crashdumpTelemetryInterface,
3021 "GenerateTelemetryLog");
3022 }
3023 else
3024 {
3025 BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: "
3026 << oemDiagnosticDataType;
3027 messages::actionParameterValueFormatError(
3028 asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
3029 "CollectDiagnosticData");
3030 return;
3031 }
Kenny L. Ku6eda7682020-06-19 09:48:36 -07003032 }
3033};
3034
Andrew Geisslercb92c032018-08-17 07:56:14 -07003035/**
3036 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3037 */
3038class DBusLogServiceActionsClear : public Node
3039{
3040 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003041 DBusLogServiceActionsClear(App& app) :
Andrew Geisslercb92c032018-08-17 07:56:14 -07003042 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
Gunnar Mills7af91512020-04-14 22:16:57 -05003043 "LogService.ClearLog/")
Andrew Geisslercb92c032018-08-17 07:56:14 -07003044 {
3045 entityPrivileges = {
3046 {boost::beast::http::verb::get, {{"Login"}}},
3047 {boost::beast::http::verb::head, {{"Login"}}},
3048 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3049 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3050 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3051 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3052 }
3053
3054 private:
3055 /**
3056 * Function handles POST method request.
3057 * The Clear Log actions does not require any parameter.The action deletes
3058 * all entries found in the Entries collection for this Log Service.
3059 */
zhanghch058d1b46d2021-04-01 11:18:24 +08003060 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3061 const crow::Request&, const std::vector<std::string>&) override
Andrew Geisslercb92c032018-08-17 07:56:14 -07003062 {
3063 BMCWEB_LOG_DEBUG << "Do delete all entries.";
3064
Andrew Geisslercb92c032018-08-17 07:56:14 -07003065 // Process response from Logging service.
Ed Tanous2c70f802020-09-28 14:29:23 -07003066 auto respHandler = [asyncResp](const boost::system::error_code ec) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07003067 BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3068 if (ec)
3069 {
3070 // TODO Handle for specific error code
3071 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3072 asyncResp->res.result(
3073 boost::beast::http::status::internal_server_error);
3074 return;
3075 }
3076
3077 asyncResp->res.result(boost::beast::http::status::no_content);
3078 };
3079
3080 // Make call to Logging service to request Clear Log
3081 crow::connections::systemBus->async_method_call(
Ed Tanous2c70f802020-09-28 14:29:23 -07003082 respHandler, "xyz.openbmc_project.Logging",
Andrew Geisslercb92c032018-08-17 07:56:14 -07003083 "/xyz/openbmc_project/logging",
3084 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3085 }
3086};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003087
3088/****************************************************
3089 * Redfish PostCode interfaces
3090 * using DBUS interface: getPostCodesTS
3091 ******************************************************/
3092class PostCodesLogService : public Node
3093{
3094 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003095 PostCodesLogService(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003096 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
3097 {
3098 entityPrivileges = {
3099 {boost::beast::http::verb::get, {{"Login"}}},
3100 {boost::beast::http::verb::head, {{"Login"}}},
3101 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3102 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3103 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3104 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3105 }
3106
3107 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08003108 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3109 const crow::Request&, const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003110 {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003111
3112 asyncResp->res.jsonValue = {
3113 {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
3114 {"@odata.type", "#LogService.v1_1_0.LogService"},
ZhikuiRena3316fc2020-01-29 14:58:08 -08003115 {"Name", "POST Code Log Service"},
3116 {"Description", "POST Code Log Service"},
3117 {"Id", "BIOS POST Code Log"},
3118 {"OverWritePolicy", "WrapsWhenFull"},
3119 {"Entries",
3120 {{"@odata.id",
3121 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
3122 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
3123 {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
3124 "Actions/LogService.ClearLog"}};
3125 }
3126};
3127
3128class PostCodesClear : public Node
3129{
3130 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003131 PostCodesClear(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003132 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3133 "LogService.ClearLog/")
3134 {
3135 entityPrivileges = {
3136 {boost::beast::http::verb::get, {{"Login"}}},
3137 {boost::beast::http::verb::head, {{"Login"}}},
AppaRao Puli39460282020-04-07 17:03:04 +05303138 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
3139 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
3140 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
3141 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003142 }
3143
3144 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08003145 void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3146 const crow::Request&, const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003147 {
3148 BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3149
ZhikuiRena3316fc2020-01-29 14:58:08 -08003150 // Make call to post-code service to request clear all
3151 crow::connections::systemBus->async_method_call(
3152 [asyncResp](const boost::system::error_code ec) {
3153 if (ec)
3154 {
3155 // TODO Handle for specific error code
3156 BMCWEB_LOG_ERROR
3157 << "doClearPostCodes resp_handler got error " << ec;
3158 asyncResp->res.result(
3159 boost::beast::http::status::internal_server_error);
3160 messages::internalError(asyncResp->res);
3161 return;
3162 }
3163 },
Jonathan Doman15124762021-01-07 17:54:17 -08003164 "xyz.openbmc_project.State.Boot.PostCode0",
3165 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003166 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3167 }
3168};
3169
3170static void fillPostCodeEntry(
zhanghch058d1b46d2021-04-01 11:18:24 +08003171 const std::shared_ptr<bmcweb::AsyncResp>& aResp,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303172 const boost::container::flat_map<
3173 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003174 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3175 const uint64_t skip = 0, const uint64_t top = 0)
3176{
3177 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003178 const message_registries::Message* message =
Manojkiran Eda4a0bf532021-04-21 22:46:14 +05303179 message_registries::getMessage("OpenBMC.0.2.BIOSPOSTCode");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003180
3181 uint64_t currentCodeIndex = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003182 nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003183
3184 uint64_t firstCodeTimeUs = 0;
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303185 for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3186 code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003187 {
3188 currentCodeIndex++;
3189 std::string postcodeEntryID =
3190 "B" + std::to_string(bootIndex) + "-" +
3191 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3192
3193 uint64_t usecSinceEpoch = code.first;
3194 uint64_t usTimeOffset = 0;
3195
3196 if (1 == currentCodeIndex)
3197 { // already incremented
3198 firstCodeTimeUs = code.first;
3199 }
3200 else
3201 {
3202 usTimeOffset = code.first - firstCodeTimeUs;
3203 }
3204
3205 // skip if no specific codeIndex is specified and currentCodeIndex does
3206 // not fall between top and skip
3207 if ((codeIndex == 0) &&
3208 (currentCodeIndex <= skip || currentCodeIndex > top))
3209 {
3210 continue;
3211 }
3212
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003213 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003214 // currentIndex
3215 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3216 {
3217 // This is done for simplicity. 1st entry is needed to calculate
3218 // time offset. To improve efficiency, one can get to the entry
3219 // directly (possibly with flatmap's nth method)
3220 continue;
3221 }
3222
3223 // currentCodeIndex is within top and skip or equal to specified code
3224 // index
3225
3226 // Get the Created time from the timestamp
3227 std::string entryTimeStr;
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003228 entryTimeStr = crow::utility::getDateTime(
3229 static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003230
3231 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3232 std::ostringstream hexCode;
3233 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303234 << std::get<0>(code.second);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003235 std::ostringstream timeOffsetStr;
3236 // Set Fixed -Point Notation
3237 timeOffsetStr << std::fixed;
3238 // Set precision to 4 digits
3239 timeOffsetStr << std::setprecision(4);
3240 // Add double to stream
3241 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3242 std::vector<std::string> messageArgs = {
3243 std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3244
3245 // Get MessageArgs template from message registry
3246 std::string msg;
3247 if (message != nullptr)
3248 {
3249 msg = message->message;
3250
3251 // fill in this post code value
3252 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003253 for (const std::string& messageArg : messageArgs)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003254 {
3255 std::string argStr = "%" + std::to_string(++i);
3256 size_t argPos = msg.find(argStr);
3257 if (argPos != std::string::npos)
3258 {
3259 msg.replace(argPos, argStr.length(), messageArg);
3260 }
3261 }
3262 }
3263
Tim Leed4342a92020-04-27 11:47:58 +08003264 // Get Severity template from message registry
3265 std::string severity;
3266 if (message != nullptr)
3267 {
3268 severity = message->severity;
3269 }
3270
ZhikuiRena3316fc2020-01-29 14:58:08 -08003271 // add to AsyncResp
3272 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003273 nlohmann::json& bmcLogEntry = logEntryArray.back();
Gunnar Mills743e9a12020-10-26 12:44:53 -05003274 bmcLogEntry = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3275 {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3276 "PostCodes/Entries/" +
3277 postcodeEntryID},
3278 {"Name", "POST Code Log Entry"},
3279 {"Id", postcodeEntryID},
3280 {"Message", std::move(msg)},
Manojkiran Eda4a0bf532021-04-21 22:46:14 +05303281 {"MessageId", "OpenBMC.0.2.BIOSPOSTCode"},
Gunnar Mills743e9a12020-10-26 12:44:53 -05003282 {"MessageArgs", std::move(messageArgs)},
3283 {"EntryType", "Event"},
3284 {"Severity", std::move(severity)},
3285 {"Created", entryTimeStr}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003286 }
3287}
3288
zhanghch058d1b46d2021-04-01 11:18:24 +08003289static void getPostCodeForEntry(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003290 const uint16_t bootIndex,
3291 const uint64_t codeIndex)
3292{
3293 crow::connections::systemBus->async_method_call(
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303294 [aResp, bootIndex,
3295 codeIndex](const boost::system::error_code ec,
3296 const boost::container::flat_map<
3297 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3298 postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003299 if (ec)
3300 {
3301 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3302 messages::internalError(aResp->res);
3303 return;
3304 }
3305
3306 // skip the empty postcode boots
3307 if (postcode.empty())
3308 {
3309 return;
3310 }
3311
3312 fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3313
3314 aResp->res.jsonValue["Members@odata.count"] =
3315 aResp->res.jsonValue["Members"].size();
3316 },
Jonathan Doman15124762021-01-07 17:54:17 -08003317 "xyz.openbmc_project.State.Boot.PostCode0",
3318 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003319 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3320 bootIndex);
3321}
3322
zhanghch058d1b46d2021-04-01 11:18:24 +08003323static void getPostCodeForBoot(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003324 const uint16_t bootIndex,
3325 const uint16_t bootCount,
3326 const uint64_t entryCount, const uint64_t skip,
3327 const uint64_t top)
3328{
3329 crow::connections::systemBus->async_method_call(
3330 [aResp, bootIndex, bootCount, entryCount, skip,
3331 top](const boost::system::error_code ec,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303332 const boost::container::flat_map<
3333 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3334 postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003335 if (ec)
3336 {
3337 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3338 messages::internalError(aResp->res);
3339 return;
3340 }
3341
3342 uint64_t endCount = entryCount;
3343 if (!postcode.empty())
3344 {
3345 endCount = entryCount + postcode.size();
3346
3347 if ((skip < endCount) && ((top + skip) > entryCount))
3348 {
3349 uint64_t thisBootSkip =
3350 std::max(skip, entryCount) - entryCount;
3351 uint64_t thisBootTop =
3352 std::min(top + skip, endCount) - entryCount;
3353
3354 fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3355 thisBootSkip, thisBootTop);
3356 }
3357 aResp->res.jsonValue["Members@odata.count"] = endCount;
3358 }
3359
3360 // continue to previous bootIndex
3361 if (bootIndex < bootCount)
3362 {
3363 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3364 bootCount, endCount, skip, top);
3365 }
3366 else
3367 {
3368 aResp->res.jsonValue["Members@odata.nextLink"] =
3369 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3370 "Entries?$skip=" +
3371 std::to_string(skip + top);
3372 }
3373 },
Jonathan Doman15124762021-01-07 17:54:17 -08003374 "xyz.openbmc_project.State.Boot.PostCode0",
3375 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003376 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3377 bootIndex);
3378}
3379
zhanghch058d1b46d2021-04-01 11:18:24 +08003380static void
3381 getCurrentBootNumber(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
3382 const uint64_t skip, const uint64_t top)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003383{
3384 uint64_t entryCount = 0;
3385 crow::connections::systemBus->async_method_call(
3386 [aResp, entryCount, skip,
3387 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003388 const std::variant<uint16_t>& bootCount) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003389 if (ec)
3390 {
3391 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3392 messages::internalError(aResp->res);
3393 return;
3394 }
3395 auto pVal = std::get_if<uint16_t>(&bootCount);
3396 if (pVal)
3397 {
3398 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3399 }
3400 else
3401 {
3402 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3403 }
3404 },
Jonathan Doman15124762021-01-07 17:54:17 -08003405 "xyz.openbmc_project.State.Boot.PostCode0",
3406 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003407 "org.freedesktop.DBus.Properties", "Get",
3408 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3409}
3410
3411class PostCodesEntryCollection : public Node
3412{
3413 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003414 PostCodesEntryCollection(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003415 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3416 {
3417 entityPrivileges = {
3418 {boost::beast::http::verb::get, {{"Login"}}},
3419 {boost::beast::http::verb::head, {{"Login"}}},
3420 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3421 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3422 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3423 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3424 }
3425
3426 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08003427 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3428 const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00003429 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003430 {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003431
3432 asyncResp->res.jsonValue["@odata.type"] =
3433 "#LogEntryCollection.LogEntryCollection";
ZhikuiRena3316fc2020-01-29 14:58:08 -08003434 asyncResp->res.jsonValue["@odata.id"] =
3435 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3436 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3437 asyncResp->res.jsonValue["Description"] =
3438 "Collection of POST Code Log Entries";
3439 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3440 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3441
3442 uint64_t skip = 0;
3443 uint64_t top = maxEntriesPerPage; // Show max entries by default
zhanghch058d1b46d2021-04-01 11:18:24 +08003444 if (!getSkipParam(asyncResp, req, skip))
ZhikuiRena3316fc2020-01-29 14:58:08 -08003445 {
3446 return;
3447 }
zhanghch058d1b46d2021-04-01 11:18:24 +08003448 if (!getTopParam(asyncResp, req, top))
ZhikuiRena3316fc2020-01-29 14:58:08 -08003449 {
3450 return;
3451 }
3452 getCurrentBootNumber(asyncResp, skip, top);
3453 }
3454};
3455
3456class PostCodesEntry : public Node
3457{
3458 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003459 PostCodesEntry(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003460 Node(app,
3461 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3462 std::string())
3463 {
3464 entityPrivileges = {
3465 {boost::beast::http::verb::get, {{"Login"}}},
3466 {boost::beast::http::verb::head, {{"Login"}}},
3467 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3468 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3469 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3470 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3471 }
3472
3473 private:
zhanghch058d1b46d2021-04-01 11:18:24 +08003474 void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
3475 const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003476 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003477 {
zhanghch058d1b46d2021-04-01 11:18:24 +08003478
ZhikuiRena3316fc2020-01-29 14:58:08 -08003479 if (params.size() != 1)
3480 {
3481 messages::internalError(asyncResp->res);
3482 return;
3483 }
3484
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003485 const std::string& targetID = params[0];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003486
3487 size_t bootPos = targetID.find('B');
3488 if (bootPos == std::string::npos)
3489 {
3490 // Requested ID was not found
3491 messages::resourceMissingAtURI(asyncResp->res, targetID);
3492 return;
3493 }
3494 std::string_view bootIndexStr(targetID);
3495 bootIndexStr.remove_prefix(bootPos + 1);
3496 uint16_t bootIndex = 0;
3497 uint64_t codeIndex = 0;
3498 size_t dashPos = bootIndexStr.find('-');
3499
3500 if (dashPos == std::string::npos)
3501 {
3502 return;
3503 }
3504 std::string_view codeIndexStr(bootIndexStr);
3505 bootIndexStr.remove_suffix(dashPos);
3506 codeIndexStr.remove_prefix(dashPos + 1);
3507
3508 bootIndex = static_cast<uint16_t>(
Ed Tanous23a21a12020-07-25 04:45:05 +00003509 strtoul(std::string(bootIndexStr).c_str(), nullptr, 0));
3510 codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003511 if (bootIndex == 0 || codeIndex == 0)
3512 {
3513 BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3514 << params[0];
3515 }
3516
3517 asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
ZhikuiRena3316fc2020-01-29 14:58:08 -08003518 asyncResp->res.jsonValue["@odata.id"] =
3519 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3520 "Entries";
3521 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3522 asyncResp->res.jsonValue["Description"] =
3523 "Collection of POST Code Log Entries";
3524 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3525 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3526
3527 getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3528 }
3529};
3530
Ed Tanous1da66f72018-07-27 16:13:37 -07003531} // namespace redfish