blob: 883fc6914c6958099c9b2167385ac96cad863dd0 [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{
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500665 auto respHandler = [asyncResp](const boost::system::error_code ec) {
666 BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
667 if (ec)
668 {
669 BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
670 << ec;
671 messages::internalError(asyncResp->res);
672 return;
673 }
674 };
675 crow::connections::systemBus->async_method_call(
676 respHandler, "xyz.openbmc_project.Dump.Manager",
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500677 "/xyz/openbmc_project/dump/" +
678 std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" +
679 entryID,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500680 "xyz.openbmc_project.Object.Delete", "Delete");
681}
682
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500683inline void createDumpTaskCallback(const crow::Request& req,
Ed Tanousb5a76932020-09-29 16:16:58 -0700684 const std::shared_ptr<AsyncResp>& asyncResp,
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500685 const uint32_t& dumpId,
686 const std::string& dumpPath,
687 const std::string& dumpType)
688{
689 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500690 [dumpId, dumpPath, dumpType](
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500691 boost::system::error_code err, sdbusplus::message::message& m,
692 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000693 if (err)
694 {
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500695 BMCWEB_LOG_ERROR << "Error in creating a dump";
696 taskData->state = "Cancelled";
697 return task::completed;
Ed Tanouscb13a392020-07-25 19:02:03 +0000698 }
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500699 std::vector<std::pair<
700 std::string,
701 std::vector<std::pair<std::string, std::variant<std::string>>>>>
702 interfacesList;
703
704 sdbusplus::message::object_path objPath;
705
706 m.read(objPath, interfacesList);
707
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500708 if (objPath.str ==
709 "/xyz/openbmc_project/dump/" +
710 std::string(boost::algorithm::to_lower_copy(dumpType)) +
711 "/entry/" + std::to_string(dumpId))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500712 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500713 nlohmann::json retMessage = messages::success();
714 taskData->messages.emplace_back(retMessage);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500715
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500716 std::string headerLoc =
717 "Location: " + dumpPath + std::to_string(dumpId);
718 taskData->payload->httpHeaders.emplace_back(
719 std::move(headerLoc));
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500720
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500721 taskData->state = "Completed";
722 return task::completed;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500723 }
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500724 return task::completed;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500725 },
726 "type='signal',interface='org.freedesktop.DBus."
727 "ObjectManager',"
728 "member='InterfacesAdded', "
729 "path='/xyz/openbmc_project/dump'");
730
731 task->startTimer(std::chrono::minutes(3));
732 task->populateResp(asyncResp->res);
733 task->payload.emplace(req);
734}
735
736inline void createDump(crow::Response& res, const crow::Request& req,
737 const std::string& dumpType)
738{
739 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
740
741 std::string dumpPath;
742 if (dumpType == "BMC")
743 {
744 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
745 }
746 else if (dumpType == "System")
747 {
748 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
749 }
750 else
751 {
752 BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
753 messages::internalError(asyncResp->res);
754 return;
755 }
756
757 std::optional<std::string> diagnosticDataType;
758 std::optional<std::string> oemDiagnosticDataType;
759
760 if (!redfish::json_util::readJson(
761 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
762 "OEMDiagnosticDataType", oemDiagnosticDataType))
763 {
764 return;
765 }
766
767 if (dumpType == "System")
768 {
769 if (!oemDiagnosticDataType || !diagnosticDataType)
770 {
771 BMCWEB_LOG_ERROR << "CreateDump action parameter "
772 "'DiagnosticDataType'/"
773 "'OEMDiagnosticDataType' value not found!";
774 messages::actionParameterMissing(
775 asyncResp->res, "CollectDiagnosticData",
776 "DiagnosticDataType & OEMDiagnosticDataType");
777 return;
778 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700779 if ((*oemDiagnosticDataType != "System") ||
780 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500781 {
782 BMCWEB_LOG_ERROR << "Wrong parameter values passed";
783 messages::invalidObject(asyncResp->res,
784 "System Dump creation parameters");
785 return;
786 }
787 }
788 else if (dumpType == "BMC")
789 {
790 if (!diagnosticDataType)
791 {
792 BMCWEB_LOG_ERROR << "CreateDump action parameter "
793 "'DiagnosticDataType' not found!";
794 messages::actionParameterMissing(
795 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
796 return;
797 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700798 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500799 {
800 BMCWEB_LOG_ERROR
801 << "Wrong parameter value passed for 'DiagnosticDataType'";
802 messages::invalidObject(asyncResp->res,
803 "BMC Dump creation parameters");
804 return;
805 }
806 }
807
808 crow::connections::systemBus->async_method_call(
809 [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
810 const uint32_t& dumpId) {
811 if (ec)
812 {
813 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
814 messages::internalError(asyncResp->res);
815 return;
816 }
817 BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
818
819 createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
820 },
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500821 "xyz.openbmc_project.Dump.Manager",
822 "/xyz/openbmc_project/dump/" +
823 std::string(boost::algorithm::to_lower_copy(dumpType)),
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500824 "xyz.openbmc_project.Dump.Create", "CreateDump");
825}
826
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500827inline void clearDump(crow::Response& res, const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500828{
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500829 std::string dumpTypeLowerCopy =
830 std::string(boost::algorithm::to_lower_copy(dumpType));
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500831 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
832 crow::connections::systemBus->async_method_call(
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500833 [asyncResp, dumpType](const boost::system::error_code ec,
834 const std::vector<std::string>& subTreePaths) {
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500835 if (ec)
836 {
837 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
838 messages::internalError(asyncResp->res);
839 return;
840 }
841
842 for (const std::string& path : subTreePaths)
843 {
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000844 sdbusplus::message::object_path objPath(path);
845 std::string logID = objPath.filename();
846 if (logID.empty())
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500847 {
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000848 continue;
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500849 }
Ed Tanous2dfd18e2020-12-18 00:41:31 +0000850 deleteDumpEntry(asyncResp, logID, dumpType);
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500851 }
852 },
853 "xyz.openbmc_project.ObjectMapper",
854 "/xyz/openbmc_project/object_mapper",
855 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500856 "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0,
857 std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." +
858 dumpType});
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500859}
860
Ed Tanous2c70f802020-09-28 14:29:23 -0700861static void parseCrashdumpParameters(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500862 const std::vector<std::pair<std::string, VariantType>>& params,
863 std::string& filename, std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -0700864{
865 for (auto property : params)
866 {
867 if (property.first == "Timestamp")
868 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500869 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500870 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700871 if (value != nullptr)
872 {
873 timestamp = *value;
874 }
875 }
876 else if (property.first == "Filename")
877 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500878 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500879 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700880 if (value != nullptr)
881 {
882 filename = *value;
883 }
884 }
885 else if (property.first == "Log")
886 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500887 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500888 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700889 if (value != nullptr)
890 {
891 logfile = *value;
892 }
893 }
894 }
895}
896
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500897constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800898class SystemLogServiceCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -0700899{
900 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700901 SystemLogServiceCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800902 Node(app, "/redfish/v1/Systems/system/LogServices/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800903 {
904 entityPrivileges = {
905 {boost::beast::http::verb::get, {{"Login"}}},
906 {boost::beast::http::verb::head, {{"Login"}}},
907 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
908 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
909 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
910 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
911 }
912
913 private:
914 /**
915 * Functions triggers appropriate requests on DBus
916 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000917 void doGet(crow::Response& res, const crow::Request&,
918 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800919 {
920 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800921 // Collections don't include the static data added by SubRoute because
922 // it has a duplicate entry for members
923 asyncResp->res.jsonValue["@odata.type"] =
924 "#LogServiceCollection.LogServiceCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800925 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800926 "/redfish/v1/Systems/system/LogServices";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800927 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
928 asyncResp->res.jsonValue["Description"] =
929 "Collection of LogServices for this Computer System";
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500930 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800931 logServiceArray = nlohmann::json::array();
Ed Tanous029573d2019-02-01 10:57:49 -0800932 logServiceArray.push_back(
933 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500934#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
raviteja-bc9bb6862020-02-03 11:53:32 -0600935 logServiceArray.push_back(
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500936 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
raviteja-bc9bb6862020-02-03 11:53:32 -0600937#endif
938
Jason M. Billsd53dd412019-02-12 17:16:22 -0800939#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
940 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -0500941 {{"@odata.id",
942 "/redfish/v1/Systems/system/LogServices/Crashdump"}});
Jason M. Billsd53dd412019-02-12 17:16:22 -0800943#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800944 asyncResp->res.jsonValue["Members@odata.count"] =
945 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800946
947 crow::connections::systemBus->async_method_call(
948 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500949 const std::vector<std::string>& subtreePath) {
ZhikuiRena3316fc2020-01-29 14:58:08 -0800950 if (ec)
951 {
952 BMCWEB_LOG_ERROR << ec;
953 return;
954 }
955
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500956 for (auto& pathStr : subtreePath)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800957 {
958 if (pathStr.find("PostCode") != std::string::npos)
959 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000960 nlohmann::json& logServiceArrayLocal =
ZhikuiRena3316fc2020-01-29 14:58:08 -0800961 asyncResp->res.jsonValue["Members"];
Ed Tanous23a21a12020-07-25 04:45:05 +0000962 logServiceArrayLocal.push_back(
ZhikuiRena3316fc2020-01-29 14:58:08 -0800963 {{"@odata.id", "/redfish/v1/Systems/system/"
964 "LogServices/PostCodes"}});
965 asyncResp->res.jsonValue["Members@odata.count"] =
Ed Tanous23a21a12020-07-25 04:45:05 +0000966 logServiceArrayLocal.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800967 return;
968 }
969 }
970 },
971 "xyz.openbmc_project.ObjectMapper",
972 "/xyz/openbmc_project/object_mapper",
973 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500974 std::array<const char*, 1>{postCodeIface});
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800975 }
976};
977
978class EventLogService : public Node
979{
980 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700981 EventLogService(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800982 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800983 {
984 entityPrivileges = {
985 {boost::beast::http::verb::get, {{"Login"}}},
986 {boost::beast::http::verb::head, {{"Login"}}},
987 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
988 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
989 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
990 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
991 }
992
993 private:
Ed Tanouscb13a392020-07-25 19:02:03 +0000994 void doGet(crow::Response& res, const crow::Request&,
995 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800996 {
997 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
998
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800999 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001000 "/redfish/v1/Systems/system/LogServices/EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001001 asyncResp->res.jsonValue["@odata.type"] =
1002 "#LogService.v1_1_0.LogService";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001003 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1004 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
Gunnar Mills73ec8302020-04-14 16:02:42 -05001005 asyncResp->res.jsonValue["Id"] = "EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001006 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1007 asyncResp->res.jsonValue["Entries"] = {
1008 {"@odata.id",
Ed Tanous029573d2019-02-01 10:57:49 -08001009 "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
Gunnar Millse7d6c8b2019-07-03 11:30:01 -05001010 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1011
1012 {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1013 "Actions/LogService.ClearLog"}};
Jason M. Bills489640c2019-05-17 09:56:36 -07001014 }
1015};
1016
Tim Lee1f56a3a2019-10-09 10:17:57 +08001017class JournalEventLogClear : public Node
Jason M. Bills489640c2019-05-17 09:56:36 -07001018{
1019 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001020 JournalEventLogClear(App& app) :
Jason M. Bills489640c2019-05-17 09:56:36 -07001021 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1022 "LogService.ClearLog/")
1023 {
1024 entityPrivileges = {
1025 {boost::beast::http::verb::get, {{"Login"}}},
1026 {boost::beast::http::verb::head, {{"Login"}}},
1027 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1028 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1029 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1030 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1031 }
1032
1033 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001034 void doPost(crow::Response& res, const crow::Request&,
1035 const std::vector<std::string>&) override
Jason M. Bills489640c2019-05-17 09:56:36 -07001036 {
1037 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1038
1039 // Clear the EventLog by deleting the log files
1040 std::vector<std::filesystem::path> redfishLogFiles;
1041 if (getRedfishLogFiles(redfishLogFiles))
1042 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001043 for (const std::filesystem::path& file : redfishLogFiles)
Jason M. Bills489640c2019-05-17 09:56:36 -07001044 {
1045 std::error_code ec;
1046 std::filesystem::remove(file, ec);
1047 }
1048 }
1049
1050 // Reload rsyslog so it knows to start new log files
1051 crow::connections::systemBus->async_method_call(
1052 [asyncResp](const boost::system::error_code ec) {
1053 if (ec)
1054 {
1055 BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1056 messages::internalError(asyncResp->res);
1057 return;
1058 }
1059
1060 messages::success(asyncResp->res);
1061 },
1062 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1063 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1064 "replace");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001065 }
1066};
1067
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001068static int fillEventLogEntryJson(const std::string& logEntryID,
Ed Tanousb5a76932020-09-29 16:16:58 -07001069 const std::string& logEntry,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001070 nlohmann::json& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001071{
Jason M. Bills95820182019-04-22 16:25:34 -07001072 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001073 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001074 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001075 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001076 {
1077 return 1;
1078 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001079 std::string timestamp = logEntry.substr(0, space);
1080 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001081 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001082 if (entryStart == std::string::npos)
1083 {
1084 return 1;
1085 }
1086 std::string_view entry(logEntry);
1087 entry.remove_prefix(entryStart);
1088 // Use split to separate the entry into its fields
1089 std::vector<std::string> logEntryFields;
1090 boost::split(logEntryFields, entry, boost::is_any_of(","),
1091 boost::token_compress_on);
1092 // We need at least a MessageId to be valid
1093 if (logEntryFields.size() < 1)
1094 {
1095 return 1;
1096 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001097 std::string& messageID = logEntryFields[0];
Jason M. Bills95820182019-04-22 16:25:34 -07001098
Jason M. Bills4851d452019-03-28 11:27:48 -07001099 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001100 const message_registries::Message* message =
Jason M. Bills4851d452019-03-28 11:27:48 -07001101 message_registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001102
Jason M. Bills4851d452019-03-28 11:27:48 -07001103 std::string msg;
1104 std::string severity;
1105 if (message != nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001106 {
Jason M. Bills4851d452019-03-28 11:27:48 -07001107 msg = message->message;
1108 severity = message->severity;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001109 }
1110
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001111 // Get the MessageArgs from the log if there are any
1112 boost::beast::span<std::string> messageArgs;
1113 if (logEntryFields.size() > 1)
Jason M. Bills4851d452019-03-28 11:27:48 -07001114 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001115 std::string& messageArgsStart = logEntryFields[1];
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001116 // If the first string is empty, assume there are no MessageArgs
1117 std::size_t messageArgsSize = 0;
1118 if (!messageArgsStart.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001119 {
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001120 messageArgsSize = logEntryFields.size() - 1;
1121 }
1122
Ed Tanous23a21a12020-07-25 04:45:05 +00001123 messageArgs = {&messageArgsStart, messageArgsSize};
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001124
1125 // Fill the MessageArgs into the Message
1126 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001127 for (const std::string& messageArg : messageArgs)
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001128 {
1129 std::string argStr = "%" + std::to_string(++i);
1130 size_t argPos = msg.find(argStr);
1131 if (argPos != std::string::npos)
1132 {
1133 msg.replace(argPos, argStr.length(), messageArg);
1134 }
Jason M. Bills4851d452019-03-28 11:27:48 -07001135 }
1136 }
1137
Jason M. Bills95820182019-04-22 16:25:34 -07001138 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1139 // format which matches the Redfish format except for the fractional seconds
1140 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001141 std::size_t dot = timestamp.find_first_of('.');
1142 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001143 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001144 {
Jason M. Bills95820182019-04-22 16:25:34 -07001145 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001146 }
1147
1148 // Fill in the log entry with the gathered data
Jason M. Bills95820182019-04-22 16:25:34 -07001149 logEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001150 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Ed Tanous029573d2019-02-01 10:57:49 -08001151 {"@odata.id",
Jason M. Bills897967d2019-07-29 17:05:30 -07001152 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
Jason M. Bills95820182019-04-22 16:25:34 -07001153 logEntryID},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001154 {"Name", "System Event Log Entry"},
Jason M. Bills95820182019-04-22 16:25:34 -07001155 {"Id", logEntryID},
1156 {"Message", std::move(msg)},
1157 {"MessageId", std::move(messageID)},
Ed Tanousf23b7292020-10-15 09:41:17 -07001158 {"MessageArgs", messageArgs},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001159 {"EntryType", "Event"},
Jason M. Bills95820182019-04-22 16:25:34 -07001160 {"Severity", std::move(severity)},
1161 {"Created", std::move(timestamp)}};
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001162 return 0;
1163}
1164
Anthony Wilson27062602019-04-22 02:10:09 -05001165class JournalEventLogEntryCollection : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001166{
1167 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001168 JournalEventLogEntryCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001169 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001170 {
1171 entityPrivileges = {
1172 {boost::beast::http::verb::get, {{"Login"}}},
1173 {boost::beast::http::verb::head, {{"Login"}}},
1174 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1175 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1176 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1177 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1178 }
1179
1180 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001181 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001182 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001183 {
1184 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous271584a2019-07-09 16:24:22 -07001185 uint64_t skip = 0;
1186 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001187 if (!getSkipParam(asyncResp->res, req, skip))
1188 {
1189 return;
1190 }
1191 if (!getTopParam(asyncResp->res, req, top))
1192 {
1193 return;
1194 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001195 // Collections don't include the static data added by SubRoute because
1196 // it has a duplicate entry for members
1197 asyncResp->res.jsonValue["@odata.type"] =
1198 "#LogEntryCollection.LogEntryCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001199 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001200 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001201 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1202 asyncResp->res.jsonValue["Description"] =
1203 "Collection of System Event Log Entries";
Andrew Geisslercb92c032018-08-17 07:56:14 -07001204
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001205 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001206 logEntryArray = nlohmann::json::array();
Jason M. Bills95820182019-04-22 16:25:34 -07001207 // Go through the log files and create a unique ID for each entry
1208 std::vector<std::filesystem::path> redfishLogFiles;
1209 getRedfishLogFiles(redfishLogFiles);
Ed Tanousb01bf292019-03-25 19:25:26 +00001210 uint64_t entryCount = 0;
Jason M. Billscd225da2019-05-08 15:31:57 -07001211 std::string logEntry;
Jason M. Bills95820182019-04-22 16:25:34 -07001212
1213 // Oldest logs are in the last file, so start there and loop backwards
Jason M. Billscd225da2019-05-08 15:31:57 -07001214 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1215 it++)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001216 {
Jason M. Billscd225da2019-05-08 15:31:57 -07001217 std::ifstream logStream(*it);
Jason M. Bills95820182019-04-22 16:25:34 -07001218 if (!logStream.is_open())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001219 {
1220 continue;
1221 }
1222
Jason M. Billse85d6b12019-07-29 17:01:15 -07001223 // Reset the unique ID on the first entry
1224 bool firstEntry = true;
Jason M. Bills95820182019-04-22 16:25:34 -07001225 while (std::getline(logStream, logEntry))
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001226 {
Jason M. Bills95820182019-04-22 16:25:34 -07001227 entryCount++;
1228 // Handle paging using skip (number of entries to skip from the
1229 // start) and top (number of entries to display)
1230 if (entryCount <= skip || entryCount > skip + top)
1231 {
1232 continue;
1233 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001234
Jason M. Bills95820182019-04-22 16:25:34 -07001235 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001236 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Jason M. Bills95820182019-04-22 16:25:34 -07001237 {
1238 continue;
1239 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001240
Jason M. Billse85d6b12019-07-29 17:01:15 -07001241 if (firstEntry)
1242 {
1243 firstEntry = false;
1244 }
1245
Jason M. Bills95820182019-04-22 16:25:34 -07001246 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001247 nlohmann::json& bmcLogEntry = logEntryArray.back();
Jason M. Bills95820182019-04-22 16:25:34 -07001248 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
1249 {
1250 messages::internalError(asyncResp->res);
1251 return;
1252 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001253 }
1254 }
1255 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1256 if (skip + top < entryCount)
1257 {
1258 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Bills95820182019-04-22 16:25:34 -07001259 "/redfish/v1/Systems/system/LogServices/EventLog/"
1260 "Entries?$skip=" +
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001261 std::to_string(skip + top);
1262 }
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001263 }
1264};
1265
Jason M. Bills897967d2019-07-29 17:05:30 -07001266class JournalEventLogEntry : public Node
1267{
1268 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001269 JournalEventLogEntry(App& app) :
Jason M. Bills897967d2019-07-29 17:05:30 -07001270 Node(app,
1271 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1272 std::string())
1273 {
1274 entityPrivileges = {
1275 {boost::beast::http::verb::get, {{"Login"}}},
1276 {boost::beast::http::verb::head, {{"Login"}}},
1277 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1278 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1279 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1280 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1281 }
1282
1283 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001284 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001285 const std::vector<std::string>& params) override
Jason M. Bills897967d2019-07-29 17:05:30 -07001286 {
1287 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1288 if (params.size() != 1)
1289 {
1290 messages::internalError(asyncResp->res);
1291 return;
1292 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001293 const std::string& targetID = params[0];
Jason M. Bills897967d2019-07-29 17:05:30 -07001294
1295 // Go through the log files and check the unique ID for each entry to
1296 // find the target entry
1297 std::vector<std::filesystem::path> redfishLogFiles;
1298 getRedfishLogFiles(redfishLogFiles);
1299 std::string logEntry;
1300
1301 // Oldest logs are in the last file, so start there and loop backwards
1302 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1303 it++)
1304 {
1305 std::ifstream logStream(*it);
1306 if (!logStream.is_open())
1307 {
1308 continue;
1309 }
1310
1311 // Reset the unique ID on the first entry
1312 bool firstEntry = true;
1313 while (std::getline(logStream, logEntry))
1314 {
1315 std::string idStr;
1316 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1317 {
1318 continue;
1319 }
1320
1321 if (firstEntry)
1322 {
1323 firstEntry = false;
1324 }
1325
1326 if (idStr == targetID)
1327 {
1328 if (fillEventLogEntryJson(idStr, logEntry,
1329 asyncResp->res.jsonValue) != 0)
1330 {
1331 messages::internalError(asyncResp->res);
1332 return;
1333 }
1334 return;
1335 }
1336 }
1337 }
1338 // Requested ID was not found
1339 messages::resourceMissingAtURI(asyncResp->res, targetID);
1340 }
1341};
1342
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001343class DBusEventLogEntryCollection : public Node
1344{
1345 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001346 DBusEventLogEntryCollection(App& app) :
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001347 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1348 {
1349 entityPrivileges = {
1350 {boost::beast::http::verb::get, {{"Login"}}},
1351 {boost::beast::http::verb::head, {{"Login"}}},
1352 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1353 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1354 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1355 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1356 }
1357
1358 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001359 void doGet(crow::Response& res, const crow::Request&,
1360 const std::vector<std::string>&) override
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001361 {
1362 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1363
1364 // Collections don't include the static data added by SubRoute because
1365 // it has a duplicate entry for members
1366 asyncResp->res.jsonValue["@odata.type"] =
1367 "#LogEntryCollection.LogEntryCollection";
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001368 asyncResp->res.jsonValue["@odata.id"] =
1369 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1370 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1371 asyncResp->res.jsonValue["Description"] =
1372 "Collection of System Event Log Entries";
1373
Andrew Geisslercb92c032018-08-17 07:56:14 -07001374 // DBus implementation of EventLog/Entries
1375 // Make call to Logging Service to find all log entry objects
1376 crow::connections::systemBus->async_method_call(
1377 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001378 GetManagedObjectsType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001379 if (ec)
1380 {
1381 // TODO Handle for specific error code
1382 BMCWEB_LOG_ERROR
1383 << "getLogEntriesIfaceData resp_handler got error "
1384 << ec;
1385 messages::internalError(asyncResp->res);
1386 return;
1387 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001388 nlohmann::json& entriesArray =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001389 asyncResp->res.jsonValue["Members"];
1390 entriesArray = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001391 for (auto& objectPath : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001392 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001393 for (auto& interfaceMap : objectPath.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001394 {
1395 if (interfaceMap.first !=
1396 "xyz.openbmc_project.Logging.Entry")
1397 {
1398 BMCWEB_LOG_DEBUG << "Bailing early on "
1399 << interfaceMap.first;
1400 continue;
1401 }
1402 entriesArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001403 nlohmann::json& thisEntry = entriesArray.back();
1404 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001405 std::time_t timestamp{};
George Liud139c232020-08-18 18:48:57 +08001406 std::time_t updateTimestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001407 std::string* severity = nullptr;
1408 std::string* message = nullptr;
Xiaochao Ma75710de2021-01-21 17:56:02 +08001409 bool resolved = false;
George Liud139c232020-08-18 18:48:57 +08001410
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001411 for (auto& propertyMap : interfaceMap.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001412 {
1413 if (propertyMap.first == "Id")
1414 {
Patrick Williams8d78b7a2020-05-13 11:24:20 -05001415 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001416 }
1417 else if (propertyMap.first == "Timestamp")
1418 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001419 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001420 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001421 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001422 {
1423 timestamp = crow::utility::getTimestamp(
1424 *millisTimeStamp);
1425 }
George Liud139c232020-08-18 18:48:57 +08001426 }
1427 else if (propertyMap.first == "UpdateTimestamp")
1428 {
1429 const uint64_t* millisTimeStamp =
1430 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001431 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001432 {
1433 updateTimestamp =
1434 crow::utility::getTimestamp(
1435 *millisTimeStamp);
1436 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001437 }
1438 else if (propertyMap.first == "Severity")
1439 {
1440 severity = std::get_if<std::string>(
1441 &propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001442 }
1443 else if (propertyMap.first == "Message")
1444 {
1445 message = std::get_if<std::string>(
1446 &propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001447 }
Xiaochao Ma75710de2021-01-21 17:56:02 +08001448 else if (propertyMap.first == "Resolved")
1449 {
1450 bool* resolveptr =
1451 std::get_if<bool>(&propertyMap.second);
1452 if (resolveptr == nullptr)
1453 {
1454 messages::internalError(asyncResp->res);
1455 return;
1456 }
1457 resolved = *resolveptr;
1458 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001459 }
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001460 if (id == nullptr || message == nullptr ||
1461 severity == nullptr)
1462 {
1463 messages::internalError(asyncResp->res);
1464 return;
1465 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001466 thisEntry = {
Xiaochao Ma75710de2021-01-21 17:56:02 +08001467 {"@odata.type", "#LogEntry.v1_8_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001468 {"@odata.id",
1469 "/redfish/v1/Systems/system/LogServices/EventLog/"
1470 "Entries/" +
1471 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001472 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001473 {"Id", std::to_string(*id)},
1474 {"Message", *message},
Xiaochao Ma75710de2021-01-21 17:56:02 +08001475 {"Resolved", resolved},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001476 {"EntryType", "Event"},
1477 {"Severity",
1478 translateSeverityDbusToRedfish(*severity)},
George Liud139c232020-08-18 18:48:57 +08001479 {"Created", crow::utility::getDateTime(timestamp)},
1480 {"Modified",
1481 crow::utility::getDateTime(updateTimestamp)}};
Andrew Geisslercb92c032018-08-17 07:56:14 -07001482 }
1483 }
1484 std::sort(entriesArray.begin(), entriesArray.end(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001485 [](const nlohmann::json& left,
1486 const nlohmann::json& right) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001487 return (left["Id"] <= right["Id"]);
1488 });
1489 asyncResp->res.jsonValue["Members@odata.count"] =
1490 entriesArray.size();
1491 },
1492 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
1493 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001494 }
1495};
1496
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001497class DBusEventLogEntry : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001498{
1499 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001500 DBusEventLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001501 Node(app,
Ed Tanous029573d2019-02-01 10:57:49 -08001502 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1503 std::string())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001504 {
1505 entityPrivileges = {
1506 {boost::beast::http::verb::get, {{"Login"}}},
1507 {boost::beast::http::verb::head, {{"Login"}}},
1508 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1509 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1510 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1511 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1512 }
1513
1514 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001515 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001516 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001517 {
1518 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous029573d2019-02-01 10:57:49 -08001519 if (params.size() != 1)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001520 {
1521 messages::internalError(asyncResp->res);
1522 return;
1523 }
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001524 std::string entryID = params[0];
1525 dbus::utility::escapePathForDbus(entryID);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001526
Andrew Geisslercb92c032018-08-17 07:56:14 -07001527 // DBus implementation of EventLog/Entries
1528 // Make call to Logging Service to find all log entry objects
1529 crow::connections::systemBus->async_method_call(
1530 [asyncResp, entryID](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001531 GetManagedPropertyType& resp) {
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001532 if (ec.value() == EBADR)
1533 {
1534 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1535 entryID);
1536 return;
1537 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001538 if (ec)
1539 {
1540 BMCWEB_LOG_ERROR
1541 << "EventLogEntry (DBus) resp_handler got error " << ec;
1542 messages::internalError(asyncResp->res);
1543 return;
1544 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001545 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001546 std::time_t timestamp{};
George Liud139c232020-08-18 18:48:57 +08001547 std::time_t updateTimestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001548 std::string* severity = nullptr;
1549 std::string* message = nullptr;
Xiaochao Ma75710de2021-01-21 17:56:02 +08001550 bool resolved = false;
George Liud139c232020-08-18 18:48:57 +08001551
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001552 for (auto& propertyMap : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001553 {
1554 if (propertyMap.first == "Id")
1555 {
1556 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001557 }
1558 else if (propertyMap.first == "Timestamp")
1559 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001560 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001561 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001562 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001563 {
1564 timestamp =
1565 crow::utility::getTimestamp(*millisTimeStamp);
1566 }
George Liud139c232020-08-18 18:48:57 +08001567 }
1568 else if (propertyMap.first == "UpdateTimestamp")
1569 {
1570 const uint64_t* millisTimeStamp =
1571 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001572 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001573 {
1574 updateTimestamp =
1575 crow::utility::getTimestamp(*millisTimeStamp);
1576 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001577 }
1578 else if (propertyMap.first == "Severity")
1579 {
1580 severity =
1581 std::get_if<std::string>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001582 }
1583 else if (propertyMap.first == "Message")
1584 {
1585 message = std::get_if<std::string>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001586 }
Xiaochao Ma75710de2021-01-21 17:56:02 +08001587 else if (propertyMap.first == "Resolved")
1588 {
1589 bool* resolveptr =
1590 std::get_if<bool>(&propertyMap.second);
1591 if (resolveptr == nullptr)
1592 {
1593 messages::internalError(asyncResp->res);
1594 return;
1595 }
1596 resolved = *resolveptr;
1597 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001598 }
Ed Tanous271584a2019-07-09 16:24:22 -07001599 if (id == nullptr || message == nullptr || severity == nullptr)
1600 {
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001601 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001602 return;
1603 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001604 asyncResp->res.jsonValue = {
Xiaochao Ma75710de2021-01-21 17:56:02 +08001605 {"@odata.type", "#LogEntry.v1_8_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001606 {"@odata.id",
1607 "/redfish/v1/Systems/system/LogServices/EventLog/"
1608 "Entries/" +
1609 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001610 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001611 {"Id", std::to_string(*id)},
1612 {"Message", *message},
Xiaochao Ma75710de2021-01-21 17:56:02 +08001613 {"Resolved", resolved},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001614 {"EntryType", "Event"},
1615 {"Severity", translateSeverityDbusToRedfish(*severity)},
George Liud139c232020-08-18 18:48:57 +08001616 {"Created", crow::utility::getDateTime(timestamp)},
1617 {"Modified", crow::utility::getDateTime(updateTimestamp)}};
Andrew Geisslercb92c032018-08-17 07:56:14 -07001618 },
1619 "xyz.openbmc_project.Logging",
1620 "/xyz/openbmc_project/logging/entry/" + entryID,
1621 "org.freedesktop.DBus.Properties", "GetAll",
1622 "xyz.openbmc_project.Logging.Entry");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001623 }
Chicago Duan336e96c2019-07-15 14:22:08 +08001624
Xiaochao Ma75710de2021-01-21 17:56:02 +08001625 void doPatch(crow::Response& res, const crow::Request& req,
1626 const std::vector<std::string>& params) override
1627 {
1628 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1629
1630 if (params.size() != 1)
1631 {
1632 messages::internalError(asyncResp->res);
1633 return;
1634 }
1635 std::string entryId = params[0];
1636
1637 std::optional<bool> resolved;
1638
1639 if (!json_util::readJson(req, res, "Resolved", resolved))
1640 {
1641 return;
1642 }
1643
1644 if (resolved)
1645 {
1646 BMCWEB_LOG_DEBUG << "Set Resolved";
1647
1648 crow::connections::systemBus->async_method_call(
1649 [asyncResp, resolved,
1650 entryId](const boost::system::error_code ec) {
1651 if (ec)
1652 {
1653 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
1654 messages::internalError(asyncResp->res);
1655 return;
1656 }
1657 },
1658 "xyz.openbmc_project.Logging",
1659 "/xyz/openbmc_project/logging/entry/" + entryId,
1660 "org.freedesktop.DBus.Properties", "Set",
1661 "xyz.openbmc_project.Logging.Entry", "Resolved",
1662 std::variant<bool>(*resolved));
1663 }
1664 }
1665
Ed Tanouscb13a392020-07-25 19:02:03 +00001666 void doDelete(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001667 const std::vector<std::string>& params) override
Chicago Duan336e96c2019-07-15 14:22:08 +08001668 {
1669
1670 BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1671
1672 auto asyncResp = std::make_shared<AsyncResp>(res);
1673
1674 if (params.size() != 1)
1675 {
1676 messages::internalError(asyncResp->res);
1677 return;
1678 }
1679 std::string entryID = params[0];
1680
1681 dbus::utility::escapePathForDbus(entryID);
1682
1683 // Process response from Logging service.
1684 auto respHandler = [asyncResp](const boost::system::error_code ec) {
1685 BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1686 if (ec)
1687 {
1688 // TODO Handle for specific error code
1689 BMCWEB_LOG_ERROR
1690 << "EventLogEntry (DBus) doDelete respHandler got error "
1691 << ec;
1692 asyncResp->res.result(
1693 boost::beast::http::status::internal_server_error);
1694 return;
1695 }
1696
1697 asyncResp->res.result(boost::beast::http::status::ok);
1698 };
1699
1700 // Make call to Logging service to request Delete Log
1701 crow::connections::systemBus->async_method_call(
1702 respHandler, "xyz.openbmc_project.Logging",
1703 "/xyz/openbmc_project/logging/entry/" + entryID,
1704 "xyz.openbmc_project.Object.Delete", "Delete");
1705 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001706};
1707
1708class BMCLogServiceCollection : public Node
1709{
1710 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001711 BMCLogServiceCollection(App& app) :
Ed Tanous4ed77cd2018-10-15 08:08:07 -07001712 Node(app, "/redfish/v1/Managers/bmc/LogServices/")
Ed Tanous1da66f72018-07-27 16:13:37 -07001713 {
Ed Tanous1da66f72018-07-27 16:13:37 -07001714 entityPrivileges = {
Jason M. Billse1f26342018-07-18 12:12:00 -07001715 {boost::beast::http::verb::get, {{"Login"}}},
1716 {boost::beast::http::verb::head, {{"Login"}}},
1717 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1718 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1719 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1720 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07001721 }
1722
1723 private:
1724 /**
1725 * Functions triggers appropriate requests on DBus
1726 */
Ed Tanouscb13a392020-07-25 19:02:03 +00001727 void doGet(crow::Response& res, const crow::Request&,
1728 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07001729 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001730 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07001731 // Collections don't include the static data added by SubRoute because
1732 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07001733 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001734 "#LogServiceCollection.LogServiceCollection";
Jason M. Billse1f26342018-07-18 12:12:00 -07001735 asyncResp->res.jsonValue["@odata.id"] =
1736 "/redfish/v1/Managers/bmc/LogServices";
1737 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1738 asyncResp->res.jsonValue["Description"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001739 "Collection of LogServices for this Manager";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001740 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001741 logServiceArray = nlohmann::json::array();
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001742#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
1743 logServiceArray.push_back(
1744 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}});
1745#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001746#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
1747 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001748 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001749#endif
Jason M. Billse1f26342018-07-18 12:12:00 -07001750 asyncResp->res.jsonValue["Members@odata.count"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001751 logServiceArray.size();
Ed Tanous1da66f72018-07-27 16:13:37 -07001752 }
1753};
1754
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001755class BMCJournalLogService : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07001756{
1757 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001758 BMCJournalLogService(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001759 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001760 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001761 entityPrivileges = {
1762 {boost::beast::http::verb::get, {{"Login"}}},
1763 {boost::beast::http::verb::head, {{"Login"}}},
1764 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1765 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1766 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1767 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1768 }
1769
1770 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001771 void doGet(crow::Response& res, const crow::Request&,
1772 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001773 {
1774 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001775 asyncResp->res.jsonValue["@odata.type"] =
1776 "#LogService.v1_1_0.LogService";
Ed Tanous0f74e642018-11-12 15:17:05 -08001777 asyncResp->res.jsonValue["@odata.id"] =
1778 "/redfish/v1/Managers/bmc/LogServices/Journal";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001779 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1780 asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1781 asyncResp->res.jsonValue["Id"] = "BMC Journal";
Jason M. Billse1f26342018-07-18 12:12:00 -07001782 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
Jason M. Billscd50aa42019-02-12 17:09:02 -08001783 asyncResp->res.jsonValue["Entries"] = {
1784 {"@odata.id",
Ed Tanous086be232019-05-23 11:47:09 -07001785 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07001786 }
1787};
1788
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001789static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1790 sd_journal* journal,
1791 nlohmann::json& bmcJournalLogEntryJson)
Jason M. Billse1f26342018-07-18 12:12:00 -07001792{
1793 // Get the Log Entry contents
1794 int ret = 0;
Jason M. Billse1f26342018-07-18 12:12:00 -07001795
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001796 std::string message;
1797 std::string_view syslogID;
1798 ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID);
1799 if (ret < 0)
1800 {
1801 BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: "
1802 << strerror(-ret);
1803 }
1804 if (!syslogID.empty())
1805 {
1806 message += std::string(syslogID) + ": ";
1807 }
1808
Ed Tanous39e77502019-03-04 17:35:53 -08001809 std::string_view msg;
Jason M. Bills16428a12018-11-02 12:42:29 -07001810 ret = getJournalMetadata(journal, "MESSAGE", msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001811 if (ret < 0)
1812 {
1813 BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1814 return 1;
1815 }
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001816 message += std::string(msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001817
1818 // Get the severity from the PRIORITY field
Ed Tanous271584a2019-07-09 16:24:22 -07001819 long int severity = 8; // Default to an invalid priority
Jason M. Bills16428a12018-11-02 12:42:29 -07001820 ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
Jason M. Billse1f26342018-07-18 12:12:00 -07001821 if (ret < 0)
1822 {
1823 BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
Jason M. Billse1f26342018-07-18 12:12:00 -07001824 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001825
1826 // Get the Created time from the timestamp
Jason M. Bills16428a12018-11-02 12:42:29 -07001827 std::string entryTimeStr;
1828 if (!getEntryTimestamp(journal, entryTimeStr))
Jason M. Billse1f26342018-07-18 12:12:00 -07001829 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001830 return 1;
Jason M. Billse1f26342018-07-18 12:12:00 -07001831 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001832
1833 // Fill in the log entry with the gathered data
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001834 bmcJournalLogEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001835 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001836 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
1837 bmcJournalLogEntryID},
Jason M. Billse1f26342018-07-18 12:12:00 -07001838 {"Name", "BMC Journal Entry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001839 {"Id", bmcJournalLogEntryID},
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001840 {"Message", std::move(message)},
Jason M. Billse1f26342018-07-18 12:12:00 -07001841 {"EntryType", "Oem"},
Patrick Williams738c1e62021-02-22 17:14:25 -06001842 {"Severity", severity <= 2 ? "Critical"
1843 : severity <= 4 ? "Warning"
1844 : "OK"},
Ed Tanous086be232019-05-23 11:47:09 -07001845 {"OemRecordFormat", "BMC Journal Entry"},
Jason M. Billse1f26342018-07-18 12:12:00 -07001846 {"Created", std::move(entryTimeStr)}};
1847 return 0;
1848}
1849
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001850class BMCJournalLogEntryCollection : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001851{
1852 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001853 BMCJournalLogEntryCollection(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001854 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001855 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001856 entityPrivileges = {
1857 {boost::beast::http::verb::get, {{"Login"}}},
1858 {boost::beast::http::verb::head, {{"Login"}}},
1859 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1860 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1861 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1862 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1863 }
1864
1865 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001866 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001867 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001868 {
1869 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001870 static constexpr const long maxEntriesPerPage = 1000;
Ed Tanous271584a2019-07-09 16:24:22 -07001871 uint64_t skip = 0;
1872 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Bills16428a12018-11-02 12:42:29 -07001873 if (!getSkipParam(asyncResp->res, req, skip))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001874 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001875 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001876 }
Jason M. Bills16428a12018-11-02 12:42:29 -07001877 if (!getTopParam(asyncResp->res, req, top))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001878 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001879 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001880 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001881 // Collections don't include the static data added by SubRoute because
1882 // it has a duplicate entry for members
1883 asyncResp->res.jsonValue["@odata.type"] =
1884 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08001885 asyncResp->res.jsonValue["@odata.id"] =
1886 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001887 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001888 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001889 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
1890 asyncResp->res.jsonValue["Description"] =
1891 "Collection of BMC Journal Entries";
Ed Tanous0f74e642018-11-12 15:17:05 -08001892 asyncResp->res.jsonValue["@odata.id"] =
1893 "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001894 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07001895 logEntryArray = nlohmann::json::array();
1896
1897 // Go through the journal and use the timestamp to create a unique ID
1898 // for each entry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001899 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001900 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1901 if (ret < 0)
1902 {
1903 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001904 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001905 return;
1906 }
1907 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1908 journalTmp, sd_journal_close);
1909 journalTmp = nullptr;
Ed Tanousb01bf292019-03-25 19:25:26 +00001910 uint64_t entryCount = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001911 // Reset the unique ID on the first entry
1912 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001913 SD_JOURNAL_FOREACH(journal.get())
1914 {
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001915 entryCount++;
1916 // Handle paging using skip (number of entries to skip from the
1917 // start) and top (number of entries to display)
1918 if (entryCount <= skip || entryCount > skip + top)
1919 {
1920 continue;
1921 }
1922
Jason M. Bills16428a12018-11-02 12:42:29 -07001923 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001924 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
Jason M. Billse1f26342018-07-18 12:12:00 -07001925 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001926 continue;
1927 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001928
Jason M. Billse85d6b12019-07-29 17:01:15 -07001929 if (firstEntry)
1930 {
1931 firstEntry = false;
1932 }
1933
Jason M. Billse1f26342018-07-18 12:12:00 -07001934 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001935 nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001936 if (fillBMCJournalLogEntryJson(idStr, journal.get(),
1937 bmcJournalLogEntry) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001938 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001939 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001940 return;
1941 }
1942 }
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001943 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1944 if (skip + top < entryCount)
1945 {
1946 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001947 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001948 std::to_string(skip + top);
1949 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001950 }
1951};
1952
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001953class BMCJournalLogEntry : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001954{
1955 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001956 BMCJournalLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001957 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
Jason M. Billse1f26342018-07-18 12:12:00 -07001958 std::string())
1959 {
1960 entityPrivileges = {
1961 {boost::beast::http::verb::get, {{"Login"}}},
1962 {boost::beast::http::verb::head, {{"Login"}}},
1963 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1964 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1965 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1966 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1967 }
1968
1969 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001970 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001971 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001972 {
1973 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1974 if (params.size() != 1)
1975 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001976 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001977 return;
1978 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001979 const std::string& entryID = params[0];
Jason M. Billse1f26342018-07-18 12:12:00 -07001980 // Convert the unique ID back to a timestamp to find the entry
Jason M. Billse1f26342018-07-18 12:12:00 -07001981 uint64_t ts = 0;
Ed Tanous271584a2019-07-09 16:24:22 -07001982 uint64_t index = 0;
Jason M. Bills16428a12018-11-02 12:42:29 -07001983 if (!getTimestampFromID(asyncResp->res, entryID, ts, index))
Jason M. Billse1f26342018-07-18 12:12:00 -07001984 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001985 return;
Jason M. Billse1f26342018-07-18 12:12:00 -07001986 }
1987
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001988 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001989 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1990 if (ret < 0)
1991 {
1992 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001993 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001994 return;
1995 }
1996 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1997 journalTmp, sd_journal_close);
1998 journalTmp = nullptr;
1999 // Go to the timestamp in the log and move to the entry at the index
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002000 // tracking the unique ID
2001 std::string idStr;
2002 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07002003 ret = sd_journal_seek_realtime_usec(journal.get(), ts);
Manojkiran Eda2056b6d2020-05-28 08:57:36 +05302004 if (ret < 0)
2005 {
2006 BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
2007 << strerror(-ret);
2008 messages::internalError(asyncResp->res);
2009 return;
2010 }
Ed Tanous271584a2019-07-09 16:24:22 -07002011 for (uint64_t i = 0; i <= index; i++)
Jason M. Billse1f26342018-07-18 12:12:00 -07002012 {
2013 sd_journal_next(journal.get());
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002014 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
2015 {
2016 messages::internalError(asyncResp->res);
2017 return;
2018 }
2019 if (firstEntry)
2020 {
2021 firstEntry = false;
2022 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002023 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002024 // Confirm that the entry ID matches what was requested
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07002025 if (idStr != entryID)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08002026 {
2027 messages::resourceMissingAtURI(asyncResp->res, entryID);
2028 return;
2029 }
2030
2031 if (fillBMCJournalLogEntryJson(entryID, journal.get(),
2032 asyncResp->res.jsonValue) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07002033 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002034 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002035 return;
2036 }
2037 }
2038};
2039
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002040class BMCDumpService : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002041{
2042 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002043 BMCDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002044 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002045 {
2046 entityPrivileges = {
2047 {boost::beast::http::verb::get, {{"Login"}}},
2048 {boost::beast::http::verb::head, {{"Login"}}},
2049 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2050 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2051 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2052 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2053 }
2054
2055 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002056 void doGet(crow::Response& res, const crow::Request&,
2057 const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002058 {
2059 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2060
2061 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002062 "/redfish/v1/Managers/bmc/LogServices/Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002063 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002064 "#LogService.v1_2_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002065 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2066 asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
2067 asyncResp->res.jsonValue["Id"] = "Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002068 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
raviteja-bc9bb6862020-02-03 11:53:32 -06002069 asyncResp->res.jsonValue["Entries"] = {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002070 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
2071 asyncResp->res.jsonValue["Actions"] = {
2072 {"#LogService.ClearLog",
2073 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2074 "Actions/LogService.ClearLog"}}},
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002075 {"#LogService.CollectDiagnosticData",
2076 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2077 "Actions/LogService.CollectDiagnosticData"}}}};
raviteja-bc9bb6862020-02-03 11:53:32 -06002078 }
2079};
2080
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002081class BMCDumpEntryCollection : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002082{
2083 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002084 BMCDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002085 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002086 {
2087 entityPrivileges = {
2088 {boost::beast::http::verb::get, {{"Login"}}},
2089 {boost::beast::http::verb::head, {{"Login"}}},
2090 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2091 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2092 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2093 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2094 }
2095
2096 private:
2097 /**
2098 * Functions triggers appropriate requests on DBus
2099 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002100 void doGet(crow::Response& res, const crow::Request&,
2101 const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002102 {
2103 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2104
2105 asyncResp->res.jsonValue["@odata.type"] =
2106 "#LogEntryCollection.LogEntryCollection";
2107 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002108 "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
2109 asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002110 asyncResp->res.jsonValue["Description"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002111 "Collection of BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002112
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002113 getDumpEntryCollection(asyncResp, "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002114 }
2115};
2116
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002117class BMCDumpEntry : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002118{
2119 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002120 BMCDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002121 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
raviteja-bc9bb6862020-02-03 11:53:32 -06002122 std::string())
2123 {
2124 entityPrivileges = {
2125 {boost::beast::http::verb::get, {{"Login"}}},
2126 {boost::beast::http::verb::head, {{"Login"}}},
2127 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2128 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2129 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2130 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2131 }
2132
2133 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002134 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002135 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002136 {
2137 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2138 if (params.size() != 1)
2139 {
2140 messages::internalError(asyncResp->res);
2141 return;
2142 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002143 getDumpEntryById(asyncResp, params[0], "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002144 }
2145
Ed Tanouscb13a392020-07-25 19:02:03 +00002146 void doDelete(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002147 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002148 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002149 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002150 if (params.size() != 1)
2151 {
2152 messages::internalError(asyncResp->res);
2153 return;
2154 }
Stanley Chu98782562020-11-04 16:10:24 +08002155 deleteDumpEntry(asyncResp, params[0], "bmc");
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002156 }
2157};
raviteja-bc9bb6862020-02-03 11:53:32 -06002158
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002159class BMCDumpCreate : public Node
2160{
2161 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002162 BMCDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002163 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002164 "Actions/"
2165 "LogService.CollectDiagnosticData/")
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002166 {
2167 entityPrivileges = {
2168 {boost::beast::http::verb::get, {{"Login"}}},
2169 {boost::beast::http::verb::head, {{"Login"}}},
2170 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2171 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2172 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2173 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2174 }
2175
2176 private:
2177 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002178 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002179 {
2180 createDump(res, req, "BMC");
2181 }
2182};
2183
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002184class BMCDumpClear : public Node
2185{
2186 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002187 BMCDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002188 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2189 "Actions/"
2190 "LogService.ClearLog/")
2191 {
2192 entityPrivileges = {
2193 {boost::beast::http::verb::get, {{"Login"}}},
2194 {boost::beast::http::verb::head, {{"Login"}}},
2195 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2196 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2197 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2198 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2199 }
2200
2201 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002202 void doPost(crow::Response& res, const crow::Request&,
2203 const std::vector<std::string>&) override
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002204 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -05002205 clearDump(res, "BMC");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002206 }
2207};
2208
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002209class SystemDumpService : public Node
2210{
2211 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002212 SystemDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002213 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
2214 {
2215 entityPrivileges = {
2216 {boost::beast::http::verb::get, {{"Login"}}},
2217 {boost::beast::http::verb::head, {{"Login"}}},
2218 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2219 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2220 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2221 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2222 }
raviteja-bc9bb6862020-02-03 11:53:32 -06002223
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002224 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002225 void doGet(crow::Response& res, const crow::Request&,
2226 const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002227 {
2228 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002229
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002230 asyncResp->res.jsonValue["@odata.id"] =
2231 "/redfish/v1/Systems/system/LogServices/Dump";
2232 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002233 "#LogService.v1_2_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002234 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2235 asyncResp->res.jsonValue["Description"] = "System Dump LogService";
2236 asyncResp->res.jsonValue["Id"] = "Dump";
2237 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2238 asyncResp->res.jsonValue["Entries"] = {
2239 {"@odata.id",
2240 "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
2241 asyncResp->res.jsonValue["Actions"] = {
2242 {"#LogService.ClearLog",
2243 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2244 "LogService.ClearLog"}}},
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002245 {"#LogService.CollectDiagnosticData",
2246 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2247 "LogService.CollectDiagnosticData"}}}};
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002248 }
2249};
2250
2251class SystemDumpEntryCollection : public Node
2252{
2253 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002254 SystemDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002255 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
2256 {
2257 entityPrivileges = {
2258 {boost::beast::http::verb::get, {{"Login"}}},
2259 {boost::beast::http::verb::head, {{"Login"}}},
2260 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2261 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2262 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2263 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2264 }
2265
2266 private:
2267 /**
2268 * Functions triggers appropriate requests on DBus
2269 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002270 void doGet(crow::Response& res, const crow::Request&,
2271 const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002272 {
2273 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2274
2275 asyncResp->res.jsonValue["@odata.type"] =
2276 "#LogEntryCollection.LogEntryCollection";
2277 asyncResp->res.jsonValue["@odata.id"] =
2278 "/redfish/v1/Systems/system/LogServices/Dump/Entries";
2279 asyncResp->res.jsonValue["Name"] = "System Dump Entries";
2280 asyncResp->res.jsonValue["Description"] =
2281 "Collection of System Dump Entries";
2282
2283 getDumpEntryCollection(asyncResp, "System");
2284 }
2285};
2286
2287class SystemDumpEntry : public Node
2288{
2289 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002290 SystemDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002291 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
2292 std::string())
2293 {
2294 entityPrivileges = {
2295 {boost::beast::http::verb::get, {{"Login"}}},
2296 {boost::beast::http::verb::head, {{"Login"}}},
2297 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2298 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2299 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2300 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2301 }
2302
2303 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002304 void doGet(crow::Response& res, const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002305 const std::vector<std::string>& params) override
2306 {
2307 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2308 if (params.size() != 1)
2309 {
2310 messages::internalError(asyncResp->res);
2311 return;
2312 }
2313 getDumpEntryById(asyncResp, params[0], "System");
2314 }
2315
Ed Tanouscb13a392020-07-25 19:02:03 +00002316 void doDelete(crow::Response& res, const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002317 const std::vector<std::string>& params) override
2318 {
2319 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2320 if (params.size() != 1)
2321 {
2322 messages::internalError(asyncResp->res);
2323 return;
2324 }
Stanley Chu98782562020-11-04 16:10:24 +08002325 deleteDumpEntry(asyncResp, params[0], "system");
raviteja-bc9bb6862020-02-03 11:53:32 -06002326 }
2327};
2328
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002329class SystemDumpCreate : public Node
2330{
2331 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002332 SystemDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002333 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002334 "Actions/"
2335 "LogService.CollectDiagnosticData/")
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002336 {
2337 entityPrivileges = {
2338 {boost::beast::http::verb::get, {{"Login"}}},
2339 {boost::beast::http::verb::head, {{"Login"}}},
2340 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2341 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2342 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2343 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2344 }
2345
2346 private:
2347 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002348 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002349 {
2350 createDump(res, req, "System");
2351 }
2352};
2353
raviteja-b013487e2020-03-03 03:20:48 -06002354class SystemDumpClear : public Node
2355{
2356 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002357 SystemDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002358 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
raviteja-b013487e2020-03-03 03:20:48 -06002359 "Actions/"
2360 "LogService.ClearLog/")
2361 {
2362 entityPrivileges = {
2363 {boost::beast::http::verb::get, {{"Login"}}},
2364 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002365 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2366 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2367 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b013487e2020-03-03 03:20:48 -06002368 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2369 }
2370
2371 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002372 void doPost(crow::Response& res, const crow::Request&,
2373 const std::vector<std::string>&) override
raviteja-b013487e2020-03-03 03:20:48 -06002374 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -05002375 clearDump(res, "System");
raviteja-b013487e2020-03-03 03:20:48 -06002376 }
2377};
2378
Jason M. Bills424c4172019-03-21 13:50:33 -07002379class CrashdumpService : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002380{
2381 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002382 CrashdumpService(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002383 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002384 {
AppaRao Puli39460282020-04-07 17:03:04 +05302385 // Note: Deviated from redfish privilege registry for GET & HEAD
2386 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002387 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302388 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2389 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002390 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2391 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2392 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2393 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002394 }
2395
2396 private:
2397 /**
2398 * Functions triggers appropriate requests on DBus
2399 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002400 void doGet(crow::Response& res, const crow::Request&,
2401 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002402 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002403 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002404 // Copy over the static data to include the entries added by SubRoute
Ed Tanous0f74e642018-11-12 15:17:05 -08002405 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002406 "/redfish/v1/Systems/system/LogServices/Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002407 asyncResp->res.jsonValue["@odata.type"] =
2408 "#LogService.v1_1_0.LogService";
Gunnar Mills4f50ae42020-02-06 15:29:57 -06002409 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2410 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2411 asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002412 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2413 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Jason M. Billscd50aa42019-02-12 17:09:02 -08002414 asyncResp->res.jsonValue["Entries"] = {
2415 {"@odata.id",
Jason M. Bills424c4172019-03-21 13:50:33 -07002416 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07002417 asyncResp->res.jsonValue["Actions"] = {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002418 {"#LogService.ClearLog",
2419 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2420 "Actions/LogService.ClearLog"}}},
Ed Tanous1da66f72018-07-27 16:13:37 -07002421 {"Oem",
Jason M. Bills424c4172019-03-21 13:50:33 -07002422 {{"#Crashdump.OnDemand",
2423 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002424 "Actions/Oem/Crashdump.OnDemand"}}},
2425 {"#Crashdump.Telemetry",
2426 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2427 "Actions/Oem/Crashdump.Telemetry"}}}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002428
2429#ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
Jason M. Billse1f26342018-07-18 12:12:00 -07002430 asyncResp->res.jsonValue["Actions"]["Oem"].push_back(
Jason M. Bills424c4172019-03-21 13:50:33 -07002431 {"#Crashdump.SendRawPeci",
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05002432 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2433 "Actions/Oem/Crashdump.SendRawPeci"}}});
Ed Tanous1da66f72018-07-27 16:13:37 -07002434#endif
Ed Tanous1da66f72018-07-27 16:13:37 -07002435 }
2436};
2437
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002438class CrashdumpClear : public Node
2439{
2440 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002441 CrashdumpClear(App& app) :
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002442 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2443 "LogService.ClearLog/")
2444 {
AppaRao Puli39460282020-04-07 17:03:04 +05302445 // Note: Deviated from redfish privilege registry for GET & HEAD
2446 // method for security reasons.
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002447 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302448 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2449 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002450 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2451 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2452 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2453 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2454 }
2455
2456 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002457 void doPost(crow::Response& res, const crow::Request&,
2458 const std::vector<std::string>&) override
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002459 {
2460 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2461
2462 crow::connections::systemBus->async_method_call(
2463 [asyncResp](const boost::system::error_code ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002464 const std::string&) {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002465 if (ec)
2466 {
2467 messages::internalError(asyncResp->res);
2468 return;
2469 }
2470 messages::success(asyncResp->res);
2471 },
2472 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
2473 }
2474};
2475
Ed Tanousb5a76932020-09-29 16:16:58 -07002476static void logCrashdumpEntry(const std::shared_ptr<AsyncResp>& asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002477 const std::string& logID,
2478 nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002479{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002480 auto getStoredLogCallback =
2481 [asyncResp, logID, &logEntryJson](
2482 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002483 const std::vector<std::pair<std::string, VariantType>>& params) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002484 if (ec)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002485 {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002486 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
2487 if (ec.value() ==
2488 boost::system::linux_error::bad_request_descriptor)
2489 {
2490 messages::resourceNotFound(asyncResp->res, "LogEntry",
2491 logID);
2492 }
2493 else
2494 {
2495 messages::internalError(asyncResp->res);
2496 }
2497 return;
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002498 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002499
Johnathan Mantey043a0532020-03-10 17:15:28 -07002500 std::string timestamp{};
2501 std::string filename{};
2502 std::string logfile{};
Ed Tanous2c70f802020-09-28 14:29:23 -07002503 parseCrashdumpParameters(params, filename, timestamp, logfile);
Johnathan Mantey043a0532020-03-10 17:15:28 -07002504
2505 if (filename.empty() || timestamp.empty())
2506 {
2507 messages::resourceMissingAtURI(asyncResp->res, logID);
2508 return;
2509 }
2510
2511 std::string crashdumpURI =
2512 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2513 logID + "/" + filename;
2514 logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
2515 {"@odata.id", "/redfish/v1/Systems/system/"
2516 "LogServices/Crashdump/Entries/" +
2517 logID},
2518 {"Name", "CPU Crashdump"},
2519 {"Id", logID},
2520 {"EntryType", "Oem"},
2521 {"OemRecordFormat", "Crashdump URI"},
2522 {"Message", std::move(crashdumpURI)},
2523 {"Created", std::move(timestamp)}};
2524 };
Jason M. Billse855dd22019-10-08 11:37:48 -07002525 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002526 std::move(getStoredLogCallback), crashdumpObject,
2527 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002528 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Jason M. Billse855dd22019-10-08 11:37:48 -07002529}
2530
Jason M. Bills424c4172019-03-21 13:50:33 -07002531class CrashdumpEntryCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002532{
2533 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002534 CrashdumpEntryCollection(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002535 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002536 {
AppaRao Puli39460282020-04-07 17:03:04 +05302537 // Note: Deviated from redfish privilege registry for GET & HEAD
2538 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002539 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302540 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2541 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002542 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2543 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2544 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2545 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002546 }
2547
2548 private:
2549 /**
2550 * Functions triggers appropriate requests on DBus
2551 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002552 void doGet(crow::Response& res, const crow::Request&,
2553 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002554 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002555 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002556 // Collections don't include the static data added by SubRoute because
2557 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07002558 auto getLogEntriesCallback = [asyncResp](
2559 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002560 const std::vector<std::string>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002561 if (ec)
2562 {
2563 if (ec.value() !=
2564 boost::system::errc::no_such_file_or_directory)
Ed Tanous1da66f72018-07-27 16:13:37 -07002565 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002566 BMCWEB_LOG_DEBUG << "failed to get entries ec: "
2567 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002568 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002569 return;
Ed Tanous1da66f72018-07-27 16:13:37 -07002570 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002571 }
2572 asyncResp->res.jsonValue["@odata.type"] =
2573 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08002574 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002575 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
Jason M. Bills424c4172019-03-21 13:50:33 -07002576 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002577 asyncResp->res.jsonValue["Description"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002578 "Collection of Crashdump Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002579 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07002580 logEntryArray = nlohmann::json::array();
Jason M. Billse855dd22019-10-08 11:37:48 -07002581 std::vector<std::string> logIDs;
2582 // Get the list of log entries and build up an empty array big
2583 // enough to hold them
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002584 for (const std::string& objpath : resp)
Jason M. Billse1f26342018-07-18 12:12:00 -07002585 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002586 // Get the log ID
Ed Tanousf23b7292020-10-15 09:41:17 -07002587 std::size_t lastPos = objpath.rfind('/');
Jason M. Billse855dd22019-10-08 11:37:48 -07002588 if (lastPos == std::string::npos)
Jason M. Billse1f26342018-07-18 12:12:00 -07002589 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002590 continue;
Jason M. Billse1f26342018-07-18 12:12:00 -07002591 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002592 logIDs.emplace_back(objpath.substr(lastPos + 1));
2593
2594 // Add a space for the log entry to the array
2595 logEntryArray.push_back({});
2596 }
2597 // Now go through and set up async calls to fill in the entries
2598 size_t index = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002599 for (const std::string& logID : logIDs)
Jason M. Billse855dd22019-10-08 11:37:48 -07002600 {
2601 // Add the log entry to the array
2602 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
Jason M. Billse1f26342018-07-18 12:12:00 -07002603 }
2604 asyncResp->res.jsonValue["Members@odata.count"] =
2605 logEntryArray.size();
2606 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002607 crow::connections::systemBus->async_method_call(
2608 std::move(getLogEntriesCallback),
2609 "xyz.openbmc_project.ObjectMapper",
2610 "/xyz/openbmc_project/object_mapper",
2611 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002612 std::array<const char*, 1>{crashdumpInterface});
Ed Tanous1da66f72018-07-27 16:13:37 -07002613 }
2614};
2615
Jason M. Bills424c4172019-03-21 13:50:33 -07002616class CrashdumpEntry : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002617{
2618 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002619 CrashdumpEntry(App& app) :
Jason M. Billsd53dd412019-02-12 17:16:22 -08002620 Node(app,
Jason M. Bills424c4172019-03-21 13:50:33 -07002621 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
Ed Tanous1da66f72018-07-27 16:13:37 -07002622 std::string())
2623 {
AppaRao Puli39460282020-04-07 17:03:04 +05302624 // Note: Deviated from redfish privilege registry for GET & HEAD
2625 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002626 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302627 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2628 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002629 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2630 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2631 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2632 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002633 }
2634
2635 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002636 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002637 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002638 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002639 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002640 if (params.size() != 1)
2641 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002642 messages::internalError(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002643 return;
2644 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002645 const std::string& logID = params[0];
Jason M. Billse855dd22019-10-08 11:37:48 -07002646 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2647 }
2648};
2649
2650class CrashdumpFile : public Node
2651{
2652 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002653 CrashdumpFile(App& app) :
Jason M. Billse855dd22019-10-08 11:37:48 -07002654 Node(app,
2655 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2656 "<str>/",
2657 std::string(), std::string())
2658 {
AppaRao Puli39460282020-04-07 17:03:04 +05302659 // Note: Deviated from redfish privilege registry for GET & HEAD
2660 // method for security reasons.
Jason M. Billse855dd22019-10-08 11:37:48 -07002661 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302662 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2663 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse855dd22019-10-08 11:37:48 -07002664 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2665 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2666 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2667 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2668 }
2669
2670 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002671 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002672 const std::vector<std::string>& params) override
Jason M. Billse855dd22019-10-08 11:37:48 -07002673 {
2674 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2675 if (params.size() != 2)
2676 {
2677 messages::internalError(asyncResp->res);
2678 return;
2679 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002680 const std::string& logID = params[0];
2681 const std::string& fileName = params[1];
Jason M. Billse855dd22019-10-08 11:37:48 -07002682
Johnathan Mantey043a0532020-03-10 17:15:28 -07002683 auto getStoredLogCallback =
2684 [asyncResp, logID, fileName](
2685 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002686 const std::vector<std::pair<std::string, VariantType>>& resp) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002687 if (ec)
2688 {
2689 BMCWEB_LOG_DEBUG << "failed to get log ec: "
2690 << ec.message();
2691 messages::internalError(asyncResp->res);
2692 return;
2693 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002694
Johnathan Mantey043a0532020-03-10 17:15:28 -07002695 std::string dbusFilename{};
2696 std::string dbusTimestamp{};
2697 std::string dbusFilepath{};
Jason M. Billse855dd22019-10-08 11:37:48 -07002698
Ed Tanous2c70f802020-09-28 14:29:23 -07002699 parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002700 dbusFilepath);
2701
2702 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2703 dbusFilepath.empty())
2704 {
2705 messages::resourceMissingAtURI(asyncResp->res, fileName);
2706 return;
2707 }
2708
2709 // Verify the file name parameter is correct
2710 if (fileName != dbusFilename)
2711 {
2712 messages::resourceMissingAtURI(asyncResp->res, fileName);
2713 return;
2714 }
2715
2716 if (!std::filesystem::exists(dbusFilepath))
2717 {
2718 messages::resourceMissingAtURI(asyncResp->res, fileName);
2719 return;
2720 }
2721 std::ifstream ifs(dbusFilepath, std::ios::in |
2722 std::ios::binary |
2723 std::ios::ate);
2724 std::ifstream::pos_type fileSize = ifs.tellg();
2725 if (fileSize < 0)
2726 {
2727 messages::generalError(asyncResp->res);
2728 return;
2729 }
2730 ifs.seekg(0, std::ios::beg);
2731
2732 auto crashData = std::make_unique<char[]>(
2733 static_cast<unsigned int>(fileSize));
2734
2735 ifs.read(crashData.get(), static_cast<int>(fileSize));
2736
2737 // The cast to std::string is intentional in order to use the
2738 // assign() that applies move mechanics
2739 asyncResp->res.body().assign(
2740 static_cast<std::string>(crashData.get()));
2741
2742 // Configure this to be a file download when accessed from
2743 // a browser
2744 asyncResp->res.addHeader("Content-Disposition", "attachment");
2745 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002746 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002747 std::move(getStoredLogCallback), crashdumpObject,
2748 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002749 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Ed Tanous1da66f72018-07-27 16:13:37 -07002750 }
2751};
2752
Jason M. Bills424c4172019-03-21 13:50:33 -07002753class OnDemandCrashdump : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002754{
2755 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002756 OnDemandCrashdump(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002757 Node(app,
2758 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2759 "Crashdump.OnDemand/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002760 {
AppaRao Puli39460282020-04-07 17:03:04 +05302761 // Note: Deviated from redfish privilege registry for GET & HEAD
2762 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002763 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302764 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2765 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2766 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2767 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2768 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2769 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002770 }
2771
2772 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002773 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002774 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002775 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002776 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002777
James Feistfe306722020-03-12 16:32:08 -07002778 auto generateonDemandLogCallback = [asyncResp,
2779 req](const boost::system::error_code
2780 ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002781 const std::string&) {
James Feist46229572020-02-19 15:11:58 -08002782 if (ec)
2783 {
2784 if (ec.value() == boost::system::errc::operation_not_supported)
Ed Tanous1da66f72018-07-27 16:13:37 -07002785 {
James Feist46229572020-02-19 15:11:58 -08002786 messages::resourceInStandby(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002787 }
James Feist46229572020-02-19 15:11:58 -08002788 else if (ec.value() ==
2789 boost::system::errc::device_or_resource_busy)
2790 {
2791 messages::serviceTemporarilyUnavailable(asyncResp->res,
2792 "60");
2793 }
2794 else
2795 {
2796 messages::internalError(asyncResp->res);
2797 }
2798 return;
2799 }
2800 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002801 [](boost::system::error_code err, sdbusplus::message::message&,
2802 const std::shared_ptr<task::TaskData>& taskData) {
James Feist66afe4f2020-02-24 13:09:58 -08002803 if (!err)
2804 {
James Feiste5d50062020-05-11 17:29:00 -07002805 taskData->messages.emplace_back(
2806 messages::taskCompletedOK(
2807 std::to_string(taskData->index)));
James Feist831d6b02020-03-12 16:31:30 -07002808 taskData->state = "Completed";
James Feist66afe4f2020-02-24 13:09:58 -08002809 }
James Feist32898ce2020-03-10 16:16:52 -07002810 return task::completed;
James Feist66afe4f2020-02-24 13:09:58 -08002811 },
James Feist46229572020-02-19 15:11:58 -08002812 "type='signal',interface='org.freedesktop.DBus.Properties',"
2813 "member='PropertiesChanged',arg0namespace='com.intel."
2814 "crashdump'");
2815 task->startTimer(std::chrono::minutes(5));
2816 task->populateResp(asyncResp->res);
James Feistfe306722020-03-12 16:32:08 -07002817 task->payload.emplace(req);
James Feist46229572020-02-19 15:11:58 -08002818 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002819 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002820 std::move(generateonDemandLogCallback), crashdumpObject,
2821 crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog");
Ed Tanous1da66f72018-07-27 16:13:37 -07002822 }
2823};
2824
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002825class TelemetryCrashdump : public Node
2826{
2827 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002828 TelemetryCrashdump(App& app) :
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002829 Node(app,
2830 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2831 "Crashdump.Telemetry/")
2832 {
2833 // Note: Deviated from redfish privilege registry for GET & HEAD
2834 // method for security reasons.
2835 entityPrivileges = {
2836 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2837 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2838 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2839 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2840 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2841 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2842 }
2843
2844 private:
2845 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002846 const std::vector<std::string>&) override
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002847 {
2848 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2849
2850 auto generateTelemetryLogCallback = [asyncResp, req](
2851 const boost::system::error_code
2852 ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002853 const std::string&) {
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002854 if (ec)
2855 {
2856 if (ec.value() == boost::system::errc::operation_not_supported)
2857 {
2858 messages::resourceInStandby(asyncResp->res);
2859 }
2860 else if (ec.value() ==
2861 boost::system::errc::device_or_resource_busy)
2862 {
2863 messages::serviceTemporarilyUnavailable(asyncResp->res,
2864 "60");
2865 }
2866 else
2867 {
2868 messages::internalError(asyncResp->res);
2869 }
2870 return;
2871 }
2872 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
2873 [](boost::system::error_code err, sdbusplus::message::message&,
2874 const std::shared_ptr<task::TaskData>& taskData) {
2875 if (!err)
2876 {
2877 taskData->messages.emplace_back(
2878 messages::taskCompletedOK(
2879 std::to_string(taskData->index)));
2880 taskData->state = "Completed";
2881 }
2882 return task::completed;
2883 },
2884 "type='signal',interface='org.freedesktop.DBus.Properties',"
2885 "member='PropertiesChanged',arg0namespace='com.intel."
2886 "crashdump'");
2887 task->startTimer(std::chrono::minutes(5));
2888 task->populateResp(asyncResp->res);
2889 task->payload.emplace(req);
2890 };
2891 crow::connections::systemBus->async_method_call(
2892 std::move(generateTelemetryLogCallback), crashdumpObject,
2893 crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog");
2894 }
2895};
2896
Jason M. Billse1f26342018-07-18 12:12:00 -07002897class SendRawPECI : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002898{
2899 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002900 SendRawPECI(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002901 Node(app,
2902 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2903 "Crashdump.SendRawPeci/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002904 {
AppaRao Puli39460282020-04-07 17:03:04 +05302905 // Note: Deviated from redfish privilege registry for GET & HEAD
2906 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002907 entityPrivileges = {
2908 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2909 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2910 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2911 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2912 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2913 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2914 }
2915
2916 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002917 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002918 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002919 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002920 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002921 std::vector<std::vector<uint8_t>> peciCommands;
Ed Tanousb1556422018-10-16 14:09:17 -07002922
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002923 if (!json_util::readJson(req, res, "PECICommands", peciCommands))
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002924 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002925 return;
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002926 }
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002927 uint32_t idx = 0;
2928 for (auto const& cmd : peciCommands)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002929 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002930 if (cmd.size() < 3)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002931 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002932 std::string s("[");
2933 for (auto const& val : cmd)
2934 {
2935 if (val != *cmd.begin())
2936 {
2937 s += ",";
2938 }
2939 s += std::to_string(val);
2940 }
2941 s += "]";
2942 messages::actionParameterValueFormatError(
2943 res, s, "PECICommands[" + std::to_string(idx) + "]",
2944 "SendRawPeci");
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002945 return;
2946 }
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002947 idx++;
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002948 }
Ed Tanous1da66f72018-07-27 16:13:37 -07002949 // Callback to return the Raw PECI response
Jason M. Billse1f26342018-07-18 12:12:00 -07002950 auto sendRawPECICallback =
2951 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002952 const std::vector<std::vector<uint8_t>>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002953 if (ec)
2954 {
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002955 BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: "
Jason M. Billse1f26342018-07-18 12:12:00 -07002956 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002957 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002958 return;
2959 }
2960 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
2961 {"PECIResponse", resp}};
2962 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002963 // Call the SendRawPECI command with the provided data
2964 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002965 std::move(sendRawPECICallback), crashdumpObject, crashdumpPath,
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002966 crashdumpRawPECIInterface, "SendRawPeci", peciCommands);
Ed Tanous1da66f72018-07-27 16:13:37 -07002967 }
2968};
2969
Andrew Geisslercb92c032018-08-17 07:56:14 -07002970/**
2971 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
2972 */
2973class DBusLogServiceActionsClear : public Node
2974{
2975 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002976 DBusLogServiceActionsClear(App& app) :
Andrew Geisslercb92c032018-08-17 07:56:14 -07002977 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
Gunnar Mills7af91512020-04-14 22:16:57 -05002978 "LogService.ClearLog/")
Andrew Geisslercb92c032018-08-17 07:56:14 -07002979 {
2980 entityPrivileges = {
2981 {boost::beast::http::verb::get, {{"Login"}}},
2982 {boost::beast::http::verb::head, {{"Login"}}},
2983 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2984 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2985 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2986 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2987 }
2988
2989 private:
2990 /**
2991 * Function handles POST method request.
2992 * The Clear Log actions does not require any parameter.The action deletes
2993 * all entries found in the Entries collection for this Log Service.
2994 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002995 void doPost(crow::Response& res, const crow::Request&,
2996 const std::vector<std::string>&) override
Andrew Geisslercb92c032018-08-17 07:56:14 -07002997 {
2998 BMCWEB_LOG_DEBUG << "Do delete all entries.";
2999
3000 auto asyncResp = std::make_shared<AsyncResp>(res);
3001 // Process response from Logging service.
Ed Tanous2c70f802020-09-28 14:29:23 -07003002 auto respHandler = [asyncResp](const boost::system::error_code ec) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07003003 BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3004 if (ec)
3005 {
3006 // TODO Handle for specific error code
3007 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3008 asyncResp->res.result(
3009 boost::beast::http::status::internal_server_error);
3010 return;
3011 }
3012
3013 asyncResp->res.result(boost::beast::http::status::no_content);
3014 };
3015
3016 // Make call to Logging service to request Clear Log
3017 crow::connections::systemBus->async_method_call(
Ed Tanous2c70f802020-09-28 14:29:23 -07003018 respHandler, "xyz.openbmc_project.Logging",
Andrew Geisslercb92c032018-08-17 07:56:14 -07003019 "/xyz/openbmc_project/logging",
3020 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3021 }
3022};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003023
3024/****************************************************
3025 * Redfish PostCode interfaces
3026 * using DBUS interface: getPostCodesTS
3027 ******************************************************/
3028class PostCodesLogService : public Node
3029{
3030 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003031 PostCodesLogService(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003032 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
3033 {
3034 entityPrivileges = {
3035 {boost::beast::http::verb::get, {{"Login"}}},
3036 {boost::beast::http::verb::head, {{"Login"}}},
3037 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3038 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3039 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3040 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3041 }
3042
3043 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003044 void doGet(crow::Response& res, const crow::Request&,
3045 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003046 {
3047 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3048
3049 asyncResp->res.jsonValue = {
3050 {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
3051 {"@odata.type", "#LogService.v1_1_0.LogService"},
ZhikuiRena3316fc2020-01-29 14:58:08 -08003052 {"Name", "POST Code Log Service"},
3053 {"Description", "POST Code Log Service"},
3054 {"Id", "BIOS POST Code Log"},
3055 {"OverWritePolicy", "WrapsWhenFull"},
3056 {"Entries",
3057 {{"@odata.id",
3058 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
3059 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
3060 {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
3061 "Actions/LogService.ClearLog"}};
3062 }
3063};
3064
3065class PostCodesClear : public Node
3066{
3067 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003068 PostCodesClear(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003069 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3070 "LogService.ClearLog/")
3071 {
3072 entityPrivileges = {
3073 {boost::beast::http::verb::get, {{"Login"}}},
3074 {boost::beast::http::verb::head, {{"Login"}}},
AppaRao Puli39460282020-04-07 17:03:04 +05303075 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
3076 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
3077 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
3078 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003079 }
3080
3081 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003082 void doPost(crow::Response& res, const crow::Request&,
3083 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003084 {
3085 BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3086
3087 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3088 // Make call to post-code service to request clear all
3089 crow::connections::systemBus->async_method_call(
3090 [asyncResp](const boost::system::error_code ec) {
3091 if (ec)
3092 {
3093 // TODO Handle for specific error code
3094 BMCWEB_LOG_ERROR
3095 << "doClearPostCodes resp_handler got error " << ec;
3096 asyncResp->res.result(
3097 boost::beast::http::status::internal_server_error);
3098 messages::internalError(asyncResp->res);
3099 return;
3100 }
3101 },
Jonathan Doman15124762021-01-07 17:54:17 -08003102 "xyz.openbmc_project.State.Boot.PostCode0",
3103 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003104 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3105 }
3106};
3107
3108static void fillPostCodeEntry(
Ed Tanousb5a76932020-09-29 16:16:58 -07003109 const std::shared_ptr<AsyncResp>& aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003110 const boost::container::flat_map<uint64_t, uint64_t>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003111 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3112 const uint64_t skip = 0, const uint64_t top = 0)
3113{
3114 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003115 const message_registries::Message* message =
ZhikuiRena3316fc2020-01-29 14:58:08 -08003116 message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003117
3118 uint64_t currentCodeIndex = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003119 nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003120
3121 uint64_t firstCodeTimeUs = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003122 for (const std::pair<uint64_t, uint64_t>& code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003123 {
3124 currentCodeIndex++;
3125 std::string postcodeEntryID =
3126 "B" + std::to_string(bootIndex) + "-" +
3127 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3128
3129 uint64_t usecSinceEpoch = code.first;
3130 uint64_t usTimeOffset = 0;
3131
3132 if (1 == currentCodeIndex)
3133 { // already incremented
3134 firstCodeTimeUs = code.first;
3135 }
3136 else
3137 {
3138 usTimeOffset = code.first - firstCodeTimeUs;
3139 }
3140
3141 // skip if no specific codeIndex is specified and currentCodeIndex does
3142 // not fall between top and skip
3143 if ((codeIndex == 0) &&
3144 (currentCodeIndex <= skip || currentCodeIndex > top))
3145 {
3146 continue;
3147 }
3148
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003149 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003150 // currentIndex
3151 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3152 {
3153 // This is done for simplicity. 1st entry is needed to calculate
3154 // time offset. To improve efficiency, one can get to the entry
3155 // directly (possibly with flatmap's nth method)
3156 continue;
3157 }
3158
3159 // currentCodeIndex is within top and skip or equal to specified code
3160 // index
3161
3162 // Get the Created time from the timestamp
3163 std::string entryTimeStr;
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003164 entryTimeStr = crow::utility::getDateTime(
3165 static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003166
3167 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3168 std::ostringstream hexCode;
3169 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
3170 << code.second;
3171 std::ostringstream timeOffsetStr;
3172 // Set Fixed -Point Notation
3173 timeOffsetStr << std::fixed;
3174 // Set precision to 4 digits
3175 timeOffsetStr << std::setprecision(4);
3176 // Add double to stream
3177 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3178 std::vector<std::string> messageArgs = {
3179 std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3180
3181 // Get MessageArgs template from message registry
3182 std::string msg;
3183 if (message != nullptr)
3184 {
3185 msg = message->message;
3186
3187 // fill in this post code value
3188 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003189 for (const std::string& messageArg : messageArgs)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003190 {
3191 std::string argStr = "%" + std::to_string(++i);
3192 size_t argPos = msg.find(argStr);
3193 if (argPos != std::string::npos)
3194 {
3195 msg.replace(argPos, argStr.length(), messageArg);
3196 }
3197 }
3198 }
3199
Tim Leed4342a92020-04-27 11:47:58 +08003200 // Get Severity template from message registry
3201 std::string severity;
3202 if (message != nullptr)
3203 {
3204 severity = message->severity;
3205 }
3206
ZhikuiRena3316fc2020-01-29 14:58:08 -08003207 // add to AsyncResp
3208 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003209 nlohmann::json& bmcLogEntry = logEntryArray.back();
Gunnar Mills743e9a12020-10-26 12:44:53 -05003210 bmcLogEntry = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3211 {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3212 "PostCodes/Entries/" +
3213 postcodeEntryID},
3214 {"Name", "POST Code Log Entry"},
3215 {"Id", postcodeEntryID},
3216 {"Message", std::move(msg)},
3217 {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"},
3218 {"MessageArgs", std::move(messageArgs)},
3219 {"EntryType", "Event"},
3220 {"Severity", std::move(severity)},
3221 {"Created", entryTimeStr}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003222 }
3223}
3224
Ed Tanousb5a76932020-09-29 16:16:58 -07003225static void getPostCodeForEntry(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003226 const uint16_t bootIndex,
3227 const uint64_t codeIndex)
3228{
3229 crow::connections::systemBus->async_method_call(
3230 [aResp, bootIndex, codeIndex](
3231 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003232 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003233 if (ec)
3234 {
3235 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3236 messages::internalError(aResp->res);
3237 return;
3238 }
3239
3240 // skip the empty postcode boots
3241 if (postcode.empty())
3242 {
3243 return;
3244 }
3245
3246 fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3247
3248 aResp->res.jsonValue["Members@odata.count"] =
3249 aResp->res.jsonValue["Members"].size();
3250 },
Jonathan Doman15124762021-01-07 17:54:17 -08003251 "xyz.openbmc_project.State.Boot.PostCode0",
3252 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003253 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3254 bootIndex);
3255}
3256
Ed Tanousb5a76932020-09-29 16:16:58 -07003257static void getPostCodeForBoot(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003258 const uint16_t bootIndex,
3259 const uint16_t bootCount,
3260 const uint64_t entryCount, const uint64_t skip,
3261 const uint64_t top)
3262{
3263 crow::connections::systemBus->async_method_call(
3264 [aResp, bootIndex, bootCount, entryCount, skip,
3265 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003266 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003267 if (ec)
3268 {
3269 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3270 messages::internalError(aResp->res);
3271 return;
3272 }
3273
3274 uint64_t endCount = entryCount;
3275 if (!postcode.empty())
3276 {
3277 endCount = entryCount + postcode.size();
3278
3279 if ((skip < endCount) && ((top + skip) > entryCount))
3280 {
3281 uint64_t thisBootSkip =
3282 std::max(skip, entryCount) - entryCount;
3283 uint64_t thisBootTop =
3284 std::min(top + skip, endCount) - entryCount;
3285
3286 fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3287 thisBootSkip, thisBootTop);
3288 }
3289 aResp->res.jsonValue["Members@odata.count"] = endCount;
3290 }
3291
3292 // continue to previous bootIndex
3293 if (bootIndex < bootCount)
3294 {
3295 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3296 bootCount, endCount, skip, top);
3297 }
3298 else
3299 {
3300 aResp->res.jsonValue["Members@odata.nextLink"] =
3301 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3302 "Entries?$skip=" +
3303 std::to_string(skip + top);
3304 }
3305 },
Jonathan Doman15124762021-01-07 17:54:17 -08003306 "xyz.openbmc_project.State.Boot.PostCode0",
3307 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003308 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3309 bootIndex);
3310}
3311
Ed Tanousb5a76932020-09-29 16:16:58 -07003312static void getCurrentBootNumber(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003313 const uint64_t skip, const uint64_t top)
3314{
3315 uint64_t entryCount = 0;
3316 crow::connections::systemBus->async_method_call(
3317 [aResp, entryCount, skip,
3318 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003319 const std::variant<uint16_t>& bootCount) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003320 if (ec)
3321 {
3322 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3323 messages::internalError(aResp->res);
3324 return;
3325 }
3326 auto pVal = std::get_if<uint16_t>(&bootCount);
3327 if (pVal)
3328 {
3329 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3330 }
3331 else
3332 {
3333 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3334 }
3335 },
Jonathan Doman15124762021-01-07 17:54:17 -08003336 "xyz.openbmc_project.State.Boot.PostCode0",
3337 "/xyz/openbmc_project/State/Boot/PostCode0",
ZhikuiRena3316fc2020-01-29 14:58:08 -08003338 "org.freedesktop.DBus.Properties", "Get",
3339 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3340}
3341
3342class PostCodesEntryCollection : public Node
3343{
3344 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003345 PostCodesEntryCollection(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003346 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3347 {
3348 entityPrivileges = {
3349 {boost::beast::http::verb::get, {{"Login"}}},
3350 {boost::beast::http::verb::head, {{"Login"}}},
3351 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3352 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3353 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3354 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3355 }
3356
3357 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003358 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00003359 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003360 {
3361 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3362
3363 asyncResp->res.jsonValue["@odata.type"] =
3364 "#LogEntryCollection.LogEntryCollection";
ZhikuiRena3316fc2020-01-29 14:58:08 -08003365 asyncResp->res.jsonValue["@odata.id"] =
3366 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3367 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3368 asyncResp->res.jsonValue["Description"] =
3369 "Collection of POST Code Log Entries";
3370 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3371 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3372
3373 uint64_t skip = 0;
3374 uint64_t top = maxEntriesPerPage; // Show max entries by default
3375 if (!getSkipParam(asyncResp->res, req, skip))
3376 {
3377 return;
3378 }
3379 if (!getTopParam(asyncResp->res, req, top))
3380 {
3381 return;
3382 }
3383 getCurrentBootNumber(asyncResp, skip, top);
3384 }
3385};
3386
3387class PostCodesEntry : public Node
3388{
3389 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003390 PostCodesEntry(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003391 Node(app,
3392 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3393 std::string())
3394 {
3395 entityPrivileges = {
3396 {boost::beast::http::verb::get, {{"Login"}}},
3397 {boost::beast::http::verb::head, {{"Login"}}},
3398 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3399 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3400 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3401 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3402 }
3403
3404 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003405 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003406 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003407 {
3408 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3409 if (params.size() != 1)
3410 {
3411 messages::internalError(asyncResp->res);
3412 return;
3413 }
3414
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003415 const std::string& targetID = params[0];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003416
3417 size_t bootPos = targetID.find('B');
3418 if (bootPos == std::string::npos)
3419 {
3420 // Requested ID was not found
3421 messages::resourceMissingAtURI(asyncResp->res, targetID);
3422 return;
3423 }
3424 std::string_view bootIndexStr(targetID);
3425 bootIndexStr.remove_prefix(bootPos + 1);
3426 uint16_t bootIndex = 0;
3427 uint64_t codeIndex = 0;
3428 size_t dashPos = bootIndexStr.find('-');
3429
3430 if (dashPos == std::string::npos)
3431 {
3432 return;
3433 }
3434 std::string_view codeIndexStr(bootIndexStr);
3435 bootIndexStr.remove_suffix(dashPos);
3436 codeIndexStr.remove_prefix(dashPos + 1);
3437
3438 bootIndex = static_cast<uint16_t>(
Ed Tanous23a21a12020-07-25 04:45:05 +00003439 strtoul(std::string(bootIndexStr).c_str(), nullptr, 0));
3440 codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003441 if (bootIndex == 0 || codeIndex == 0)
3442 {
3443 BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3444 << params[0];
3445 }
3446
3447 asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
ZhikuiRena3316fc2020-01-29 14:58:08 -08003448 asyncResp->res.jsonValue["@odata.id"] =
3449 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3450 "Entries";
3451 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3452 asyncResp->res.jsonValue["Description"] =
3453 "Collection of POST Code Log Entries";
3454 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3455 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3456
3457 getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3458 }
3459};
3460
Ed Tanous1da66f72018-07-27 16:13:37 -07003461} // namespace redfish