blob: 1d076a3d7baf0e7f08e517248625ba05a80b37e8 [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>
25
Jason M. Bills4851d452019-03-28 11:27:48 -070026#include <boost/algorithm/string/split.hpp>
27#include <boost/beast/core/span.hpp>
Ed Tanous1da66f72018-07-27 16:13:37 -070028#include <boost/container/flat_map.hpp>
Jason M. Bills1ddcf012019-11-26 14:59:21 -080029#include <boost/system/linux_error.hpp>
Andrew Geisslercb92c032018-08-17 07:56:14 -070030#include <error_messages.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050031
James Feist4418c7f2019-04-15 11:09:15 -070032#include <filesystem>
Xiaochao Ma75710de2021-01-21 17:56:02 +080033#include <optional>
Jason M. Billscd225da2019-05-08 15:31:57 -070034#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080035#include <variant>
Ed Tanous1da66f72018-07-27 16:13:37 -070036
37namespace redfish
38{
39
Gunnar Mills1214b7e2020-06-04 10:11:30 -050040constexpr char const* crashdumpObject = "com.intel.crashdump";
41constexpr char const* crashdumpPath = "/com/intel/crashdump";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050042constexpr char const* crashdumpInterface = "com.intel.crashdump";
43constexpr char const* deleteAllInterface =
Jason M. Bills5b61b5e2019-10-16 10:59:02 -070044 "xyz.openbmc_project.Collection.DeleteAll";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050045constexpr char const* crashdumpOnDemandInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070046 "com.intel.crashdump.OnDemand";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050047constexpr char const* crashdumpRawPECIInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070048 "com.intel.crashdump.SendRawPeci";
Kenny L. Ku6eda7682020-06-19 09:48:36 -070049constexpr char const* crashdumpTelemetryInterface =
50 "com.intel.crashdump.Telemetry";
Ed Tanous1da66f72018-07-27 16:13:37 -070051
Jason M. Bills4851d452019-03-28 11:27:48 -070052namespace message_registries
53{
Gunnar Mills1214b7e2020-06-04 10:11:30 -050054static const Message* getMessageFromRegistry(
55 const std::string& messageKey,
Jason M. Bills4851d452019-03-28 11:27:48 -070056 const boost::beast::span<const MessageEntry> registry)
57{
58 boost::beast::span<const MessageEntry>::const_iterator messageIt =
59 std::find_if(registry.cbegin(), registry.cend(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -050060 [&messageKey](const MessageEntry& messageEntry) {
Jason M. Bills4851d452019-03-28 11:27:48 -070061 return !std::strcmp(messageEntry.first,
62 messageKey.c_str());
63 });
64 if (messageIt != registry.cend())
65 {
66 return &messageIt->second;
67 }
68
69 return nullptr;
70}
71
Gunnar Mills1214b7e2020-06-04 10:11:30 -050072static const Message* getMessage(const std::string_view& messageID)
Jason M. Bills4851d452019-03-28 11:27:48 -070073{
74 // Redfish MessageIds are in the form
75 // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
76 // the right Message
77 std::vector<std::string> fields;
78 fields.reserve(4);
79 boost::split(fields, messageID, boost::is_any_of("."));
Gunnar Mills1214b7e2020-06-04 10:11:30 -050080 std::string& registryName = fields[0];
81 std::string& messageKey = fields[3];
Jason M. Bills4851d452019-03-28 11:27:48 -070082
83 // Find the right registry and check it for the MessageKey
84 if (std::string(base::header.registryPrefix) == registryName)
85 {
86 return getMessageFromRegistry(
87 messageKey, boost::beast::span<const MessageEntry>(base::registry));
88 }
89 if (std::string(openbmc::header.registryPrefix) == registryName)
90 {
91 return getMessageFromRegistry(
92 messageKey,
93 boost::beast::span<const MessageEntry>(openbmc::registry));
94 }
95 return nullptr;
96}
97} // namespace message_registries
98
James Feistf6150402019-01-08 10:36:20 -080099namespace fs = std::filesystem;
Ed Tanous1da66f72018-07-27 16:13:37 -0700100
Andrew Geisslercb92c032018-08-17 07:56:14 -0700101using GetManagedPropertyType = boost::container::flat_map<
Patrick Williams19bd78d2020-05-13 17:38:24 -0500102 std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t,
103 int32_t, uint32_t, int64_t, uint64_t, double>>;
Andrew Geisslercb92c032018-08-17 07:56:14 -0700104
105using GetManagedObjectsType = boost::container::flat_map<
106 sdbusplus::message::object_path,
107 boost::container::flat_map<std::string, GetManagedPropertyType>>;
108
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500109inline std::string translateSeverityDbusToRedfish(const std::string& s)
Andrew Geisslercb92c032018-08-17 07:56:14 -0700110{
Ed Tanousd4d25792020-09-29 15:15:03 -0700111 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
112 (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
113 (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
114 (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
Andrew Geisslercb92c032018-08-17 07:56:14 -0700115 {
116 return "Critical";
117 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700118 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
119 (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
120 (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
Andrew Geisslercb92c032018-08-17 07:56:14 -0700121 {
122 return "OK";
123 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700124 if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
Andrew Geisslercb92c032018-08-17 07:56:14 -0700125 {
126 return "Warning";
127 }
128 return "";
129}
130
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500131static int getJournalMetadata(sd_journal* journal,
132 const std::string_view& field,
133 std::string_view& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700134{
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500135 const char* data = nullptr;
Jason M. Bills16428a12018-11-02 12:42:29 -0700136 size_t length = 0;
137 int ret = 0;
138 // Get the metadata from the requested field of the journal entry
Ed Tanous271584a2019-07-09 16:24:22 -0700139 ret = sd_journal_get_data(journal, field.data(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500140 reinterpret_cast<const void**>(&data), &length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700141 if (ret < 0)
142 {
143 return ret;
144 }
Ed Tanous39e77502019-03-04 17:35:53 -0800145 contents = std::string_view(data, length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700146 // Only use the content after the "=" character.
Ed Tanous81ce6092020-12-17 16:54:55 +0000147 contents.remove_prefix(std::min(contents.find('=') + 1, contents.size()));
Jason M. Bills16428a12018-11-02 12:42:29 -0700148 return ret;
149}
150
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500151static int getJournalMetadata(sd_journal* journal,
152 const std::string_view& field, const int& base,
153 long int& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700154{
155 int ret = 0;
Ed Tanous39e77502019-03-04 17:35:53 -0800156 std::string_view metadata;
Jason M. Bills16428a12018-11-02 12:42:29 -0700157 // Get the metadata from the requested field of the journal entry
158 ret = getJournalMetadata(journal, field, metadata);
159 if (ret < 0)
160 {
161 return ret;
162 }
Ed Tanousb01bf292019-03-25 19:25:26 +0000163 contents = strtol(metadata.data(), nullptr, base);
Jason M. Bills16428a12018-11-02 12:42:29 -0700164 return ret;
165}
166
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500167static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800168{
169 int ret = 0;
170 uint64_t timestamp = 0;
171 ret = sd_journal_get_realtime_usec(journal, &timestamp);
172 if (ret < 0)
173 {
174 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
175 << strerror(-ret);
176 return false;
177 }
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -0500178 entryTimestamp = crow::utility::getDateTime(
179 static_cast<std::time_t>(timestamp / 1000 / 1000));
180 return true;
ZhikuiRena3316fc2020-01-29 14:58:08 -0800181}
182
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500183static bool getSkipParam(crow::Response& res, const crow::Request& req,
184 uint64_t& skip)
Jason M. Bills16428a12018-11-02 12:42:29 -0700185{
James Feist5a7e8772020-07-22 09:08:38 -0700186 boost::urls::url_view::params_type::iterator it =
187 req.urlParams.find("$skip");
188 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700189 {
James Feist5a7e8772020-07-22 09:08:38 -0700190 std::string skipParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500191 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700192 skip = std::strtoul(skipParam.c_str(), &ptr, 10);
193 if (skipParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700194 {
195
196 messages::queryParameterValueTypeError(res, std::string(skipParam),
197 "$skip");
198 return false;
199 }
Jason M. Bills16428a12018-11-02 12:42:29 -0700200 }
201 return true;
202}
203
Ed Tanous271584a2019-07-09 16:24:22 -0700204static constexpr const uint64_t maxEntriesPerPage = 1000;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500205static bool getTopParam(crow::Response& res, const crow::Request& req,
206 uint64_t& top)
Jason M. Bills16428a12018-11-02 12:42:29 -0700207{
James Feist5a7e8772020-07-22 09:08:38 -0700208 boost::urls::url_view::params_type::iterator it =
209 req.urlParams.find("$top");
210 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700211 {
James Feist5a7e8772020-07-22 09:08:38 -0700212 std::string topParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500213 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700214 top = std::strtoul(topParam.c_str(), &ptr, 10);
215 if (topParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700216 {
217 messages::queryParameterValueTypeError(res, std::string(topParam),
218 "$top");
219 return false;
220 }
Ed Tanous271584a2019-07-09 16:24:22 -0700221 if (top < 1U || top > maxEntriesPerPage)
Jason M. Bills16428a12018-11-02 12:42:29 -0700222 {
223
224 messages::queryParameterOutOfRange(
225 res, std::to_string(top), "$top",
226 "1-" + std::to_string(maxEntriesPerPage));
227 return false;
228 }
229 }
230 return true;
231}
232
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500233static bool getUniqueEntryID(sd_journal* journal, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700234 const bool firstEntry = true)
Jason M. Bills16428a12018-11-02 12:42:29 -0700235{
236 int ret = 0;
237 static uint64_t prevTs = 0;
238 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700239 if (firstEntry)
240 {
241 prevTs = 0;
242 }
243
Jason M. Bills16428a12018-11-02 12:42:29 -0700244 // Get the entry timestamp
245 uint64_t curTs = 0;
246 ret = sd_journal_get_realtime_usec(journal, &curTs);
247 if (ret < 0)
248 {
249 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
250 << strerror(-ret);
251 return false;
252 }
253 // If the timestamp isn't unique, increment the index
254 if (curTs == prevTs)
255 {
256 index++;
257 }
258 else
259 {
260 // Otherwise, reset it
261 index = 0;
262 }
263 // Save the timestamp
264 prevTs = curTs;
265
266 entryID = std::to_string(curTs);
267 if (index > 0)
268 {
269 entryID += "_" + std::to_string(index);
270 }
271 return true;
272}
273
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500274static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700275 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700276{
Ed Tanous271584a2019-07-09 16:24:22 -0700277 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700278 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700279 if (firstEntry)
280 {
281 prevTs = 0;
282 }
283
Jason M. Bills95820182019-04-22 16:25:34 -0700284 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700285 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700286 std::tm timeStruct = {};
287 std::istringstream entryStream(logEntry);
288 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
289 {
290 curTs = std::mktime(&timeStruct);
291 }
292 // If the timestamp isn't unique, increment the index
293 if (curTs == prevTs)
294 {
295 index++;
296 }
297 else
298 {
299 // Otherwise, reset it
300 index = 0;
301 }
302 // Save the timestamp
303 prevTs = curTs;
304
305 entryID = std::to_string(curTs);
306 if (index > 0)
307 {
308 entryID += "_" + std::to_string(index);
309 }
310 return true;
311}
312
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500313static bool getTimestampFromID(crow::Response& res, const std::string& entryID,
314 uint64_t& timestamp, uint64_t& index)
Jason M. Bills16428a12018-11-02 12:42:29 -0700315{
316 if (entryID.empty())
317 {
318 return false;
319 }
320 // Convert the unique ID back to a timestamp to find the entry
Ed Tanous39e77502019-03-04 17:35:53 -0800321 std::string_view tsStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700322
Ed Tanous81ce6092020-12-17 16:54:55 +0000323 auto underscorePos = tsStr.find('_');
Jason M. Bills16428a12018-11-02 12:42:29 -0700324 if (underscorePos != tsStr.npos)
325 {
326 // Timestamp has an index
327 tsStr.remove_suffix(tsStr.size() - underscorePos);
Ed Tanous39e77502019-03-04 17:35:53 -0800328 std::string_view indexStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700329 indexStr.remove_prefix(underscorePos + 1);
330 std::size_t pos;
331 try
332 {
Ed Tanous39e77502019-03-04 17:35:53 -0800333 index = std::stoul(std::string(indexStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700334 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500335 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700336 {
337 messages::resourceMissingAtURI(res, entryID);
338 return false;
339 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500340 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700341 {
342 messages::resourceMissingAtURI(res, entryID);
343 return false;
344 }
345 if (pos != indexStr.size())
346 {
347 messages::resourceMissingAtURI(res, entryID);
348 return false;
349 }
350 }
351 // Timestamp has no index
352 std::size_t pos;
353 try
354 {
Ed Tanous39e77502019-03-04 17:35:53 -0800355 timestamp = std::stoull(std::string(tsStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700356 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500357 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700358 {
359 messages::resourceMissingAtURI(res, entryID);
360 return false;
361 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500362 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700363 {
364 messages::resourceMissingAtURI(res, entryID);
365 return false;
366 }
367 if (pos != tsStr.size())
368 {
369 messages::resourceMissingAtURI(res, entryID);
370 return false;
371 }
372 return true;
373}
374
Jason M. Bills95820182019-04-22 16:25:34 -0700375static bool
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500376 getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700377{
378 static const std::filesystem::path redfishLogDir = "/var/log";
379 static const std::string redfishLogFilename = "redfish";
380
381 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500382 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700383 std::filesystem::directory_iterator(redfishLogDir))
384 {
385 // If we find a redfish log file, save the path
386 std::string filename = dirEnt.path().filename();
387 if (boost::starts_with(filename, redfishLogFilename))
388 {
389 redfishLogFiles.emplace_back(redfishLogDir / filename);
390 }
391 }
392 // As the log files rotate, they are appended with a ".#" that is higher for
393 // the older logs. Since we don't expect more than 10 log files, we
394 // can just sort the list to get them in order from newest to oldest
395 std::sort(redfishLogFiles.begin(), redfishLogFiles.end());
396
397 return !redfishLogFiles.empty();
398}
399
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500400inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp,
401 const std::string& dumpType)
402{
403 std::string dumpPath;
404 if (dumpType == "BMC")
405 {
406 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
407 }
408 else if (dumpType == "System")
409 {
410 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
411 }
412 else
413 {
414 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
415 messages::internalError(asyncResp->res);
416 return;
417 }
418
419 crow::connections::systemBus->async_method_call(
420 [asyncResp, dumpPath, dumpType](const boost::system::error_code ec,
421 GetManagedObjectsType& resp) {
422 if (ec)
423 {
424 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
425 messages::internalError(asyncResp->res);
426 return;
427 }
428
429 nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
430 entriesArray = nlohmann::json::array();
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500431 std::string dumpEntryPath =
432 "/xyz/openbmc_project/dump/" +
433 std::string(boost::algorithm::to_lower_copy(dumpType)) +
434 "/entry/";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500435
436 for (auto& object : resp)
437 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500438 if (object.first.str.find(dumpEntryPath) == std::string::npos)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500439 {
440 continue;
441 }
442 std::time_t timestamp;
443 uint64_t size = 0;
444 entriesArray.push_back({});
445 nlohmann::json& thisEntry = entriesArray.back();
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000446
447 std::string entryID = object.first.filename();
448 if (entryID.empty())
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500449 {
450 continue;
451 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500452
453 for (auto& interfaceMap : object.second)
454 {
455 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
456 {
457
458 for (auto& propertyMap : interfaceMap.second)
459 {
460 if (propertyMap.first == "Size")
461 {
462 auto sizePtr =
463 std::get_if<uint64_t>(&propertyMap.second);
464 if (sizePtr == nullptr)
465 {
466 messages::internalError(asyncResp->res);
467 break;
468 }
469 size = *sizePtr;
470 break;
471 }
472 }
473 }
474 else if (interfaceMap.first ==
475 "xyz.openbmc_project.Time.EpochTime")
476 {
477
478 for (auto& propertyMap : interfaceMap.second)
479 {
480 if (propertyMap.first == "Elapsed")
481 {
482 const uint64_t* usecsTimeStamp =
483 std::get_if<uint64_t>(&propertyMap.second);
484 if (usecsTimeStamp == nullptr)
485 {
486 messages::internalError(asyncResp->res);
487 break;
488 }
489 timestamp =
490 static_cast<std::time_t>(*usecsTimeStamp);
491 break;
492 }
493 }
494 }
495 }
496
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500497 thisEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500498 thisEntry["@odata.id"] = dumpPath + entryID;
499 thisEntry["Id"] = entryID;
500 thisEntry["EntryType"] = "Event";
501 thisEntry["Created"] = crow::utility::getDateTime(timestamp);
502 thisEntry["Name"] = dumpType + " Dump Entry";
503
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500504 thisEntry["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500505
506 if (dumpType == "BMC")
507 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500508 thisEntry["DiagnosticDataType"] = "Manager";
509 thisEntry["AdditionalDataURI"] =
510 "/redfish/v1/Managers/bmc/LogServices/Dump/"
511 "attachment/" +
512 entryID;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500513 }
514 else if (dumpType == "System")
515 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500516 thisEntry["DiagnosticDataType"] = "OEM";
517 thisEntry["OEMDiagnosticDataType"] = "System";
518 thisEntry["AdditionalDataURI"] =
519 "/redfish/v1/Systems/system/LogServices/Dump/"
520 "attachment/" +
521 entryID;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500522 }
523 }
524 asyncResp->res.jsonValue["Members@odata.count"] =
525 entriesArray.size();
526 },
527 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
528 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
529}
530
531inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp,
532 const std::string& entryID,
533 const std::string& dumpType)
534{
535 std::string dumpPath;
536 if (dumpType == "BMC")
537 {
538 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
539 }
540 else if (dumpType == "System")
541 {
542 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
543 }
544 else
545 {
546 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
547 messages::internalError(asyncResp->res);
548 return;
549 }
550
551 crow::connections::systemBus->async_method_call(
552 [asyncResp, entryID, dumpPath, dumpType](
553 const boost::system::error_code ec, GetManagedObjectsType& resp) {
554 if (ec)
555 {
556 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
557 messages::internalError(asyncResp->res);
558 return;
559 }
560
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500561 bool foundDumpEntry = false;
562 std::string dumpEntryPath =
563 "/xyz/openbmc_project/dump/" +
564 std::string(boost::algorithm::to_lower_copy(dumpType)) +
565 "/entry/";
566
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500567 for (auto& objectPath : resp)
568 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500569 if (objectPath.first.str != dumpEntryPath + entryID)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500570 {
571 continue;
572 }
573
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500574 foundDumpEntry = true;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500575 std::time_t timestamp;
576 uint64_t size = 0;
577
578 for (auto& interfaceMap : objectPath.second)
579 {
580 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
581 {
582 for (auto& propertyMap : interfaceMap.second)
583 {
584 if (propertyMap.first == "Size")
585 {
586 auto sizePtr =
587 std::get_if<uint64_t>(&propertyMap.second);
588 if (sizePtr == nullptr)
589 {
590 messages::internalError(asyncResp->res);
591 break;
592 }
593 size = *sizePtr;
594 break;
595 }
596 }
597 }
598 else if (interfaceMap.first ==
599 "xyz.openbmc_project.Time.EpochTime")
600 {
601 for (auto& propertyMap : interfaceMap.second)
602 {
603 if (propertyMap.first == "Elapsed")
604 {
605 const uint64_t* usecsTimeStamp =
606 std::get_if<uint64_t>(&propertyMap.second);
607 if (usecsTimeStamp == nullptr)
608 {
609 messages::internalError(asyncResp->res);
610 break;
611 }
612 timestamp =
613 static_cast<std::time_t>(*usecsTimeStamp);
614 break;
615 }
616 }
617 }
618 }
619
620 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500621 "#LogEntry.v1_7_0.LogEntry";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500622 asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID;
623 asyncResp->res.jsonValue["Id"] = entryID;
624 asyncResp->res.jsonValue["EntryType"] = "Event";
625 asyncResp->res.jsonValue["Created"] =
626 crow::utility::getDateTime(timestamp);
627 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
628
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500629 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500630
631 if (dumpType == "BMC")
632 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500633 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
634 asyncResp->res.jsonValue["AdditionalDataURI"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500635 "/redfish/v1/Managers/bmc/LogServices/Dump/"
636 "attachment/" +
637 entryID;
638 }
639 else if (dumpType == "System")
640 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500641 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
642 asyncResp->res.jsonValue["OEMDiagnosticDataType"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500643 "System";
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500644 asyncResp->res.jsonValue["AdditionalDataURI"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500645 "/redfish/v1/Systems/system/LogServices/Dump/"
646 "attachment/" +
647 entryID;
648 }
649 }
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500650 if (foundDumpEntry == false)
651 {
652 BMCWEB_LOG_ERROR << "Can't find Dump Entry";
653 messages::internalError(asyncResp->res);
654 return;
655 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500656 },
657 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
658 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
659}
660
Stanley Chu98782562020-11-04 16:10:24 +0800661inline void deleteDumpEntry(const std::shared_ptr<AsyncResp>& asyncResp,
662 const std::string& entryID,
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500663 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500664{
George Liu3de8d8b2021-03-22 17:49:39 +0800665 auto respHandler = [asyncResp,
666 entryID](const boost::system::error_code ec) {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500667 BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
668 if (ec)
669 {
George Liu3de8d8b2021-03-22 17:49:39 +0800670 if (ec.value() == EBADR)
671 {
672 messages::resourceNotFound(asyncResp->res, "LogEntry", entryID);
673 return;
674 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500675 BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
676 << ec;
677 messages::internalError(asyncResp->res);
678 return;
679 }
680 };
681 crow::connections::systemBus->async_method_call(
682 respHandler, "xyz.openbmc_project.Dump.Manager",
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500683 "/xyz/openbmc_project/dump/" +
684 std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" +
685 entryID,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500686 "xyz.openbmc_project.Object.Delete", "Delete");
687}
688
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500689inline void createDumpTaskCallback(const crow::Request& req,
Ed Tanousb5a76932020-09-29 16:16:58 -0700690 const std::shared_ptr<AsyncResp>& asyncResp,
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500691 const uint32_t& dumpId,
692 const std::string& dumpPath,
693 const std::string& dumpType)
694{
695 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500696 [dumpId, dumpPath, dumpType](
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500697 boost::system::error_code err, sdbusplus::message::message& m,
698 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000699 if (err)
700 {
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500701 BMCWEB_LOG_ERROR << "Error in creating a dump";
702 taskData->state = "Cancelled";
703 return task::completed;
Ed Tanouscb13a392020-07-25 19:02:03 +0000704 }
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500705 std::vector<std::pair<
706 std::string,
707 std::vector<std::pair<std::string, std::variant<std::string>>>>>
708 interfacesList;
709
710 sdbusplus::message::object_path objPath;
711
712 m.read(objPath, interfacesList);
713
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500714 if (objPath.str ==
715 "/xyz/openbmc_project/dump/" +
716 std::string(boost::algorithm::to_lower_copy(dumpType)) +
717 "/entry/" + std::to_string(dumpId))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500718 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500719 nlohmann::json retMessage = messages::success();
720 taskData->messages.emplace_back(retMessage);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500721
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500722 std::string headerLoc =
723 "Location: " + dumpPath + std::to_string(dumpId);
724 taskData->payload->httpHeaders.emplace_back(
725 std::move(headerLoc));
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500726
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500727 taskData->state = "Completed";
728 return task::completed;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500729 }
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500730 return task::completed;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500731 },
732 "type='signal',interface='org.freedesktop.DBus."
733 "ObjectManager',"
734 "member='InterfacesAdded', "
735 "path='/xyz/openbmc_project/dump'");
736
737 task->startTimer(std::chrono::minutes(3));
738 task->populateResp(asyncResp->res);
739 task->payload.emplace(req);
740}
741
742inline void createDump(crow::Response& res, const crow::Request& req,
743 const std::string& dumpType)
744{
745 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
746
747 std::string dumpPath;
748 if (dumpType == "BMC")
749 {
750 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
751 }
752 else if (dumpType == "System")
753 {
754 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
755 }
756 else
757 {
758 BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
759 messages::internalError(asyncResp->res);
760 return;
761 }
762
763 std::optional<std::string> diagnosticDataType;
764 std::optional<std::string> oemDiagnosticDataType;
765
766 if (!redfish::json_util::readJson(
767 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
768 "OEMDiagnosticDataType", oemDiagnosticDataType))
769 {
770 return;
771 }
772
773 if (dumpType == "System")
774 {
775 if (!oemDiagnosticDataType || !diagnosticDataType)
776 {
777 BMCWEB_LOG_ERROR << "CreateDump action parameter "
778 "'DiagnosticDataType'/"
779 "'OEMDiagnosticDataType' value not found!";
780 messages::actionParameterMissing(
781 asyncResp->res, "CollectDiagnosticData",
782 "DiagnosticDataType & OEMDiagnosticDataType");
783 return;
784 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700785 if ((*oemDiagnosticDataType != "System") ||
786 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500787 {
788 BMCWEB_LOG_ERROR << "Wrong parameter values passed";
789 messages::invalidObject(asyncResp->res,
790 "System Dump creation parameters");
791 return;
792 }
793 }
794 else if (dumpType == "BMC")
795 {
796 if (!diagnosticDataType)
797 {
798 BMCWEB_LOG_ERROR << "CreateDump action parameter "
799 "'DiagnosticDataType' not found!";
800 messages::actionParameterMissing(
801 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
802 return;
803 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700804 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500805 {
806 BMCWEB_LOG_ERROR
807 << "Wrong parameter value passed for 'DiagnosticDataType'";
808 messages::invalidObject(asyncResp->res,
809 "BMC Dump creation parameters");
810 return;
811 }
812 }
813
814 crow::connections::systemBus->async_method_call(
815 [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
816 const uint32_t& dumpId) {
817 if (ec)
818 {
819 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
820 messages::internalError(asyncResp->res);
821 return;
822 }
823 BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
824
825 createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
826 },
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500827 "xyz.openbmc_project.Dump.Manager",
828 "/xyz/openbmc_project/dump/" +
829 std::string(boost::algorithm::to_lower_copy(dumpType)),
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500830 "xyz.openbmc_project.Dump.Create", "CreateDump");
831}
832
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500833inline void clearDump(crow::Response& res, const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500834{
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500835 std::string dumpTypeLowerCopy =
836 std::string(boost::algorithm::to_lower_copy(dumpType));
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500837 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
838 crow::connections::systemBus->async_method_call(
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500839 [asyncResp, dumpType](const boost::system::error_code ec,
840 const std::vector<std::string>& subTreePaths) {
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500841 if (ec)
842 {
843 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
844 messages::internalError(asyncResp->res);
845 return;
846 }
847
848 for (const std::string& path : subTreePaths)
849 {
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000850 sdbusplus::message::object_path objPath(path);
851 std::string logID = objPath.filename();
852 if (logID.empty())
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500853 {
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000854 continue;
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500855 }
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000856 deleteDumpEntry(asyncResp, logID, dumpType);
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500857 }
858 },
859 "xyz.openbmc_project.ObjectMapper",
860 "/xyz/openbmc_project/object_mapper",
861 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500862 "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0,
863 std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." +
864 dumpType});
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500865}
866
Ed Tanous2c70f802020-09-28 14:29:23 -0700867static void parseCrashdumpParameters(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500868 const std::vector<std::pair<std::string, VariantType>>& params,
869 std::string& filename, std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -0700870{
871 for (auto property : params)
872 {
873 if (property.first == "Timestamp")
874 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500875 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500876 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700877 if (value != nullptr)
878 {
879 timestamp = *value;
880 }
881 }
882 else if (property.first == "Filename")
883 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500884 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500885 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700886 if (value != nullptr)
887 {
888 filename = *value;
889 }
890 }
891 else if (property.first == "Log")
892 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500893 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500894 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700895 if (value != nullptr)
896 {
897 logfile = *value;
898 }
899 }
900 }
901}
902
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500903constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800904class SystemLogServiceCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -0700905{
906 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700907 SystemLogServiceCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800908 Node(app, "/redfish/v1/Systems/system/LogServices/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800909 {
910 entityPrivileges = {
911 {boost::beast::http::verb::get, {{"Login"}}},
912 {boost::beast::http::verb::head, {{"Login"}}},
913 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
914 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
915 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
916 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
917 }
918
919 private:
920 /**
921 * Functions triggers appropriate requests on DBus
922 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000923 void doGet(crow::Response& res, const crow::Request&,
924 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800925 {
926 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800927 // Collections don't include the static data added by SubRoute because
928 // it has a duplicate entry for members
929 asyncResp->res.jsonValue["@odata.type"] =
930 "#LogServiceCollection.LogServiceCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800931 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800932 "/redfish/v1/Systems/system/LogServices";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800933 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
934 asyncResp->res.jsonValue["Description"] =
935 "Collection of LogServices for this Computer System";
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500936 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800937 logServiceArray = nlohmann::json::array();
Ed Tanous029573d2019-02-01 10:57:49 -0800938 logServiceArray.push_back(
939 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500940#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
raviteja-bc9bb6862020-02-03 11:53:32 -0600941 logServiceArray.push_back(
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500942 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
raviteja-bc9bb6862020-02-03 11:53:32 -0600943#endif
944
Jason M. Billsd53dd412019-02-12 17:16:22 -0800945#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
946 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -0500947 {{"@odata.id",
948 "/redfish/v1/Systems/system/LogServices/Crashdump"}});
Jason M. Billsd53dd412019-02-12 17:16:22 -0800949#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800950 asyncResp->res.jsonValue["Members@odata.count"] =
951 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800952
953 crow::connections::systemBus->async_method_call(
954 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500955 const std::vector<std::string>& subtreePath) {
ZhikuiRena3316fc2020-01-29 14:58:08 -0800956 if (ec)
957 {
958 BMCWEB_LOG_ERROR << ec;
959 return;
960 }
961
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500962 for (auto& pathStr : subtreePath)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800963 {
964 if (pathStr.find("PostCode") != std::string::npos)
965 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000966 nlohmann::json& logServiceArrayLocal =
ZhikuiRena3316fc2020-01-29 14:58:08 -0800967 asyncResp->res.jsonValue["Members"];
Ed Tanous23a21a12020-07-25 04:45:05 +0000968 logServiceArrayLocal.push_back(
ZhikuiRena3316fc2020-01-29 14:58:08 -0800969 {{"@odata.id", "/redfish/v1/Systems/system/"
970 "LogServices/PostCodes"}});
971 asyncResp->res.jsonValue["Members@odata.count"] =
Ed Tanous23a21a12020-07-25 04:45:05 +0000972 logServiceArrayLocal.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800973 return;
974 }
975 }
976 },
977 "xyz.openbmc_project.ObjectMapper",
978 "/xyz/openbmc_project/object_mapper",
979 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500980 std::array<const char*, 1>{postCodeIface});
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800981 }
982};
983
984class EventLogService : public Node
985{
986 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700987 EventLogService(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800988 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800989 {
990 entityPrivileges = {
991 {boost::beast::http::verb::get, {{"Login"}}},
992 {boost::beast::http::verb::head, {{"Login"}}},
993 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
994 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
995 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
996 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
997 }
998
999 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001000 void doGet(crow::Response& res, const crow::Request&,
1001 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001002 {
1003 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1004
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001005 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001006 "/redfish/v1/Systems/system/LogServices/EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001007 asyncResp->res.jsonValue["@odata.type"] =
1008 "#LogService.v1_1_0.LogService";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001009 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1010 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
Gunnar Mills73ec8302020-04-14 16:02:42 -05001011 asyncResp->res.jsonValue["Id"] = "EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001012 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1013 asyncResp->res.jsonValue["Entries"] = {
1014 {"@odata.id",
Ed Tanous029573d2019-02-01 10:57:49 -08001015 "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
Gunnar Millse7d6c8b2019-07-03 11:30:01 -05001016 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1017
1018 {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1019 "Actions/LogService.ClearLog"}};
Jason M. Bills489640c2019-05-17 09:56:36 -07001020 }
1021};
1022
Tim Lee1f56a3a2019-10-09 10:17:57 +08001023class JournalEventLogClear : public Node
Jason M. Bills489640c2019-05-17 09:56:36 -07001024{
1025 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001026 JournalEventLogClear(App& app) :
Jason M. Bills489640c2019-05-17 09:56:36 -07001027 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1028 "LogService.ClearLog/")
1029 {
1030 entityPrivileges = {
1031 {boost::beast::http::verb::get, {{"Login"}}},
1032 {boost::beast::http::verb::head, {{"Login"}}},
1033 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1034 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1035 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1036 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1037 }
1038
1039 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001040 void doPost(crow::Response& res, const crow::Request&,
1041 const std::vector<std::string>&) override
Jason M. Bills489640c2019-05-17 09:56:36 -07001042 {
1043 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1044
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:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001187 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001188 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001189 {
1190 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous271584a2019-07-09 16:24:22 -07001191 uint64_t skip = 0;
1192 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001193 if (!getSkipParam(asyncResp->res, req, skip))
1194 {
1195 return;
1196 }
1197 if (!getTopParam(asyncResp->res, req, top))
1198 {
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:
Ed Tanouscb13a392020-07-25 19:02:03 +00001290 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001291 const std::vector<std::string>& params) override
Jason M. Bills897967d2019-07-29 17:05:30 -07001292 {
1293 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1294 if (params.size() != 1)
1295 {
1296 messages::internalError(asyncResp->res);
1297 return;
1298 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001299 const std::string& targetID = params[0];
Jason M. Bills897967d2019-07-29 17:05:30 -07001300
1301 // Go through the log files and check the unique ID for each entry to
1302 // find the target entry
1303 std::vector<std::filesystem::path> redfishLogFiles;
1304 getRedfishLogFiles(redfishLogFiles);
1305 std::string logEntry;
1306
1307 // Oldest logs are in the last file, so start there and loop backwards
1308 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1309 it++)
1310 {
1311 std::ifstream logStream(*it);
1312 if (!logStream.is_open())
1313 {
1314 continue;
1315 }
1316
1317 // Reset the unique ID on the first entry
1318 bool firstEntry = true;
1319 while (std::getline(logStream, logEntry))
1320 {
1321 std::string idStr;
1322 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1323 {
1324 continue;
1325 }
1326
1327 if (firstEntry)
1328 {
1329 firstEntry = false;
1330 }
1331
1332 if (idStr == targetID)
1333 {
1334 if (fillEventLogEntryJson(idStr, logEntry,
1335 asyncResp->res.jsonValue) != 0)
1336 {
1337 messages::internalError(asyncResp->res);
1338 return;
1339 }
1340 return;
1341 }
1342 }
1343 }
1344 // Requested ID was not found
1345 messages::resourceMissingAtURI(asyncResp->res, targetID);
1346 }
1347};
1348
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001349class DBusEventLogEntryCollection : public Node
1350{
1351 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001352 DBusEventLogEntryCollection(App& app) :
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001353 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1354 {
1355 entityPrivileges = {
1356 {boost::beast::http::verb::get, {{"Login"}}},
1357 {boost::beast::http::verb::head, {{"Login"}}},
1358 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1359 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1360 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1361 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1362 }
1363
1364 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001365 void doGet(crow::Response& res, const crow::Request&,
1366 const std::vector<std::string>&) override
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001367 {
1368 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1369
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:
Ed Tanouscb13a392020-07-25 19:02:03 +00001546 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001547 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001548 {
1549 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous029573d2019-02-01 10:57:49 -08001550 if (params.size() != 1)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001551 {
1552 messages::internalError(asyncResp->res);
1553 return;
1554 }
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001555 std::string entryID = params[0];
1556 dbus::utility::escapePathForDbus(entryID);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001557
Andrew Geisslercb92c032018-08-17 07:56:14 -07001558 // DBus implementation of EventLog/Entries
1559 // Make call to Logging Service to find all log entry objects
1560 crow::connections::systemBus->async_method_call(
1561 [asyncResp, entryID](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001562 GetManagedPropertyType& resp) {
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001563 if (ec.value() == EBADR)
1564 {
1565 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1566 entryID);
1567 return;
1568 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001569 if (ec)
1570 {
1571 BMCWEB_LOG_ERROR
1572 << "EventLogEntry (DBus) resp_handler got error " << ec;
1573 messages::internalError(asyncResp->res);
1574 return;
1575 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001576 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001577 std::time_t timestamp{};
George Liud139c232020-08-18 18:48:57 +08001578 std::time_t updateTimestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001579 std::string* severity = nullptr;
1580 std::string* message = nullptr;
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001581 std::string* filePath = nullptr;
Xiaochao Ma75710de2021-01-21 17:56:02 +08001582 bool resolved = false;
George Liud139c232020-08-18 18:48:57 +08001583
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001584 for (auto& propertyMap : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001585 {
1586 if (propertyMap.first == "Id")
1587 {
1588 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001589 }
1590 else if (propertyMap.first == "Timestamp")
1591 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001592 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001593 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001594 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001595 {
1596 timestamp =
1597 crow::utility::getTimestamp(*millisTimeStamp);
1598 }
George Liud139c232020-08-18 18:48:57 +08001599 }
1600 else if (propertyMap.first == "UpdateTimestamp")
1601 {
1602 const uint64_t* millisTimeStamp =
1603 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001604 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001605 {
1606 updateTimestamp =
1607 crow::utility::getTimestamp(*millisTimeStamp);
1608 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001609 }
1610 else if (propertyMap.first == "Severity")
1611 {
1612 severity =
1613 std::get_if<std::string>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001614 }
1615 else if (propertyMap.first == "Message")
1616 {
1617 message = std::get_if<std::string>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001618 }
Xiaochao Ma75710de2021-01-21 17:56:02 +08001619 else if (propertyMap.first == "Resolved")
1620 {
1621 bool* resolveptr =
1622 std::get_if<bool>(&propertyMap.second);
1623 if (resolveptr == nullptr)
1624 {
1625 messages::internalError(asyncResp->res);
1626 return;
1627 }
1628 resolved = *resolveptr;
1629 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001630 else if (propertyMap.first == "Path")
1631 {
1632 filePath =
1633 std::get_if<std::string>(&propertyMap.second);
1634 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001635 }
Ed Tanous271584a2019-07-09 16:24:22 -07001636 if (id == nullptr || message == nullptr || severity == nullptr)
1637 {
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001638 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001639 return;
1640 }
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001641 asyncResp->res.jsonValue["@odata.type"] =
1642 "#LogEntry.v1_8_0.LogEntry";
1643 asyncResp->res.jsonValue["@odata.id"] =
1644 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
1645 std::to_string(*id);
1646 asyncResp->res.jsonValue["Name"] = "System Event Log Entry";
1647 asyncResp->res.jsonValue["Id"] = std::to_string(*id);
1648 asyncResp->res.jsonValue["Message"] = *message;
1649 asyncResp->res.jsonValue["Resolved"] = resolved;
1650 asyncResp->res.jsonValue["EntryType"] = "Event";
1651 asyncResp->res.jsonValue["Severity"] =
1652 translateSeverityDbusToRedfish(*severity);
1653 asyncResp->res.jsonValue["Created"] =
1654 crow::utility::getDateTime(timestamp);
1655 asyncResp->res.jsonValue["Modified"] =
1656 crow::utility::getDateTime(updateTimestamp);
1657 if (filePath != nullptr)
1658 {
1659 asyncResp->res.jsonValue["AdditionalDataURI"] =
1660 "/redfish/v1/Systems/system/LogServices/EventLog/"
1661 "attachment/" +
1662 std::to_string(*id);
1663 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001664 },
1665 "xyz.openbmc_project.Logging",
1666 "/xyz/openbmc_project/logging/entry/" + entryID,
Adriana Kobylakf86bb902021-01-11 11:11:05 -06001667 "org.freedesktop.DBus.Properties", "GetAll", "");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001668 }
Chicago Duan336e96c2019-07-15 14:22:08 +08001669
Xiaochao Ma75710de2021-01-21 17:56:02 +08001670 void doPatch(crow::Response& res, const crow::Request& req,
1671 const std::vector<std::string>& params) override
1672 {
1673 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1674
1675 if (params.size() != 1)
1676 {
1677 messages::internalError(asyncResp->res);
1678 return;
1679 }
1680 std::string entryId = params[0];
1681
1682 std::optional<bool> resolved;
1683
1684 if (!json_util::readJson(req, res, "Resolved", resolved))
1685 {
1686 return;
1687 }
1688
1689 if (resolved)
1690 {
1691 BMCWEB_LOG_DEBUG << "Set Resolved";
1692
1693 crow::connections::systemBus->async_method_call(
1694 [asyncResp, resolved,
1695 entryId](const boost::system::error_code ec) {
1696 if (ec)
1697 {
1698 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1699 messages::internalError(asyncResp->res);
1700 return;
1701 }
1702 },
1703 "xyz.openbmc_project.Logging",
1704 "/xyz/openbmc_project/logging/entry/" + entryId,
1705 "org.freedesktop.DBus.Properties", "Set",
1706 "xyz.openbmc_project.Logging.Entry", "Resolved",
1707 std::variant<bool>(*resolved));
1708 }
1709 }
1710
Ed Tanouscb13a392020-07-25 19:02:03 +00001711 void doDelete(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001712 const std::vector<std::string>& params) override
Chicago Duan336e96c2019-07-15 14:22:08 +08001713 {
1714
1715 BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1716
1717 auto asyncResp = std::make_shared<AsyncResp>(res);
1718
1719 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
1760class BMCLogServiceCollection : public Node
1761{
1762 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001763 BMCLogServiceCollection(App& app) :
Ed Tanous4ed77cd2018-10-15 08:08:07 -07001764 Node(app, "/redfish/v1/Managers/bmc/LogServices/")
Ed Tanous1da66f72018-07-27 16:13:37 -07001765 {
Ed Tanous1da66f72018-07-27 16:13:37 -07001766 entityPrivileges = {
Jason M. Billse1f26342018-07-18 12:12:00 -07001767 {boost::beast::http::verb::get, {{"Login"}}},
1768 {boost::beast::http::verb::head, {{"Login"}}},
1769 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1770 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1771 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1772 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07001773 }
1774
1775 private:
1776 /**
1777 * Functions triggers appropriate requests on DBus
1778 */
Ed Tanouscb13a392020-07-25 19:02:03 +00001779 void doGet(crow::Response& res, const crow::Request&,
1780 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07001781 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001782 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07001783 // Collections don't include the static data added by SubRoute because
1784 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07001785 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001786 "#LogServiceCollection.LogServiceCollection";
Jason M. Billse1f26342018-07-18 12:12:00 -07001787 asyncResp->res.jsonValue["@odata.id"] =
1788 "/redfish/v1/Managers/bmc/LogServices";
1789 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1790 asyncResp->res.jsonValue["Description"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001791 "Collection of LogServices for this Manager";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001792 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001793 logServiceArray = nlohmann::json::array();
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001794#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
1795 logServiceArray.push_back(
1796 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}});
1797#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001798#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
1799 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001800 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001801#endif
Jason M. Billse1f26342018-07-18 12:12:00 -07001802 asyncResp->res.jsonValue["Members@odata.count"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001803 logServiceArray.size();
Ed Tanous1da66f72018-07-27 16:13:37 -07001804 }
1805};
1806
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001807class BMCJournalLogService : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07001808{
1809 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001810 BMCJournalLogService(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001811 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001812 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001813 entityPrivileges = {
1814 {boost::beast::http::verb::get, {{"Login"}}},
1815 {boost::beast::http::verb::head, {{"Login"}}},
1816 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1817 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1818 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1819 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1820 }
1821
1822 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001823 void doGet(crow::Response& res, const crow::Request&,
1824 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001825 {
1826 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001827 asyncResp->res.jsonValue["@odata.type"] =
1828 "#LogService.v1_1_0.LogService";
Ed Tanous0f74e642018-11-12 15:17:05 -08001829 asyncResp->res.jsonValue["@odata.id"] =
1830 "/redfish/v1/Managers/bmc/LogServices/Journal";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001831 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1832 asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1833 asyncResp->res.jsonValue["Id"] = "BMC Journal";
Jason M. Billse1f26342018-07-18 12:12:00 -07001834 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
Jason M. Billscd50aa42019-02-12 17:09:02 -08001835 asyncResp->res.jsonValue["Entries"] = {
1836 {"@odata.id",
Ed Tanous086be232019-05-23 11:47:09 -07001837 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07001838 }
1839};
1840
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001841static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1842 sd_journal* journal,
1843 nlohmann::json& bmcJournalLogEntryJson)
Jason M. Billse1f26342018-07-18 12:12:00 -07001844{
1845 // Get the Log Entry contents
1846 int ret = 0;
Jason M. Billse1f26342018-07-18 12:12:00 -07001847
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001848 std::string message;
1849 std::string_view syslogID;
1850 ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID);
1851 if (ret < 0)
1852 {
1853 BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: "
1854 << strerror(-ret);
1855 }
1856 if (!syslogID.empty())
1857 {
1858 message += std::string(syslogID) + ": ";
1859 }
1860
Ed Tanous39e77502019-03-04 17:35:53 -08001861 std::string_view msg;
Jason M. Bills16428a12018-11-02 12:42:29 -07001862 ret = getJournalMetadata(journal, "MESSAGE", msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001863 if (ret < 0)
1864 {
1865 BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1866 return 1;
1867 }
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001868 message += std::string(msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001869
1870 // Get the severity from the PRIORITY field
Ed Tanous271584a2019-07-09 16:24:22 -07001871 long int severity = 8; // Default to an invalid priority
Jason M. Bills16428a12018-11-02 12:42:29 -07001872 ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
Jason M. Billse1f26342018-07-18 12:12:00 -07001873 if (ret < 0)
1874 {
1875 BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
Jason M. Billse1f26342018-07-18 12:12:00 -07001876 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001877
1878 // Get the Created time from the timestamp
Jason M. Bills16428a12018-11-02 12:42:29 -07001879 std::string entryTimeStr;
1880 if (!getEntryTimestamp(journal, entryTimeStr))
Jason M. Billse1f26342018-07-18 12:12:00 -07001881 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001882 return 1;
Jason M. Billse1f26342018-07-18 12:12:00 -07001883 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001884
1885 // Fill in the log entry with the gathered data
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001886 bmcJournalLogEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001887 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001888 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
1889 bmcJournalLogEntryID},
Jason M. Billse1f26342018-07-18 12:12:00 -07001890 {"Name", "BMC Journal Entry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001891 {"Id", bmcJournalLogEntryID},
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001892 {"Message", std::move(message)},
Jason M. Billse1f26342018-07-18 12:12:00 -07001893 {"EntryType", "Oem"},
Patrick Williams738c1e62021-02-22 17:14:25 -06001894 {"Severity", severity <= 2 ? "Critical"
1895 : severity <= 4 ? "Warning"
1896 : "OK"},
Ed Tanous086be232019-05-23 11:47:09 -07001897 {"OemRecordFormat", "BMC Journal Entry"},
Jason M. Billse1f26342018-07-18 12:12:00 -07001898 {"Created", std::move(entryTimeStr)}};
1899 return 0;
1900}
1901
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001902class BMCJournalLogEntryCollection : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001903{
1904 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001905 BMCJournalLogEntryCollection(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001906 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001907 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001908 entityPrivileges = {
1909 {boost::beast::http::verb::get, {{"Login"}}},
1910 {boost::beast::http::verb::head, {{"Login"}}},
1911 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1912 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1913 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1914 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1915 }
1916
1917 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001918 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001919 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001920 {
1921 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001922 static constexpr const long maxEntriesPerPage = 1000;
Ed Tanous271584a2019-07-09 16:24:22 -07001923 uint64_t skip = 0;
1924 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Bills16428a12018-11-02 12:42:29 -07001925 if (!getSkipParam(asyncResp->res, req, skip))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001926 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001927 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001928 }
Jason M. Bills16428a12018-11-02 12:42:29 -07001929 if (!getTopParam(asyncResp->res, req, top))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001930 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001931 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001932 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001933 // Collections don't include the static data added by SubRoute because
1934 // it has a duplicate entry for members
1935 asyncResp->res.jsonValue["@odata.type"] =
1936 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08001937 asyncResp->res.jsonValue["@odata.id"] =
1938 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001939 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001940 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001941 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
1942 asyncResp->res.jsonValue["Description"] =
1943 "Collection of BMC Journal Entries";
Ed Tanous0f74e642018-11-12 15:17:05 -08001944 asyncResp->res.jsonValue["@odata.id"] =
1945 "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001946 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07001947 logEntryArray = nlohmann::json::array();
1948
1949 // Go through the journal and use the timestamp to create a unique ID
1950 // for each entry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001951 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001952 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1953 if (ret < 0)
1954 {
1955 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001956 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001957 return;
1958 }
1959 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1960 journalTmp, sd_journal_close);
1961 journalTmp = nullptr;
Ed Tanousb01bf292019-03-25 19:25:26 +00001962 uint64_t entryCount = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001963 // Reset the unique ID on the first entry
1964 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001965 SD_JOURNAL_FOREACH(journal.get())
1966 {
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001967 entryCount++;
1968 // Handle paging using skip (number of entries to skip from the
1969 // start) and top (number of entries to display)
1970 if (entryCount <= skip || entryCount > skip + top)
1971 {
1972 continue;
1973 }
1974
Jason M. Bills16428a12018-11-02 12:42:29 -07001975 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001976 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
Jason M. Billse1f26342018-07-18 12:12:00 -07001977 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001978 continue;
1979 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001980
Jason M. Billse85d6b12019-07-29 17:01:15 -07001981 if (firstEntry)
1982 {
1983 firstEntry = false;
1984 }
1985
Jason M. Billse1f26342018-07-18 12:12:00 -07001986 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001987 nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001988 if (fillBMCJournalLogEntryJson(idStr, journal.get(),
1989 bmcJournalLogEntry) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001990 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001991 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001992 return;
1993 }
1994 }
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001995 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1996 if (skip + top < entryCount)
1997 {
1998 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001999 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
Jason M. Bills193ad2f2018-09-26 15:08:52 -07002000 std::to_string(skip + top);
2001 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002002 }
2003};
2004
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002005class BMCJournalLogEntry : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002006{
2007 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002008 BMCJournalLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002009 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
Jason M. Billse1f26342018-07-18 12:12:00 -07002010 std::string())
2011 {
2012 entityPrivileges = {
2013 {boost::beast::http::verb::get, {{"Login"}}},
2014 {boost::beast::http::verb::head, {{"Login"}}},
2015 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2016 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2017 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2018 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2019 }
2020
2021 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002022 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002023 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07002024 {
2025 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2026 if (params.size() != 1)
2027 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002028 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002029 return;
2030 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002031 const std::string& entryID = params[0];
Jason M. Billse1f26342018-07-18 12:12:00 -07002032 // Convert the unique ID back to a timestamp to find the entry
Jason M. Billse1f26342018-07-18 12:12:00 -07002033 uint64_t ts = 0;
Ed Tanous271584a2019-07-09 16:24:22 -07002034 uint64_t index = 0;
Jason M. Bills16428a12018-11-02 12:42:29 -07002035 if (!getTimestampFromID(asyncResp->res, entryID, ts, index))
Jason M. Billse1f26342018-07-18 12:12:00 -07002036 {
Jason M. Bills16428a12018-11-02 12:42:29 -07002037 return;
Jason M. Billse1f26342018-07-18 12:12:00 -07002038 }
2039
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002040 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07002041 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
2042 if (ret < 0)
2043 {
2044 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07002045 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002046 return;
2047 }
2048 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
2049 journalTmp, sd_journal_close);
2050 journalTmp = nullptr;
2051 // Go to the timestamp in the log and move to the entry at the index
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002052 // tracking the unique ID
2053 std::string idStr;
2054 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07002055 ret = sd_journal_seek_realtime_usec(journal.get(), ts);
Manojkiran Eda2056b6d2020-05-28 08:57:36 +05302056 if (ret < 0)
2057 {
2058 BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
2059 << strerror(-ret);
2060 messages::internalError(asyncResp->res);
2061 return;
2062 }
Ed Tanous271584a2019-07-09 16:24:22 -07002063 for (uint64_t i = 0; i <= index; i++)
Jason M. Billse1f26342018-07-18 12:12:00 -07002064 {
2065 sd_journal_next(journal.get());
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002066 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
2067 {
2068 messages::internalError(asyncResp->res);
2069 return;
2070 }
2071 if (firstEntry)
2072 {
2073 firstEntry = false;
2074 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002075 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002076 // Confirm that the entry ID matches what was requested
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002077 if (idStr != entryID)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002078 {
2079 messages::resourceMissingAtURI(asyncResp->res, entryID);
2080 return;
2081 }
2082
2083 if (fillBMCJournalLogEntryJson(entryID, journal.get(),
2084 asyncResp->res.jsonValue) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07002085 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002086 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002087 return;
2088 }
2089 }
2090};
2091
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002092class BMCDumpService : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002093{
2094 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002095 BMCDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002096 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002097 {
2098 entityPrivileges = {
2099 {boost::beast::http::verb::get, {{"Login"}}},
2100 {boost::beast::http::verb::head, {{"Login"}}},
2101 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2102 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2103 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2104 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2105 }
2106
2107 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002108 void doGet(crow::Response& res, const crow::Request&,
2109 const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002110 {
2111 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2112
2113 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002114 "/redfish/v1/Managers/bmc/LogServices/Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002115 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002116 "#LogService.v1_2_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002117 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2118 asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
2119 asyncResp->res.jsonValue["Id"] = "Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002120 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
raviteja-bc9bb6862020-02-03 11:53:32 -06002121 asyncResp->res.jsonValue["Entries"] = {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002122 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
2123 asyncResp->res.jsonValue["Actions"] = {
2124 {"#LogService.ClearLog",
2125 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2126 "Actions/LogService.ClearLog"}}},
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002127 {"#LogService.CollectDiagnosticData",
2128 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2129 "Actions/LogService.CollectDiagnosticData"}}}};
raviteja-bc9bb6862020-02-03 11:53:32 -06002130 }
2131};
2132
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002133class BMCDumpEntryCollection : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002134{
2135 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002136 BMCDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002137 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002138 {
2139 entityPrivileges = {
2140 {boost::beast::http::verb::get, {{"Login"}}},
2141 {boost::beast::http::verb::head, {{"Login"}}},
2142 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2143 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2144 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2145 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2146 }
2147
2148 private:
2149 /**
2150 * Functions triggers appropriate requests on DBus
2151 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002152 void doGet(crow::Response& res, const crow::Request&,
2153 const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002154 {
2155 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2156
2157 asyncResp->res.jsonValue["@odata.type"] =
2158 "#LogEntryCollection.LogEntryCollection";
2159 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002160 "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
2161 asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002162 asyncResp->res.jsonValue["Description"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002163 "Collection of BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002164
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002165 getDumpEntryCollection(asyncResp, "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002166 }
2167};
2168
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002169class BMCDumpEntry : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002170{
2171 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002172 BMCDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002173 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
raviteja-bc9bb6862020-02-03 11:53:32 -06002174 std::string())
2175 {
2176 entityPrivileges = {
2177 {boost::beast::http::verb::get, {{"Login"}}},
2178 {boost::beast::http::verb::head, {{"Login"}}},
2179 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2180 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2181 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2182 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2183 }
2184
2185 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002186 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002187 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002188 {
2189 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2190 if (params.size() != 1)
2191 {
2192 messages::internalError(asyncResp->res);
2193 return;
2194 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002195 getDumpEntryById(asyncResp, params[0], "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002196 }
2197
Ed Tanouscb13a392020-07-25 19:02:03 +00002198 void doDelete(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002199 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002200 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002201 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002202 if (params.size() != 1)
2203 {
2204 messages::internalError(asyncResp->res);
2205 return;
2206 }
Stanley Chu98782562020-11-04 16:10:24 +08002207 deleteDumpEntry(asyncResp, params[0], "bmc");
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002208 }
2209};
raviteja-bc9bb6862020-02-03 11:53:32 -06002210
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002211class BMCDumpCreate : public Node
2212{
2213 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002214 BMCDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002215 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002216 "Actions/"
2217 "LogService.CollectDiagnosticData/")
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002218 {
2219 entityPrivileges = {
2220 {boost::beast::http::verb::get, {{"Login"}}},
2221 {boost::beast::http::verb::head, {{"Login"}}},
2222 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2223 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2224 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2225 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2226 }
2227
2228 private:
2229 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002230 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002231 {
2232 createDump(res, req, "BMC");
2233 }
2234};
2235
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002236class BMCDumpClear : public Node
2237{
2238 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002239 BMCDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002240 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2241 "Actions/"
2242 "LogService.ClearLog/")
2243 {
2244 entityPrivileges = {
2245 {boost::beast::http::verb::get, {{"Login"}}},
2246 {boost::beast::http::verb::head, {{"Login"}}},
2247 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2248 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2249 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2250 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2251 }
2252
2253 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002254 void doPost(crow::Response& res, const crow::Request&,
2255 const std::vector<std::string>&) override
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002256 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -05002257 clearDump(res, "BMC");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002258 }
2259};
2260
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002261class SystemDumpService : public Node
2262{
2263 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002264 SystemDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002265 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
2266 {
2267 entityPrivileges = {
2268 {boost::beast::http::verb::get, {{"Login"}}},
2269 {boost::beast::http::verb::head, {{"Login"}}},
2270 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2271 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2272 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2273 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2274 }
raviteja-bc9bb6862020-02-03 11:53:32 -06002275
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002276 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002277 void doGet(crow::Response& res, const crow::Request&,
2278 const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002279 {
2280 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002281
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002282 asyncResp->res.jsonValue["@odata.id"] =
2283 "/redfish/v1/Systems/system/LogServices/Dump";
2284 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002285 "#LogService.v1_2_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002286 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2287 asyncResp->res.jsonValue["Description"] = "System Dump LogService";
2288 asyncResp->res.jsonValue["Id"] = "Dump";
2289 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2290 asyncResp->res.jsonValue["Entries"] = {
2291 {"@odata.id",
2292 "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
2293 asyncResp->res.jsonValue["Actions"] = {
2294 {"#LogService.ClearLog",
2295 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2296 "LogService.ClearLog"}}},
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002297 {"#LogService.CollectDiagnosticData",
2298 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2299 "LogService.CollectDiagnosticData"}}}};
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002300 }
2301};
2302
2303class SystemDumpEntryCollection : public Node
2304{
2305 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002306 SystemDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002307 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
2308 {
2309 entityPrivileges = {
2310 {boost::beast::http::verb::get, {{"Login"}}},
2311 {boost::beast::http::verb::head, {{"Login"}}},
2312 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2313 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2314 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2315 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2316 }
2317
2318 private:
2319 /**
2320 * Functions triggers appropriate requests on DBus
2321 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002322 void doGet(crow::Response& res, const crow::Request&,
2323 const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002324 {
2325 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2326
2327 asyncResp->res.jsonValue["@odata.type"] =
2328 "#LogEntryCollection.LogEntryCollection";
2329 asyncResp->res.jsonValue["@odata.id"] =
2330 "/redfish/v1/Systems/system/LogServices/Dump/Entries";
2331 asyncResp->res.jsonValue["Name"] = "System Dump Entries";
2332 asyncResp->res.jsonValue["Description"] =
2333 "Collection of System Dump Entries";
2334
2335 getDumpEntryCollection(asyncResp, "System");
2336 }
2337};
2338
2339class SystemDumpEntry : public Node
2340{
2341 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002342 SystemDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002343 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
2344 std::string())
2345 {
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:
Ed Tanouscb13a392020-07-25 19:02:03 +00002356 void doGet(crow::Response& res, const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002357 const std::vector<std::string>& params) override
2358 {
2359 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2360 if (params.size() != 1)
2361 {
2362 messages::internalError(asyncResp->res);
2363 return;
2364 }
2365 getDumpEntryById(asyncResp, params[0], "System");
2366 }
2367
Ed Tanouscb13a392020-07-25 19:02:03 +00002368 void doDelete(crow::Response& res, const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002369 const std::vector<std::string>& params) override
2370 {
2371 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2372 if (params.size() != 1)
2373 {
2374 messages::internalError(asyncResp->res);
2375 return;
2376 }
Stanley Chu98782562020-11-04 16:10:24 +08002377 deleteDumpEntry(asyncResp, params[0], "system");
raviteja-bc9bb6862020-02-03 11:53:32 -06002378 }
2379};
2380
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002381class SystemDumpCreate : public Node
2382{
2383 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002384 SystemDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002385 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002386 "Actions/"
2387 "LogService.CollectDiagnosticData/")
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002388 {
2389 entityPrivileges = {
2390 {boost::beast::http::verb::get, {{"Login"}}},
2391 {boost::beast::http::verb::head, {{"Login"}}},
2392 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2393 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2394 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2395 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2396 }
2397
2398 private:
2399 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002400 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002401 {
2402 createDump(res, req, "System");
2403 }
2404};
2405
raviteja-b013487e2020-03-03 03:20:48 -06002406class SystemDumpClear : public Node
2407{
2408 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002409 SystemDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002410 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
raviteja-b013487e2020-03-03 03:20:48 -06002411 "Actions/"
2412 "LogService.ClearLog/")
2413 {
2414 entityPrivileges = {
2415 {boost::beast::http::verb::get, {{"Login"}}},
2416 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002417 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2418 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2419 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b013487e2020-03-03 03:20:48 -06002420 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2421 }
2422
2423 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002424 void doPost(crow::Response& res, const crow::Request&,
2425 const std::vector<std::string>&) override
raviteja-b013487e2020-03-03 03:20:48 -06002426 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -05002427 clearDump(res, "System");
raviteja-b013487e2020-03-03 03:20:48 -06002428 }
2429};
2430
Jason M. Bills424c4172019-03-21 13:50:33 -07002431class CrashdumpService : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002432{
2433 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002434 CrashdumpService(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002435 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002436 {
AppaRao Puli39460282020-04-07 17:03:04 +05302437 // Note: Deviated from redfish privilege registry for GET & HEAD
2438 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002439 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302440 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2441 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002442 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2443 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2444 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2445 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002446 }
2447
2448 private:
2449 /**
2450 * Functions triggers appropriate requests on DBus
2451 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002452 void doGet(crow::Response& res, const crow::Request&,
2453 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002454 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002455 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002456 // Copy over the static data to include the entries added by SubRoute
Ed Tanous0f74e642018-11-12 15:17:05 -08002457 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002458 "/redfish/v1/Systems/system/LogServices/Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002459 asyncResp->res.jsonValue["@odata.type"] =
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002460 "#LogService.v1_2_0.LogService";
Gunnar Mills4f50ae42020-02-06 15:29:57 -06002461 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2462 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2463 asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002464 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2465 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Jason M. Billscd50aa42019-02-12 17:09:02 -08002466 asyncResp->res.jsonValue["Entries"] = {
2467 {"@odata.id",
Jason M. Bills424c4172019-03-21 13:50:33 -07002468 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07002469 asyncResp->res.jsonValue["Actions"] = {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002470 {"#LogService.ClearLog",
2471 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2472 "Actions/LogService.ClearLog"}}},
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002473 {"#LogService.CollectDiagnosticData",
2474 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2475 "Actions/LogService.CollectDiagnosticData"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002476
2477#ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002478 asyncResp->res.jsonValue["Actions"]["Oem"] = {
Jason M. Bills424c4172019-03-21 13:50:33 -07002479 {"#Crashdump.SendRawPeci",
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05002480 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002481 "Actions/Oem/Crashdump.SendRawPeci"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002482#endif
Ed Tanous1da66f72018-07-27 16:13:37 -07002483 }
2484};
2485
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002486class CrashdumpClear : public Node
2487{
2488 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002489 CrashdumpClear(App& app) :
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002490 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2491 "LogService.ClearLog/")
2492 {
AppaRao Puli39460282020-04-07 17:03:04 +05302493 // Note: Deviated from redfish privilege registry for GET & HEAD
2494 // method for security reasons.
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002495 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302496 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2497 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002498 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2499 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2500 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2501 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2502 }
2503
2504 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002505 void doPost(crow::Response& res, const crow::Request&,
2506 const std::vector<std::string>&) override
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002507 {
2508 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2509
2510 crow::connections::systemBus->async_method_call(
2511 [asyncResp](const boost::system::error_code ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002512 const std::string&) {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002513 if (ec)
2514 {
2515 messages::internalError(asyncResp->res);
2516 return;
2517 }
2518 messages::success(asyncResp->res);
2519 },
2520 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
2521 }
2522};
2523
Ed Tanousb5a76932020-09-29 16:16:58 -07002524static void logCrashdumpEntry(const std::shared_ptr<AsyncResp>& asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002525 const std::string& logID,
2526 nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002527{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002528 auto getStoredLogCallback =
2529 [asyncResp, logID, &logEntryJson](
2530 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002531 const std::vector<std::pair<std::string, VariantType>>& params) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002532 if (ec)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002533 {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002534 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
2535 if (ec.value() ==
2536 boost::system::linux_error::bad_request_descriptor)
2537 {
2538 messages::resourceNotFound(asyncResp->res, "LogEntry",
2539 logID);
2540 }
2541 else
2542 {
2543 messages::internalError(asyncResp->res);
2544 }
2545 return;
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002546 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002547
Johnathan Mantey043a0532020-03-10 17:15:28 -07002548 std::string timestamp{};
2549 std::string filename{};
2550 std::string logfile{};
Ed Tanous2c70f802020-09-28 14:29:23 -07002551 parseCrashdumpParameters(params, filename, timestamp, logfile);
Johnathan Mantey043a0532020-03-10 17:15:28 -07002552
2553 if (filename.empty() || timestamp.empty())
2554 {
2555 messages::resourceMissingAtURI(asyncResp->res, logID);
2556 return;
2557 }
2558
2559 std::string crashdumpURI =
2560 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2561 logID + "/" + filename;
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002562 logEntryJson = {{"@odata.type", "#LogEntry.v1_7_0.LogEntry"},
Johnathan Mantey043a0532020-03-10 17:15:28 -07002563 {"@odata.id", "/redfish/v1/Systems/system/"
2564 "LogServices/Crashdump/Entries/" +
2565 logID},
2566 {"Name", "CPU Crashdump"},
2567 {"Id", logID},
2568 {"EntryType", "Oem"},
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002569 {"AdditionalDataURI", std::move(crashdumpURI)},
2570 {"DiagnosticDataType", "OEM"},
2571 {"OEMDiagnosticDataType", "PECICrashdump"},
Johnathan Mantey043a0532020-03-10 17:15:28 -07002572 {"Created", std::move(timestamp)}};
2573 };
Jason M. Billse855dd22019-10-08 11:37:48 -07002574 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002575 std::move(getStoredLogCallback), crashdumpObject,
2576 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002577 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Jason M. Billse855dd22019-10-08 11:37:48 -07002578}
2579
Jason M. Bills424c4172019-03-21 13:50:33 -07002580class CrashdumpEntryCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002581{
2582 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002583 CrashdumpEntryCollection(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002584 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002585 {
AppaRao Puli39460282020-04-07 17:03:04 +05302586 // Note: Deviated from redfish privilege registry for GET & HEAD
2587 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002588 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302589 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2590 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002591 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2592 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2593 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2594 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002595 }
2596
2597 private:
2598 /**
2599 * Functions triggers appropriate requests on DBus
2600 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002601 void doGet(crow::Response& res, const crow::Request&,
2602 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002603 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002604 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002605 // Collections don't include the static data added by SubRoute because
2606 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07002607 auto getLogEntriesCallback = [asyncResp](
2608 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002609 const std::vector<std::string>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002610 if (ec)
2611 {
2612 if (ec.value() !=
2613 boost::system::errc::no_such_file_or_directory)
Ed Tanous1da66f72018-07-27 16:13:37 -07002614 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002615 BMCWEB_LOG_DEBUG << "failed to get entries ec: "
2616 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002617 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002618 return;
Ed Tanous1da66f72018-07-27 16:13:37 -07002619 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002620 }
2621 asyncResp->res.jsonValue["@odata.type"] =
2622 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08002623 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002624 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
Jason M. Bills424c4172019-03-21 13:50:33 -07002625 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002626 asyncResp->res.jsonValue["Description"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002627 "Collection of Crashdump Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002628 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07002629 logEntryArray = nlohmann::json::array();
Jason M. Billse855dd22019-10-08 11:37:48 -07002630 std::vector<std::string> logIDs;
2631 // Get the list of log entries and build up an empty array big
2632 // enough to hold them
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002633 for (const std::string& objpath : resp)
Jason M. Billse1f26342018-07-18 12:12:00 -07002634 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002635 // Get the log ID
Ed Tanousf23b7292020-10-15 09:41:17 -07002636 std::size_t lastPos = objpath.rfind('/');
Jason M. Billse855dd22019-10-08 11:37:48 -07002637 if (lastPos == std::string::npos)
Jason M. Billse1f26342018-07-18 12:12:00 -07002638 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002639 continue;
Jason M. Billse1f26342018-07-18 12:12:00 -07002640 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002641 logIDs.emplace_back(objpath.substr(lastPos + 1));
2642
2643 // Add a space for the log entry to the array
2644 logEntryArray.push_back({});
2645 }
2646 // Now go through and set up async calls to fill in the entries
2647 size_t index = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002648 for (const std::string& logID : logIDs)
Jason M. Billse855dd22019-10-08 11:37:48 -07002649 {
2650 // Add the log entry to the array
2651 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
Jason M. Billse1f26342018-07-18 12:12:00 -07002652 }
2653 asyncResp->res.jsonValue["Members@odata.count"] =
2654 logEntryArray.size();
2655 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002656 crow::connections::systemBus->async_method_call(
2657 std::move(getLogEntriesCallback),
2658 "xyz.openbmc_project.ObjectMapper",
2659 "/xyz/openbmc_project/object_mapper",
2660 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002661 std::array<const char*, 1>{crashdumpInterface});
Ed Tanous1da66f72018-07-27 16:13:37 -07002662 }
2663};
2664
Jason M. Bills424c4172019-03-21 13:50:33 -07002665class CrashdumpEntry : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002666{
2667 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002668 CrashdumpEntry(App& app) :
Jason M. Billsd53dd412019-02-12 17:16:22 -08002669 Node(app,
Jason M. Bills424c4172019-03-21 13:50:33 -07002670 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
Ed Tanous1da66f72018-07-27 16:13:37 -07002671 std::string())
2672 {
AppaRao Puli39460282020-04-07 17:03:04 +05302673 // Note: Deviated from redfish privilege registry for GET & HEAD
2674 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002675 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302676 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2677 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002678 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2679 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2680 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2681 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002682 }
2683
2684 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002685 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002686 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002687 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002688 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002689 if (params.size() != 1)
2690 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002691 messages::internalError(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002692 return;
2693 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002694 const std::string& logID = params[0];
Jason M. Billse855dd22019-10-08 11:37:48 -07002695 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2696 }
2697};
2698
2699class CrashdumpFile : public Node
2700{
2701 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002702 CrashdumpFile(App& app) :
Jason M. Billse855dd22019-10-08 11:37:48 -07002703 Node(app,
2704 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2705 "<str>/",
2706 std::string(), std::string())
2707 {
AppaRao Puli39460282020-04-07 17:03:04 +05302708 // Note: Deviated from redfish privilege registry for GET & HEAD
2709 // method for security reasons.
Jason M. Billse855dd22019-10-08 11:37:48 -07002710 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302711 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2712 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse855dd22019-10-08 11:37:48 -07002713 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2714 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2715 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2716 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2717 }
2718
2719 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002720 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002721 const std::vector<std::string>& params) override
Jason M. Billse855dd22019-10-08 11:37:48 -07002722 {
2723 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2724 if (params.size() != 2)
2725 {
2726 messages::internalError(asyncResp->res);
2727 return;
2728 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002729 const std::string& logID = params[0];
2730 const std::string& fileName = params[1];
Jason M. Billse855dd22019-10-08 11:37:48 -07002731
Johnathan Mantey043a0532020-03-10 17:15:28 -07002732 auto getStoredLogCallback =
2733 [asyncResp, logID, fileName](
2734 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002735 const std::vector<std::pair<std::string, VariantType>>& resp) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002736 if (ec)
2737 {
2738 BMCWEB_LOG_DEBUG << "failed to get log ec: "
2739 << ec.message();
2740 messages::internalError(asyncResp->res);
2741 return;
2742 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002743
Johnathan Mantey043a0532020-03-10 17:15:28 -07002744 std::string dbusFilename{};
2745 std::string dbusTimestamp{};
2746 std::string dbusFilepath{};
Jason M. Billse855dd22019-10-08 11:37:48 -07002747
Ed Tanous2c70f802020-09-28 14:29:23 -07002748 parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002749 dbusFilepath);
2750
2751 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2752 dbusFilepath.empty())
2753 {
2754 messages::resourceMissingAtURI(asyncResp->res, fileName);
2755 return;
2756 }
2757
2758 // Verify the file name parameter is correct
2759 if (fileName != dbusFilename)
2760 {
2761 messages::resourceMissingAtURI(asyncResp->res, fileName);
2762 return;
2763 }
2764
2765 if (!std::filesystem::exists(dbusFilepath))
2766 {
2767 messages::resourceMissingAtURI(asyncResp->res, fileName);
2768 return;
2769 }
2770 std::ifstream ifs(dbusFilepath, std::ios::in |
2771 std::ios::binary |
2772 std::ios::ate);
2773 std::ifstream::pos_type fileSize = ifs.tellg();
2774 if (fileSize < 0)
2775 {
2776 messages::generalError(asyncResp->res);
2777 return;
2778 }
2779 ifs.seekg(0, std::ios::beg);
2780
2781 auto crashData = std::make_unique<char[]>(
2782 static_cast<unsigned int>(fileSize));
2783
2784 ifs.read(crashData.get(), static_cast<int>(fileSize));
2785
2786 // The cast to std::string is intentional in order to use the
2787 // assign() that applies move mechanics
2788 asyncResp->res.body().assign(
2789 static_cast<std::string>(crashData.get()));
2790
2791 // Configure this to be a file download when accessed from
2792 // a browser
2793 asyncResp->res.addHeader("Content-Disposition", "attachment");
2794 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002795 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002796 std::move(getStoredLogCallback), crashdumpObject,
2797 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002798 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Ed Tanous1da66f72018-07-27 16:13:37 -07002799 }
2800};
2801
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002802class CrashdumpCollect : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002803{
2804 public:
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002805 CrashdumpCollect(App& app) :
2806 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2807 "LogService.CollectDiagnosticData/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002808 {
AppaRao Puli39460282020-04-07 17:03:04 +05302809 // Note: Deviated from redfish privilege registry for GET & HEAD
2810 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002811 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302812 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2813 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2814 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2815 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2816 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2817 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002818 }
2819
2820 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002821 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002822 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002823 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002824 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002825
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002826 std::string diagnosticDataType;
2827 std::string oemDiagnosticDataType;
2828 if (!redfish::json_util::readJson(
2829 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
2830 "OEMDiagnosticDataType", oemDiagnosticDataType))
2831 {
2832 return;
2833 }
2834
2835 if (diagnosticDataType != "OEM")
2836 {
2837 BMCWEB_LOG_ERROR
2838 << "Only OEM DiagnosticDataType supported for Crashdump";
2839 messages::actionParameterValueFormatError(
2840 asyncResp->res, diagnosticDataType, "DiagnosticDataType",
2841 "CollectDiagnosticData");
2842 return;
2843 }
2844
2845 auto collectCrashdumpCallback = [asyncResp, req](
2846 const boost::system::error_code ec,
2847 const std::string&) {
James Feist46229572020-02-19 15:11:58 -08002848 if (ec)
2849 {
2850 if (ec.value() == boost::system::errc::operation_not_supported)
Ed Tanous1da66f72018-07-27 16:13:37 -07002851 {
James Feist46229572020-02-19 15:11:58 -08002852 messages::resourceInStandby(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002853 }
James Feist46229572020-02-19 15:11:58 -08002854 else if (ec.value() ==
2855 boost::system::errc::device_or_resource_busy)
2856 {
2857 messages::serviceTemporarilyUnavailable(asyncResp->res,
2858 "60");
2859 }
2860 else
2861 {
2862 messages::internalError(asyncResp->res);
2863 }
2864 return;
2865 }
2866 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002867 [](boost::system::error_code err, sdbusplus::message::message&,
2868 const std::shared_ptr<task::TaskData>& taskData) {
James Feist66afe4f2020-02-24 13:09:58 -08002869 if (!err)
2870 {
James Feiste5d50062020-05-11 17:29:00 -07002871 taskData->messages.emplace_back(
2872 messages::taskCompletedOK(
2873 std::to_string(taskData->index)));
James Feist831d6b02020-03-12 16:31:30 -07002874 taskData->state = "Completed";
James Feist66afe4f2020-02-24 13:09:58 -08002875 }
James Feist32898ce2020-03-10 16:16:52 -07002876 return task::completed;
James Feist66afe4f2020-02-24 13:09:58 -08002877 },
James Feist46229572020-02-19 15:11:58 -08002878 "type='signal',interface='org.freedesktop.DBus.Properties',"
2879 "member='PropertiesChanged',arg0namespace='com.intel."
2880 "crashdump'");
2881 task->startTimer(std::chrono::minutes(5));
2882 task->populateResp(asyncResp->res);
James Feistfe306722020-03-12 16:32:08 -07002883 task->payload.emplace(req);
James Feist46229572020-02-19 15:11:58 -08002884 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002885
Jason M. Bills8e6c0992021-03-11 16:26:53 -08002886 if (oemDiagnosticDataType == "OnDemand")
2887 {
2888 crow::connections::systemBus->async_method_call(
2889 std::move(collectCrashdumpCallback), crashdumpObject,
2890 crashdumpPath, crashdumpOnDemandInterface,
2891 "GenerateOnDemandLog");
2892 }
2893 else if (oemDiagnosticDataType == "Telemetry")
2894 {
2895 crow::connections::systemBus->async_method_call(
2896 std::move(collectCrashdumpCallback), crashdumpObject,
2897 crashdumpPath, crashdumpTelemetryInterface,
2898 "GenerateTelemetryLog");
2899 }
2900 else
2901 {
2902 BMCWEB_LOG_ERROR << "Unsupported OEMDiagnosticDataType: "
2903 << oemDiagnosticDataType;
2904 messages::actionParameterValueFormatError(
2905 asyncResp->res, oemDiagnosticDataType, "OEMDiagnosticDataType",
2906 "CollectDiagnosticData");
2907 return;
2908 }
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002909 }
2910};
2911
Jason M. Billse1f26342018-07-18 12:12:00 -07002912class SendRawPECI : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002913{
2914 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002915 SendRawPECI(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002916 Node(app,
2917 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2918 "Crashdump.SendRawPeci/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002919 {
AppaRao Puli39460282020-04-07 17:03:04 +05302920 // Note: Deviated from redfish privilege registry for GET & HEAD
2921 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002922 entityPrivileges = {
2923 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2924 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2925 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2926 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2927 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2928 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2929 }
2930
2931 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002932 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002933 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002934 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002935 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002936 std::vector<std::vector<uint8_t>> peciCommands;
Ed Tanousb1556422018-10-16 14:09:17 -07002937
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002938 if (!json_util::readJson(req, res, "PECICommands", peciCommands))
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002939 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002940 return;
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002941 }
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002942 uint32_t idx = 0;
2943 for (auto const& cmd : peciCommands)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002944 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002945 if (cmd.size() < 3)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002946 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002947 std::string s("[");
2948 for (auto const& val : cmd)
2949 {
2950 if (val != *cmd.begin())
2951 {
2952 s += ",";
2953 }
2954 s += std::to_string(val);
2955 }
2956 s += "]";
2957 messages::actionParameterValueFormatError(
2958 res, s, "PECICommands[" + std::to_string(idx) + "]",
2959 "SendRawPeci");
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002960 return;
2961 }
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002962 idx++;
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002963 }
Ed Tanous1da66f72018-07-27 16:13:37 -07002964 // Callback to return the Raw PECI response
Jason M. Billse1f26342018-07-18 12:12:00 -07002965 auto sendRawPECICallback =
2966 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002967 const std::vector<std::vector<uint8_t>>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002968 if (ec)
2969 {
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002970 BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: "
Jason M. Billse1f26342018-07-18 12:12:00 -07002971 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002972 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002973 return;
2974 }
2975 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
2976 {"PECIResponse", resp}};
2977 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002978 // Call the SendRawPECI command with the provided data
2979 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002980 std::move(sendRawPECICallback), crashdumpObject, crashdumpPath,
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002981 crashdumpRawPECIInterface, "SendRawPeci", peciCommands);
Ed Tanous1da66f72018-07-27 16:13:37 -07002982 }
2983};
2984
Andrew Geisslercb92c032018-08-17 07:56:14 -07002985/**
2986 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
2987 */
2988class DBusLogServiceActionsClear : public Node
2989{
2990 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002991 DBusLogServiceActionsClear(App& app) :
Andrew Geisslercb92c032018-08-17 07:56:14 -07002992 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
Gunnar Mills7af91512020-04-14 22:16:57 -05002993 "LogService.ClearLog/")
Andrew Geisslercb92c032018-08-17 07:56:14 -07002994 {
2995 entityPrivileges = {
2996 {boost::beast::http::verb::get, {{"Login"}}},
2997 {boost::beast::http::verb::head, {{"Login"}}},
2998 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2999 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3000 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3001 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3002 }
3003
3004 private:
3005 /**
3006 * Function handles POST method request.
3007 * The Clear Log actions does not require any parameter.The action deletes
3008 * all entries found in the Entries collection for this Log Service.
3009 */
Ed Tanouscb13a392020-07-25 19:02:03 +00003010 void doPost(crow::Response& res, const crow::Request&,
3011 const std::vector<std::string>&) override
Andrew Geisslercb92c032018-08-17 07:56:14 -07003012 {
3013 BMCWEB_LOG_DEBUG << "Do delete all entries.";
3014
3015 auto asyncResp = std::make_shared<AsyncResp>(res);
3016 // Process response from Logging service.
Ed Tanous2c70f802020-09-28 14:29:23 -07003017 auto respHandler = [asyncResp](const boost::system::error_code ec) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07003018 BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3019 if (ec)
3020 {
3021 // TODO Handle for specific error code
3022 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3023 asyncResp->res.result(
3024 boost::beast::http::status::internal_server_error);
3025 return;
3026 }
3027
3028 asyncResp->res.result(boost::beast::http::status::no_content);
3029 };
3030
3031 // Make call to Logging service to request Clear Log
3032 crow::connections::systemBus->async_method_call(
Ed Tanous2c70f802020-09-28 14:29:23 -07003033 respHandler, "xyz.openbmc_project.Logging",
Andrew Geisslercb92c032018-08-17 07:56:14 -07003034 "/xyz/openbmc_project/logging",
3035 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3036 }
3037};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003038
3039/****************************************************
3040 * Redfish PostCode interfaces
3041 * using DBUS interface: getPostCodesTS
3042 ******************************************************/
3043class PostCodesLogService : public Node
3044{
3045 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003046 PostCodesLogService(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003047 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
3048 {
3049 entityPrivileges = {
3050 {boost::beast::http::verb::get, {{"Login"}}},
3051 {boost::beast::http::verb::head, {{"Login"}}},
3052 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3053 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3054 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3055 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3056 }
3057
3058 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003059 void doGet(crow::Response& res, const crow::Request&,
3060 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003061 {
3062 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3063
3064 asyncResp->res.jsonValue = {
3065 {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
3066 {"@odata.type", "#LogService.v1_1_0.LogService"},
ZhikuiRena3316fc2020-01-29 14:58:08 -08003067 {"Name", "POST Code Log Service"},
3068 {"Description", "POST Code Log Service"},
3069 {"Id", "BIOS POST Code Log"},
3070 {"OverWritePolicy", "WrapsWhenFull"},
3071 {"Entries",
3072 {{"@odata.id",
3073 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
3074 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
3075 {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
3076 "Actions/LogService.ClearLog"}};
3077 }
3078};
3079
3080class PostCodesClear : public Node
3081{
3082 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003083 PostCodesClear(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003084 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3085 "LogService.ClearLog/")
3086 {
3087 entityPrivileges = {
3088 {boost::beast::http::verb::get, {{"Login"}}},
3089 {boost::beast::http::verb::head, {{"Login"}}},
AppaRao Puli39460282020-04-07 17:03:04 +05303090 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
3091 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
3092 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
3093 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003094 }
3095
3096 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003097 void doPost(crow::Response& res, const crow::Request&,
3098 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003099 {
3100 BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3101
3102 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3103 // Make call to post-code service to request clear all
3104 crow::connections::systemBus->async_method_call(
3105 [asyncResp](const boost::system::error_code ec) {
3106 if (ec)
3107 {
3108 // TODO Handle for specific error code
3109 BMCWEB_LOG_ERROR
3110 << "doClearPostCodes resp_handler got error " << ec;
3111 asyncResp->res.result(
3112 boost::beast::http::status::internal_server_error);
3113 messages::internalError(asyncResp->res);
3114 return;
3115 }
3116 },
Jonathan Doman15124762021-01-07 17:54:17 -08003117 "xyz.openbmc_project.State.Boot.PostCode0",
3118 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003119 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3120 }
3121};
3122
3123static void fillPostCodeEntry(
Ed Tanousb5a76932020-09-29 16:16:58 -07003124 const std::shared_ptr<AsyncResp>& aResp,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303125 const boost::container::flat_map<
3126 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003127 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3128 const uint64_t skip = 0, const uint64_t top = 0)
3129{
3130 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003131 const message_registries::Message* message =
ZhikuiRena3316fc2020-01-29 14:58:08 -08003132 message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003133
3134 uint64_t currentCodeIndex = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003135 nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003136
3137 uint64_t firstCodeTimeUs = 0;
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303138 for (const std::pair<uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3139 code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003140 {
3141 currentCodeIndex++;
3142 std::string postcodeEntryID =
3143 "B" + std::to_string(bootIndex) + "-" +
3144 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3145
3146 uint64_t usecSinceEpoch = code.first;
3147 uint64_t usTimeOffset = 0;
3148
3149 if (1 == currentCodeIndex)
3150 { // already incremented
3151 firstCodeTimeUs = code.first;
3152 }
3153 else
3154 {
3155 usTimeOffset = code.first - firstCodeTimeUs;
3156 }
3157
3158 // skip if no specific codeIndex is specified and currentCodeIndex does
3159 // not fall between top and skip
3160 if ((codeIndex == 0) &&
3161 (currentCodeIndex <= skip || currentCodeIndex > top))
3162 {
3163 continue;
3164 }
3165
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003166 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003167 // currentIndex
3168 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3169 {
3170 // This is done for simplicity. 1st entry is needed to calculate
3171 // time offset. To improve efficiency, one can get to the entry
3172 // directly (possibly with flatmap's nth method)
3173 continue;
3174 }
3175
3176 // currentCodeIndex is within top and skip or equal to specified code
3177 // index
3178
3179 // Get the Created time from the timestamp
3180 std::string entryTimeStr;
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003181 entryTimeStr = crow::utility::getDateTime(
3182 static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003183
3184 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3185 std::ostringstream hexCode;
3186 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303187 << std::get<0>(code.second);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003188 std::ostringstream timeOffsetStr;
3189 // Set Fixed -Point Notation
3190 timeOffsetStr << std::fixed;
3191 // Set precision to 4 digits
3192 timeOffsetStr << std::setprecision(4);
3193 // Add double to stream
3194 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3195 std::vector<std::string> messageArgs = {
3196 std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3197
3198 // Get MessageArgs template from message registry
3199 std::string msg;
3200 if (message != nullptr)
3201 {
3202 msg = message->message;
3203
3204 // fill in this post code value
3205 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003206 for (const std::string& messageArg : messageArgs)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003207 {
3208 std::string argStr = "%" + std::to_string(++i);
3209 size_t argPos = msg.find(argStr);
3210 if (argPos != std::string::npos)
3211 {
3212 msg.replace(argPos, argStr.length(), messageArg);
3213 }
3214 }
3215 }
3216
Tim Leed4342a92020-04-27 11:47:58 +08003217 // Get Severity template from message registry
3218 std::string severity;
3219 if (message != nullptr)
3220 {
3221 severity = message->severity;
3222 }
3223
ZhikuiRena3316fc2020-01-29 14:58:08 -08003224 // add to AsyncResp
3225 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003226 nlohmann::json& bmcLogEntry = logEntryArray.back();
Gunnar Mills743e9a12020-10-26 12:44:53 -05003227 bmcLogEntry = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3228 {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3229 "PostCodes/Entries/" +
3230 postcodeEntryID},
3231 {"Name", "POST Code Log Entry"},
3232 {"Id", postcodeEntryID},
3233 {"Message", std::move(msg)},
3234 {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"},
3235 {"MessageArgs", std::move(messageArgs)},
3236 {"EntryType", "Event"},
3237 {"Severity", std::move(severity)},
3238 {"Created", entryTimeStr}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003239 }
3240}
3241
Ed Tanousb5a76932020-09-29 16:16:58 -07003242static void getPostCodeForEntry(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003243 const uint16_t bootIndex,
3244 const uint64_t codeIndex)
3245{
3246 crow::connections::systemBus->async_method_call(
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303247 [aResp, bootIndex,
3248 codeIndex](const boost::system::error_code ec,
3249 const boost::container::flat_map<
3250 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3251 postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003252 if (ec)
3253 {
3254 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3255 messages::internalError(aResp->res);
3256 return;
3257 }
3258
3259 // skip the empty postcode boots
3260 if (postcode.empty())
3261 {
3262 return;
3263 }
3264
3265 fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3266
3267 aResp->res.jsonValue["Members@odata.count"] =
3268 aResp->res.jsonValue["Members"].size();
3269 },
Jonathan Doman15124762021-01-07 17:54:17 -08003270 "xyz.openbmc_project.State.Boot.PostCode0",
3271 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003272 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3273 bootIndex);
3274}
3275
Ed Tanousb5a76932020-09-29 16:16:58 -07003276static void getPostCodeForBoot(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003277 const uint16_t bootIndex,
3278 const uint16_t bootCount,
3279 const uint64_t entryCount, const uint64_t skip,
3280 const uint64_t top)
3281{
3282 crow::connections::systemBus->async_method_call(
3283 [aResp, bootIndex, bootCount, entryCount, skip,
3284 top](const boost::system::error_code ec,
Manojkiran Eda6c9a2792021-02-27 14:25:04 +05303285 const boost::container::flat_map<
3286 uint64_t, std::tuple<uint64_t, std::vector<uint8_t>>>&
3287 postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003288 if (ec)
3289 {
3290 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3291 messages::internalError(aResp->res);
3292 return;
3293 }
3294
3295 uint64_t endCount = entryCount;
3296 if (!postcode.empty())
3297 {
3298 endCount = entryCount + postcode.size();
3299
3300 if ((skip < endCount) && ((top + skip) > entryCount))
3301 {
3302 uint64_t thisBootSkip =
3303 std::max(skip, entryCount) - entryCount;
3304 uint64_t thisBootTop =
3305 std::min(top + skip, endCount) - entryCount;
3306
3307 fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3308 thisBootSkip, thisBootTop);
3309 }
3310 aResp->res.jsonValue["Members@odata.count"] = endCount;
3311 }
3312
3313 // continue to previous bootIndex
3314 if (bootIndex < bootCount)
3315 {
3316 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3317 bootCount, endCount, skip, top);
3318 }
3319 else
3320 {
3321 aResp->res.jsonValue["Members@odata.nextLink"] =
3322 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3323 "Entries?$skip=" +
3324 std::to_string(skip + top);
3325 }
3326 },
Jonathan Doman15124762021-01-07 17:54:17 -08003327 "xyz.openbmc_project.State.Boot.PostCode0",
3328 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003329 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3330 bootIndex);
3331}
3332
Ed Tanousb5a76932020-09-29 16:16:58 -07003333static void getCurrentBootNumber(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003334 const uint64_t skip, const uint64_t top)
3335{
3336 uint64_t entryCount = 0;
3337 crow::connections::systemBus->async_method_call(
3338 [aResp, entryCount, skip,
3339 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003340 const std::variant<uint16_t>& bootCount) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003341 if (ec)
3342 {
3343 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3344 messages::internalError(aResp->res);
3345 return;
3346 }
3347 auto pVal = std::get_if<uint16_t>(&bootCount);
3348 if (pVal)
3349 {
3350 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3351 }
3352 else
3353 {
3354 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3355 }
3356 },
Jonathan Doman15124762021-01-07 17:54:17 -08003357 "xyz.openbmc_project.State.Boot.PostCode0",
3358 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003359 "org.freedesktop.DBus.Properties", "Get",
3360 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3361}
3362
3363class PostCodesEntryCollection : public Node
3364{
3365 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003366 PostCodesEntryCollection(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003367 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3368 {
3369 entityPrivileges = {
3370 {boost::beast::http::verb::get, {{"Login"}}},
3371 {boost::beast::http::verb::head, {{"Login"}}},
3372 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3373 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3374 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3375 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3376 }
3377
3378 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003379 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00003380 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003381 {
3382 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3383
3384 asyncResp->res.jsonValue["@odata.type"] =
3385 "#LogEntryCollection.LogEntryCollection";
ZhikuiRena3316fc2020-01-29 14:58:08 -08003386 asyncResp->res.jsonValue["@odata.id"] =
3387 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3388 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3389 asyncResp->res.jsonValue["Description"] =
3390 "Collection of POST Code Log Entries";
3391 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3392 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3393
3394 uint64_t skip = 0;
3395 uint64_t top = maxEntriesPerPage; // Show max entries by default
3396 if (!getSkipParam(asyncResp->res, req, skip))
3397 {
3398 return;
3399 }
3400 if (!getTopParam(asyncResp->res, req, top))
3401 {
3402 return;
3403 }
3404 getCurrentBootNumber(asyncResp, skip, top);
3405 }
3406};
3407
3408class PostCodesEntry : public Node
3409{
3410 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003411 PostCodesEntry(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003412 Node(app,
3413 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3414 std::string())
3415 {
3416 entityPrivileges = {
3417 {boost::beast::http::verb::get, {{"Login"}}},
3418 {boost::beast::http::verb::head, {{"Login"}}},
3419 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3420 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3421 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3422 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3423 }
3424
3425 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003426 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003427 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003428 {
3429 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3430 if (params.size() != 1)
3431 {
3432 messages::internalError(asyncResp->res);
3433 return;
3434 }
3435
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003436 const std::string& targetID = params[0];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003437
3438 size_t bootPos = targetID.find('B');
3439 if (bootPos == std::string::npos)
3440 {
3441 // Requested ID was not found
3442 messages::resourceMissingAtURI(asyncResp->res, targetID);
3443 return;
3444 }
3445 std::string_view bootIndexStr(targetID);
3446 bootIndexStr.remove_prefix(bootPos + 1);
3447 uint16_t bootIndex = 0;
3448 uint64_t codeIndex = 0;
3449 size_t dashPos = bootIndexStr.find('-');
3450
3451 if (dashPos == std::string::npos)
3452 {
3453 return;
3454 }
3455 std::string_view codeIndexStr(bootIndexStr);
3456 bootIndexStr.remove_suffix(dashPos);
3457 codeIndexStr.remove_prefix(dashPos + 1);
3458
3459 bootIndex = static_cast<uint16_t>(
Ed Tanous23a21a12020-07-25 04:45:05 +00003460 strtoul(std::string(bootIndexStr).c_str(), nullptr, 0));
3461 codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003462 if (bootIndex == 0 || codeIndex == 0)
3463 {
3464 BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3465 << params[0];
3466 }
3467
3468 asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
ZhikuiRena3316fc2020-01-29 14:58:08 -08003469 asyncResp->res.jsonValue["@odata.id"] =
3470 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3471 "Entries";
3472 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3473 asyncResp->res.jsonValue["Description"] =
3474 "Collection of POST Code Log Entries";
3475 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3476 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3477
3478 getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3479 }
3480};
3481
Ed Tanous1da66f72018-07-27 16:13:37 -07003482} // namespace redfish