blob: a4a873a28e390d47fa481b31038eeb1f508ca089 [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>
raviteja-b06578432020-02-03 12:50:42 -060030#include <dump_offload.hpp>
Andrew Geisslercb92c032018-08-17 07:56:14 -070031#include <error_messages.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050032
James Feist4418c7f2019-04-15 11:09:15 -070033#include <filesystem>
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{
111 if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert")
112 {
113 return "Critical";
114 }
115 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical")
116 {
117 return "Critical";
118 }
119 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug")
120 {
121 return "OK";
122 }
123 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency")
124 {
125 return "Critical";
126 }
127 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error")
128 {
129 return "Critical";
130 }
131 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational")
132 {
133 return "OK";
134 }
135 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")
136 {
137 return "OK";
138 }
139 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
140 {
141 return "Warning";
142 }
143 return "";
144}
145
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500146static int getJournalMetadata(sd_journal* journal,
147 const std::string_view& field,
148 std::string_view& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700149{
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500150 const char* data = nullptr;
Jason M. Bills16428a12018-11-02 12:42:29 -0700151 size_t length = 0;
152 int ret = 0;
153 // Get the metadata from the requested field of the journal entry
Ed Tanous271584a2019-07-09 16:24:22 -0700154 ret = sd_journal_get_data(journal, field.data(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500155 reinterpret_cast<const void**>(&data), &length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700156 if (ret < 0)
157 {
158 return ret;
159 }
Ed Tanous39e77502019-03-04 17:35:53 -0800160 contents = std::string_view(data, length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700161 // Only use the content after the "=" character.
162 contents.remove_prefix(std::min(contents.find("=") + 1, contents.size()));
163 return ret;
164}
165
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500166static int getJournalMetadata(sd_journal* journal,
167 const std::string_view& field, const int& base,
168 long int& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700169{
170 int ret = 0;
Ed Tanous39e77502019-03-04 17:35:53 -0800171 std::string_view metadata;
Jason M. Bills16428a12018-11-02 12:42:29 -0700172 // Get the metadata from the requested field of the journal entry
173 ret = getJournalMetadata(journal, field, metadata);
174 if (ret < 0)
175 {
176 return ret;
177 }
Ed Tanousb01bf292019-03-25 19:25:26 +0000178 contents = strtol(metadata.data(), nullptr, base);
Jason M. Bills16428a12018-11-02 12:42:29 -0700179 return ret;
180}
181
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500182static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800183{
184 int ret = 0;
185 uint64_t timestamp = 0;
186 ret = sd_journal_get_realtime_usec(journal, &timestamp);
187 if (ret < 0)
188 {
189 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
190 << strerror(-ret);
191 return false;
192 }
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -0500193 entryTimestamp = crow::utility::getDateTime(
194 static_cast<std::time_t>(timestamp / 1000 / 1000));
195 return true;
ZhikuiRena3316fc2020-01-29 14:58:08 -0800196}
197
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500198static bool getSkipParam(crow::Response& res, const crow::Request& req,
199 uint64_t& skip)
Jason M. Bills16428a12018-11-02 12:42:29 -0700200{
James Feist5a7e8772020-07-22 09:08:38 -0700201 boost::urls::url_view::params_type::iterator it =
202 req.urlParams.find("$skip");
203 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700204 {
James Feist5a7e8772020-07-22 09:08:38 -0700205 std::string skipParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500206 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700207 skip = std::strtoul(skipParam.c_str(), &ptr, 10);
208 if (skipParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700209 {
210
211 messages::queryParameterValueTypeError(res, std::string(skipParam),
212 "$skip");
213 return false;
214 }
Jason M. Bills16428a12018-11-02 12:42:29 -0700215 }
216 return true;
217}
218
Ed Tanous271584a2019-07-09 16:24:22 -0700219static constexpr const uint64_t maxEntriesPerPage = 1000;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500220static bool getTopParam(crow::Response& res, const crow::Request& req,
221 uint64_t& top)
Jason M. Bills16428a12018-11-02 12:42:29 -0700222{
James Feist5a7e8772020-07-22 09:08:38 -0700223 boost::urls::url_view::params_type::iterator it =
224 req.urlParams.find("$top");
225 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700226 {
James Feist5a7e8772020-07-22 09:08:38 -0700227 std::string topParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500228 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700229 top = std::strtoul(topParam.c_str(), &ptr, 10);
230 if (topParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700231 {
232 messages::queryParameterValueTypeError(res, std::string(topParam),
233 "$top");
234 return false;
235 }
Ed Tanous271584a2019-07-09 16:24:22 -0700236 if (top < 1U || top > maxEntriesPerPage)
Jason M. Bills16428a12018-11-02 12:42:29 -0700237 {
238
239 messages::queryParameterOutOfRange(
240 res, std::to_string(top), "$top",
241 "1-" + std::to_string(maxEntriesPerPage));
242 return false;
243 }
244 }
245 return true;
246}
247
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500248static bool getUniqueEntryID(sd_journal* journal, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700249 const bool firstEntry = true)
Jason M. Bills16428a12018-11-02 12:42:29 -0700250{
251 int ret = 0;
252 static uint64_t prevTs = 0;
253 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700254 if (firstEntry)
255 {
256 prevTs = 0;
257 }
258
Jason M. Bills16428a12018-11-02 12:42:29 -0700259 // Get the entry timestamp
260 uint64_t curTs = 0;
261 ret = sd_journal_get_realtime_usec(journal, &curTs);
262 if (ret < 0)
263 {
264 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
265 << strerror(-ret);
266 return false;
267 }
268 // If the timestamp isn't unique, increment the index
269 if (curTs == prevTs)
270 {
271 index++;
272 }
273 else
274 {
275 // Otherwise, reset it
276 index = 0;
277 }
278 // Save the timestamp
279 prevTs = curTs;
280
281 entryID = std::to_string(curTs);
282 if (index > 0)
283 {
284 entryID += "_" + std::to_string(index);
285 }
286 return true;
287}
288
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500289static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700290 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700291{
Ed Tanous271584a2019-07-09 16:24:22 -0700292 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700293 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700294 if (firstEntry)
295 {
296 prevTs = 0;
297 }
298
Jason M. Bills95820182019-04-22 16:25:34 -0700299 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700300 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700301 std::tm timeStruct = {};
302 std::istringstream entryStream(logEntry);
303 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
304 {
305 curTs = std::mktime(&timeStruct);
306 }
307 // If the timestamp isn't unique, increment the index
308 if (curTs == prevTs)
309 {
310 index++;
311 }
312 else
313 {
314 // Otherwise, reset it
315 index = 0;
316 }
317 // Save the timestamp
318 prevTs = curTs;
319
320 entryID = std::to_string(curTs);
321 if (index > 0)
322 {
323 entryID += "_" + std::to_string(index);
324 }
325 return true;
326}
327
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500328static bool getTimestampFromID(crow::Response& res, const std::string& entryID,
329 uint64_t& timestamp, uint64_t& index)
Jason M. Bills16428a12018-11-02 12:42:29 -0700330{
331 if (entryID.empty())
332 {
333 return false;
334 }
335 // Convert the unique ID back to a timestamp to find the entry
Ed Tanous39e77502019-03-04 17:35:53 -0800336 std::string_view tsStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700337
338 auto underscorePos = tsStr.find("_");
339 if (underscorePos != tsStr.npos)
340 {
341 // Timestamp has an index
342 tsStr.remove_suffix(tsStr.size() - underscorePos);
Ed Tanous39e77502019-03-04 17:35:53 -0800343 std::string_view indexStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700344 indexStr.remove_prefix(underscorePos + 1);
345 std::size_t pos;
346 try
347 {
Ed Tanous39e77502019-03-04 17:35:53 -0800348 index = std::stoul(std::string(indexStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700349 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500350 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700351 {
352 messages::resourceMissingAtURI(res, entryID);
353 return false;
354 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500355 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700356 {
357 messages::resourceMissingAtURI(res, entryID);
358 return false;
359 }
360 if (pos != indexStr.size())
361 {
362 messages::resourceMissingAtURI(res, entryID);
363 return false;
364 }
365 }
366 // Timestamp has no index
367 std::size_t pos;
368 try
369 {
Ed Tanous39e77502019-03-04 17:35:53 -0800370 timestamp = std::stoull(std::string(tsStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700371 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500372 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700373 {
374 messages::resourceMissingAtURI(res, entryID);
375 return false;
376 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500377 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700378 {
379 messages::resourceMissingAtURI(res, entryID);
380 return false;
381 }
382 if (pos != tsStr.size())
383 {
384 messages::resourceMissingAtURI(res, entryID);
385 return false;
386 }
387 return true;
388}
389
Jason M. Bills95820182019-04-22 16:25:34 -0700390static bool
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500391 getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700392{
393 static const std::filesystem::path redfishLogDir = "/var/log";
394 static const std::string redfishLogFilename = "redfish";
395
396 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500397 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700398 std::filesystem::directory_iterator(redfishLogDir))
399 {
400 // If we find a redfish log file, save the path
401 std::string filename = dirEnt.path().filename();
402 if (boost::starts_with(filename, redfishLogFilename))
403 {
404 redfishLogFiles.emplace_back(redfishLogDir / filename);
405 }
406 }
407 // As the log files rotate, they are appended with a ".#" that is higher for
408 // the older logs. Since we don't expect more than 10 log files, we
409 // can just sort the list to get them in order from newest to oldest
410 std::sort(redfishLogFiles.begin(), redfishLogFiles.end());
411
412 return !redfishLogFiles.empty();
413}
414
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500415inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp,
416 const std::string& dumpType)
417{
418 std::string dumpPath;
419 if (dumpType == "BMC")
420 {
421 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
422 }
423 else if (dumpType == "System")
424 {
425 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
426 }
427 else
428 {
429 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
430 messages::internalError(asyncResp->res);
431 return;
432 }
433
434 crow::connections::systemBus->async_method_call(
435 [asyncResp, dumpPath, dumpType](const boost::system::error_code ec,
436 GetManagedObjectsType& resp) {
437 if (ec)
438 {
439 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
440 messages::internalError(asyncResp->res);
441 return;
442 }
443
444 nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
445 entriesArray = nlohmann::json::array();
446
447 for (auto& object : resp)
448 {
449 bool foundDumpEntry = false;
450 for (auto& interfaceMap : object.second)
451 {
452 if (interfaceMap.first ==
453 ("xyz.openbmc_project.Dump.Entry." + dumpType))
454 {
455 foundDumpEntry = true;
456 break;
457 }
458 }
459
460 if (foundDumpEntry == false)
461 {
462 continue;
463 }
464 std::time_t timestamp;
465 uint64_t size = 0;
466 entriesArray.push_back({});
467 nlohmann::json& thisEntry = entriesArray.back();
468 const std::string& path =
469 static_cast<const std::string&>(object.first);
470 std::size_t lastPos = path.rfind("/");
471 if (lastPos == std::string::npos)
472 {
473 continue;
474 }
475 std::string entryID = path.substr(lastPos + 1);
476
477 for (auto& interfaceMap : object.second)
478 {
479 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
480 {
481
482 for (auto& propertyMap : interfaceMap.second)
483 {
484 if (propertyMap.first == "Size")
485 {
486 auto sizePtr =
487 std::get_if<uint64_t>(&propertyMap.second);
488 if (sizePtr == nullptr)
489 {
490 messages::internalError(asyncResp->res);
491 break;
492 }
493 size = *sizePtr;
494 break;
495 }
496 }
497 }
498 else if (interfaceMap.first ==
499 "xyz.openbmc_project.Time.EpochTime")
500 {
501
502 for (auto& propertyMap : interfaceMap.second)
503 {
504 if (propertyMap.first == "Elapsed")
505 {
506 const uint64_t* usecsTimeStamp =
507 std::get_if<uint64_t>(&propertyMap.second);
508 if (usecsTimeStamp == nullptr)
509 {
510 messages::internalError(asyncResp->res);
511 break;
512 }
513 timestamp =
514 static_cast<std::time_t>(*usecsTimeStamp);
515 break;
516 }
517 }
518 }
519 }
520
521 thisEntry["@odata.type"] = "#LogEntry.v1_5_1.LogEntry";
522 thisEntry["@odata.id"] = dumpPath + entryID;
523 thisEntry["Id"] = entryID;
524 thisEntry["EntryType"] = "Event";
525 thisEntry["Created"] = crow::utility::getDateTime(timestamp);
526 thisEntry["Name"] = dumpType + " Dump Entry";
527
528 thisEntry["Oem"]["OpenBmc"]["@odata.type"] =
529 "#OemLogEntry.v1_0_0.OpenBmc";
530 thisEntry["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = size;
531
532 if (dumpType == "BMC")
533 {
534 thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] =
535 "Manager";
536 thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] =
537 "/redfish/v1/Managers/bmc/LogServices/Dump/"
538 "attachment/" +
539 entryID;
540 }
541 else if (dumpType == "System")
542 {
543 thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = "OEM";
544 thisEntry["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] =
545 "System";
546 thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] =
547 "/redfish/v1/Systems/system/LogServices/Dump/"
548 "attachment/" +
549 entryID;
550 }
551 }
552 asyncResp->res.jsonValue["Members@odata.count"] =
553 entriesArray.size();
554 },
555 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
556 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
557}
558
559inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp,
560 const std::string& entryID,
561 const std::string& dumpType)
562{
563 std::string dumpPath;
564 if (dumpType == "BMC")
565 {
566 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
567 }
568 else if (dumpType == "System")
569 {
570 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
571 }
572 else
573 {
574 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
575 messages::internalError(asyncResp->res);
576 return;
577 }
578
579 crow::connections::systemBus->async_method_call(
580 [asyncResp, entryID, dumpPath, dumpType](
581 const boost::system::error_code ec, GetManagedObjectsType& resp) {
582 if (ec)
583 {
584 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
585 messages::internalError(asyncResp->res);
586 return;
587 }
588
589 for (auto& objectPath : resp)
590 {
591 if (objectPath.first.str.find(
592 "/xyz/openbmc_project/dump/entry/" + entryID) ==
593 std::string::npos)
594 {
595 continue;
596 }
597
598 bool foundDumpEntry = false;
599 for (auto& interfaceMap : objectPath.second)
600 {
601 if (interfaceMap.first ==
602 ("xyz.openbmc_project.Dump.Entry." + dumpType))
603 {
604 foundDumpEntry = true;
605 break;
606 }
607 }
608 if (foundDumpEntry == false)
609 {
610 BMCWEB_LOG_ERROR << "Can't find Dump Entry";
611 messages::internalError(asyncResp->res);
612 return;
613 }
614
615 std::time_t timestamp;
616 uint64_t size = 0;
617
618 for (auto& interfaceMap : objectPath.second)
619 {
620 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
621 {
622 for (auto& propertyMap : interfaceMap.second)
623 {
624 if (propertyMap.first == "Size")
625 {
626 auto sizePtr =
627 std::get_if<uint64_t>(&propertyMap.second);
628 if (sizePtr == nullptr)
629 {
630 messages::internalError(asyncResp->res);
631 break;
632 }
633 size = *sizePtr;
634 break;
635 }
636 }
637 }
638 else if (interfaceMap.first ==
639 "xyz.openbmc_project.Time.EpochTime")
640 {
641 for (auto& propertyMap : interfaceMap.second)
642 {
643 if (propertyMap.first == "Elapsed")
644 {
645 const uint64_t* usecsTimeStamp =
646 std::get_if<uint64_t>(&propertyMap.second);
647 if (usecsTimeStamp == nullptr)
648 {
649 messages::internalError(asyncResp->res);
650 break;
651 }
652 timestamp =
653 static_cast<std::time_t>(*usecsTimeStamp);
654 break;
655 }
656 }
657 }
658 }
659
660 asyncResp->res.jsonValue["@odata.type"] =
661 "#LogEntry.v1_5_1.LogEntry";
662 asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID;
663 asyncResp->res.jsonValue["Id"] = entryID;
664 asyncResp->res.jsonValue["EntryType"] = "Event";
665 asyncResp->res.jsonValue["Created"] =
666 crow::utility::getDateTime(timestamp);
667 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
668
669 asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] =
670 "#OemLogEntry.v1_0_0.OpenBmc";
671 asyncResp->res
672 .jsonValue["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] =
673 size;
674
675 if (dumpType == "BMC")
676 {
677 asyncResp->res
678 .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] =
679 "Manager";
680 asyncResp->res
681 .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] =
682 "/redfish/v1/Managers/bmc/LogServices/Dump/"
683 "attachment/" +
684 entryID;
685 }
686 else if (dumpType == "System")
687 {
688 asyncResp->res
689 .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] =
690 "OEM";
691 asyncResp->res
692 .jsonValue["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] =
693 "System";
694 asyncResp->res
695 .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] =
696 "/redfish/v1/Systems/system/LogServices/Dump/"
697 "attachment/" +
698 entryID;
699 }
700 }
701 },
702 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
703 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
704}
705
706inline void deleteDumpEntry(crow::Response& res, const std::string& entryID)
707{
708 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
709
710 auto respHandler = [asyncResp](const boost::system::error_code ec) {
711 BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
712 if (ec)
713 {
714 BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
715 << ec;
716 messages::internalError(asyncResp->res);
717 return;
718 }
719 };
720 crow::connections::systemBus->async_method_call(
721 respHandler, "xyz.openbmc_project.Dump.Manager",
722 "/xyz/openbmc_project/dump/entry/" + entryID,
723 "xyz.openbmc_project.Object.Delete", "Delete");
724}
725
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500726inline void createDumpTaskCallback(const crow::Request& req,
727 std::shared_ptr<AsyncResp> asyncResp,
728 const uint32_t& dumpId,
729 const std::string& dumpPath,
730 const std::string& dumpType)
731{
732 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
733 [dumpId, dumpPath, dumpType](
734 boost::system::error_code err, sdbusplus::message::message& m,
735 const std::shared_ptr<task::TaskData>& taskData) {
736 std::vector<std::pair<
737 std::string,
738 std::vector<std::pair<std::string, std::variant<std::string>>>>>
739 interfacesList;
740
741 sdbusplus::message::object_path objPath;
742
743 m.read(objPath, interfacesList);
744
745 for (auto& interface : interfacesList)
746 {
747 if (interface.first ==
748 ("xyz.openbmc_project.Dump.Entry." + dumpType))
749 {
750 nlohmann::json retMessage = messages::success();
751 taskData->messages.emplace_back(retMessage);
752
753 std::string headerLoc =
754 "Location: " + dumpPath + std::to_string(dumpId);
755 taskData->payload->httpHeaders.emplace_back(
756 std::move(headerLoc));
757
758 taskData->state = "Completed";
759 return task::completed;
760 }
761 }
762 return !task::completed;
763 },
764 "type='signal',interface='org.freedesktop.DBus."
765 "ObjectManager',"
766 "member='InterfacesAdded', "
767 "path='/xyz/openbmc_project/dump'");
768
769 task->startTimer(std::chrono::minutes(3));
770 task->populateResp(asyncResp->res);
771 task->payload.emplace(req);
772}
773
774inline void createDump(crow::Response& res, const crow::Request& req,
775 const std::string& dumpType)
776{
777 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
778
779 std::string dumpPath;
780 if (dumpType == "BMC")
781 {
782 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
783 }
784 else if (dumpType == "System")
785 {
786 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
787 }
788 else
789 {
790 BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
791 messages::internalError(asyncResp->res);
792 return;
793 }
794
795 std::optional<std::string> diagnosticDataType;
796 std::optional<std::string> oemDiagnosticDataType;
797
798 if (!redfish::json_util::readJson(
799 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
800 "OEMDiagnosticDataType", oemDiagnosticDataType))
801 {
802 return;
803 }
804
805 if (dumpType == "System")
806 {
807 if (!oemDiagnosticDataType || !diagnosticDataType)
808 {
809 BMCWEB_LOG_ERROR << "CreateDump action parameter "
810 "'DiagnosticDataType'/"
811 "'OEMDiagnosticDataType' value not found!";
812 messages::actionParameterMissing(
813 asyncResp->res, "CollectDiagnosticData",
814 "DiagnosticDataType & OEMDiagnosticDataType");
815 return;
816 }
817 else if ((*oemDiagnosticDataType != "System") ||
818 (*diagnosticDataType != "OEM"))
819 {
820 BMCWEB_LOG_ERROR << "Wrong parameter values passed";
821 messages::invalidObject(asyncResp->res,
822 "System Dump creation parameters");
823 return;
824 }
825 }
826 else if (dumpType == "BMC")
827 {
828 if (!diagnosticDataType)
829 {
830 BMCWEB_LOG_ERROR << "CreateDump action parameter "
831 "'DiagnosticDataType' not found!";
832 messages::actionParameterMissing(
833 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
834 return;
835 }
836 else if (*diagnosticDataType != "Manager")
837 {
838 BMCWEB_LOG_ERROR
839 << "Wrong parameter value passed for 'DiagnosticDataType'";
840 messages::invalidObject(asyncResp->res,
841 "BMC Dump creation parameters");
842 return;
843 }
844 }
845
846 crow::connections::systemBus->async_method_call(
847 [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
848 const uint32_t& dumpId) {
849 if (ec)
850 {
851 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
852 messages::internalError(asyncResp->res);
853 return;
854 }
855 BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
856
857 createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
858 },
859 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
860 "xyz.openbmc_project.Dump.Create", "CreateDump");
861}
862
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500863inline void clearDump(crow::Response& res, const std::string& dumpInterface)
864{
865 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
866 crow::connections::systemBus->async_method_call(
867 [asyncResp](const boost::system::error_code ec,
868 const std::vector<std::string>& subTreePaths) {
869 if (ec)
870 {
871 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
872 messages::internalError(asyncResp->res);
873 return;
874 }
875
876 for (const std::string& path : subTreePaths)
877 {
878 std::size_t pos = path.rfind("/");
879 if (pos != std::string::npos)
880 {
881 std::string logID = path.substr(pos + 1);
882 deleteDumpEntry(asyncResp->res, logID);
883 }
884 }
885 },
886 "xyz.openbmc_project.ObjectMapper",
887 "/xyz/openbmc_project/object_mapper",
888 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
889 "/xyz/openbmc_project/dump", 0,
890 std::array<std::string, 1>{dumpInterface});
891}
892
Johnathan Mantey043a0532020-03-10 17:15:28 -0700893static void ParseCrashdumpParameters(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500894 const std::vector<std::pair<std::string, VariantType>>& params,
895 std::string& filename, std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -0700896{
897 for (auto property : params)
898 {
899 if (property.first == "Timestamp")
900 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500901 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500902 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700903 if (value != nullptr)
904 {
905 timestamp = *value;
906 }
907 }
908 else if (property.first == "Filename")
909 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500910 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500911 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700912 if (value != nullptr)
913 {
914 filename = *value;
915 }
916 }
917 else if (property.first == "Log")
918 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500919 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500920 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700921 if (value != nullptr)
922 {
923 logfile = *value;
924 }
925 }
926 }
927}
928
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500929constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800930class SystemLogServiceCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -0700931{
932 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700933 SystemLogServiceCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800934 Node(app, "/redfish/v1/Systems/system/LogServices/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800935 {
936 entityPrivileges = {
937 {boost::beast::http::verb::get, {{"Login"}}},
938 {boost::beast::http::verb::head, {{"Login"}}},
939 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
940 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
941 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
942 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
943 }
944
945 private:
946 /**
947 * Functions triggers appropriate requests on DBus
948 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500949 void doGet(crow::Response& res, const crow::Request& req,
950 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800951 {
952 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800953 // Collections don't include the static data added by SubRoute because
954 // it has a duplicate entry for members
955 asyncResp->res.jsonValue["@odata.type"] =
956 "#LogServiceCollection.LogServiceCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800957 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800958 "/redfish/v1/Systems/system/LogServices";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800959 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
960 asyncResp->res.jsonValue["Description"] =
961 "Collection of LogServices for this Computer System";
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500962 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800963 logServiceArray = nlohmann::json::array();
Ed Tanous029573d2019-02-01 10:57:49 -0800964 logServiceArray.push_back(
965 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500966#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
raviteja-bc9bb6862020-02-03 11:53:32 -0600967 logServiceArray.push_back(
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500968 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
raviteja-bc9bb6862020-02-03 11:53:32 -0600969#endif
970
Jason M. Billsd53dd412019-02-12 17:16:22 -0800971#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
972 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -0500973 {{"@odata.id",
974 "/redfish/v1/Systems/system/LogServices/Crashdump"}});
Jason M. Billsd53dd412019-02-12 17:16:22 -0800975#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800976 asyncResp->res.jsonValue["Members@odata.count"] =
977 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800978
979 crow::connections::systemBus->async_method_call(
980 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500981 const std::vector<std::string>& subtreePath) {
ZhikuiRena3316fc2020-01-29 14:58:08 -0800982 if (ec)
983 {
984 BMCWEB_LOG_ERROR << ec;
985 return;
986 }
987
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500988 for (auto& pathStr : subtreePath)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800989 {
990 if (pathStr.find("PostCode") != std::string::npos)
991 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000992 nlohmann::json& logServiceArrayLocal =
ZhikuiRena3316fc2020-01-29 14:58:08 -0800993 asyncResp->res.jsonValue["Members"];
Ed Tanous23a21a12020-07-25 04:45:05 +0000994 logServiceArrayLocal.push_back(
ZhikuiRena3316fc2020-01-29 14:58:08 -0800995 {{"@odata.id", "/redfish/v1/Systems/system/"
996 "LogServices/PostCodes"}});
997 asyncResp->res.jsonValue["Members@odata.count"] =
Ed Tanous23a21a12020-07-25 04:45:05 +0000998 logServiceArrayLocal.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800999 return;
1000 }
1001 }
1002 },
1003 "xyz.openbmc_project.ObjectMapper",
1004 "/xyz/openbmc_project/object_mapper",
1005 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001006 std::array<const char*, 1>{postCodeIface});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001007 }
1008};
1009
1010class EventLogService : public Node
1011{
1012 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001013 EventLogService(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001014 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001015 {
1016 entityPrivileges = {
1017 {boost::beast::http::verb::get, {{"Login"}}},
1018 {boost::beast::http::verb::head, {{"Login"}}},
1019 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1020 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1021 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1022 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1023 }
1024
1025 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001026 void doGet(crow::Response& res, const crow::Request& req,
1027 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001028 {
1029 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1030
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001031 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001032 "/redfish/v1/Systems/system/LogServices/EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001033 asyncResp->res.jsonValue["@odata.type"] =
1034 "#LogService.v1_1_0.LogService";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001035 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1036 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
Gunnar Mills73ec8302020-04-14 16:02:42 -05001037 asyncResp->res.jsonValue["Id"] = "EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001038 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1039 asyncResp->res.jsonValue["Entries"] = {
1040 {"@odata.id",
Ed Tanous029573d2019-02-01 10:57:49 -08001041 "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
Gunnar Millse7d6c8b2019-07-03 11:30:01 -05001042 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1043
1044 {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1045 "Actions/LogService.ClearLog"}};
Jason M. Bills489640c2019-05-17 09:56:36 -07001046 }
1047};
1048
Tim Lee1f56a3a2019-10-09 10:17:57 +08001049class JournalEventLogClear : public Node
Jason M. Bills489640c2019-05-17 09:56:36 -07001050{
1051 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001052 JournalEventLogClear(App& app) :
Jason M. Bills489640c2019-05-17 09:56:36 -07001053 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1054 "LogService.ClearLog/")
1055 {
1056 entityPrivileges = {
1057 {boost::beast::http::verb::get, {{"Login"}}},
1058 {boost::beast::http::verb::head, {{"Login"}}},
1059 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1060 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1061 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1062 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1063 }
1064
1065 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001066 void doPost(crow::Response& res, const crow::Request& req,
1067 const std::vector<std::string>& params) override
Jason M. Bills489640c2019-05-17 09:56:36 -07001068 {
1069 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1070
1071 // Clear the EventLog by deleting the log files
1072 std::vector<std::filesystem::path> redfishLogFiles;
1073 if (getRedfishLogFiles(redfishLogFiles))
1074 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001075 for (const std::filesystem::path& file : redfishLogFiles)
Jason M. Bills489640c2019-05-17 09:56:36 -07001076 {
1077 std::error_code ec;
1078 std::filesystem::remove(file, ec);
1079 }
1080 }
1081
1082 // Reload rsyslog so it knows to start new log files
1083 crow::connections::systemBus->async_method_call(
1084 [asyncResp](const boost::system::error_code ec) {
1085 if (ec)
1086 {
1087 BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1088 messages::internalError(asyncResp->res);
1089 return;
1090 }
1091
1092 messages::success(asyncResp->res);
1093 },
1094 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1095 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1096 "replace");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001097 }
1098};
1099
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001100static int fillEventLogEntryJson(const std::string& logEntryID,
Jason M. Bills95820182019-04-22 16:25:34 -07001101 const std::string logEntry,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001102 nlohmann::json& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001103{
Jason M. Bills95820182019-04-22 16:25:34 -07001104 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001105 // First get the Timestamp
1106 size_t space = logEntry.find_first_of(" ");
1107 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001108 {
1109 return 1;
1110 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001111 std::string timestamp = logEntry.substr(0, space);
1112 // Then get the log contents
1113 size_t entryStart = logEntry.find_first_not_of(" ", space);
1114 if (entryStart == std::string::npos)
1115 {
1116 return 1;
1117 }
1118 std::string_view entry(logEntry);
1119 entry.remove_prefix(entryStart);
1120 // Use split to separate the entry into its fields
1121 std::vector<std::string> logEntryFields;
1122 boost::split(logEntryFields, entry, boost::is_any_of(","),
1123 boost::token_compress_on);
1124 // We need at least a MessageId to be valid
1125 if (logEntryFields.size() < 1)
1126 {
1127 return 1;
1128 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001129 std::string& messageID = logEntryFields[0];
Jason M. Bills95820182019-04-22 16:25:34 -07001130
Jason M. Bills4851d452019-03-28 11:27:48 -07001131 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001132 const message_registries::Message* message =
Jason M. Bills4851d452019-03-28 11:27:48 -07001133 message_registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001134
Jason M. Bills4851d452019-03-28 11:27:48 -07001135 std::string msg;
1136 std::string severity;
1137 if (message != nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001138 {
Jason M. Bills4851d452019-03-28 11:27:48 -07001139 msg = message->message;
1140 severity = message->severity;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001141 }
1142
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001143 // Get the MessageArgs from the log if there are any
1144 boost::beast::span<std::string> messageArgs;
1145 if (logEntryFields.size() > 1)
Jason M. Bills4851d452019-03-28 11:27:48 -07001146 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001147 std::string& messageArgsStart = logEntryFields[1];
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001148 // If the first string is empty, assume there are no MessageArgs
1149 std::size_t messageArgsSize = 0;
1150 if (!messageArgsStart.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001151 {
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001152 messageArgsSize = logEntryFields.size() - 1;
1153 }
1154
Ed Tanous23a21a12020-07-25 04:45:05 +00001155 messageArgs = {&messageArgsStart, messageArgsSize};
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001156
1157 // Fill the MessageArgs into the Message
1158 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001159 for (const std::string& messageArg : messageArgs)
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001160 {
1161 std::string argStr = "%" + std::to_string(++i);
1162 size_t argPos = msg.find(argStr);
1163 if (argPos != std::string::npos)
1164 {
1165 msg.replace(argPos, argStr.length(), messageArg);
1166 }
Jason M. Bills4851d452019-03-28 11:27:48 -07001167 }
1168 }
1169
Jason M. Bills95820182019-04-22 16:25:34 -07001170 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1171 // format which matches the Redfish format except for the fractional seconds
1172 // between the '.' and the '+', so just remove them.
1173 std::size_t dot = timestamp.find_first_of(".");
1174 std::size_t plus = timestamp.find_first_of("+");
1175 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001176 {
Jason M. Bills95820182019-04-22 16:25:34 -07001177 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001178 }
1179
1180 // Fill in the log entry with the gathered data
Jason M. Bills95820182019-04-22 16:25:34 -07001181 logEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001182 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Ed Tanous029573d2019-02-01 10:57:49 -08001183 {"@odata.id",
Jason M. Bills897967d2019-07-29 17:05:30 -07001184 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
Jason M. Bills95820182019-04-22 16:25:34 -07001185 logEntryID},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001186 {"Name", "System Event Log Entry"},
Jason M. Bills95820182019-04-22 16:25:34 -07001187 {"Id", logEntryID},
1188 {"Message", std::move(msg)},
1189 {"MessageId", std::move(messageID)},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001190 {"MessageArgs", std::move(messageArgs)},
1191 {"EntryType", "Event"},
Jason M. Bills95820182019-04-22 16:25:34 -07001192 {"Severity", std::move(severity)},
1193 {"Created", std::move(timestamp)}};
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001194 return 0;
1195}
1196
Anthony Wilson27062602019-04-22 02:10:09 -05001197class JournalEventLogEntryCollection : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001198{
1199 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001200 JournalEventLogEntryCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001201 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001202 {
1203 entityPrivileges = {
1204 {boost::beast::http::verb::get, {{"Login"}}},
1205 {boost::beast::http::verb::head, {{"Login"}}},
1206 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1207 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1208 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1209 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1210 }
1211
1212 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001213 void doGet(crow::Response& res, const crow::Request& req,
1214 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001215 {
1216 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous271584a2019-07-09 16:24:22 -07001217 uint64_t skip = 0;
1218 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001219 if (!getSkipParam(asyncResp->res, req, skip))
1220 {
1221 return;
1222 }
1223 if (!getTopParam(asyncResp->res, req, top))
1224 {
1225 return;
1226 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001227 // Collections don't include the static data added by SubRoute because
1228 // it has a duplicate entry for members
1229 asyncResp->res.jsonValue["@odata.type"] =
1230 "#LogEntryCollection.LogEntryCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001231 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001232 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001233 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1234 asyncResp->res.jsonValue["Description"] =
1235 "Collection of System Event Log Entries";
Andrew Geisslercb92c032018-08-17 07:56:14 -07001236
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001237 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001238 logEntryArray = nlohmann::json::array();
Jason M. Bills95820182019-04-22 16:25:34 -07001239 // Go through the log files and create a unique ID for each entry
1240 std::vector<std::filesystem::path> redfishLogFiles;
1241 getRedfishLogFiles(redfishLogFiles);
Ed Tanousb01bf292019-03-25 19:25:26 +00001242 uint64_t entryCount = 0;
Jason M. Billscd225da2019-05-08 15:31:57 -07001243 std::string logEntry;
Jason M. Bills95820182019-04-22 16:25:34 -07001244
1245 // Oldest logs are in the last file, so start there and loop backwards
Jason M. Billscd225da2019-05-08 15:31:57 -07001246 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1247 it++)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001248 {
Jason M. Billscd225da2019-05-08 15:31:57 -07001249 std::ifstream logStream(*it);
Jason M. Bills95820182019-04-22 16:25:34 -07001250 if (!logStream.is_open())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001251 {
1252 continue;
1253 }
1254
Jason M. Billse85d6b12019-07-29 17:01:15 -07001255 // Reset the unique ID on the first entry
1256 bool firstEntry = true;
Jason M. Bills95820182019-04-22 16:25:34 -07001257 while (std::getline(logStream, logEntry))
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001258 {
Jason M. Bills95820182019-04-22 16:25:34 -07001259 entryCount++;
1260 // Handle paging using skip (number of entries to skip from the
1261 // start) and top (number of entries to display)
1262 if (entryCount <= skip || entryCount > skip + top)
1263 {
1264 continue;
1265 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001266
Jason M. Bills95820182019-04-22 16:25:34 -07001267 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001268 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Jason M. Bills95820182019-04-22 16:25:34 -07001269 {
1270 continue;
1271 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001272
Jason M. Billse85d6b12019-07-29 17:01:15 -07001273 if (firstEntry)
1274 {
1275 firstEntry = false;
1276 }
1277
Jason M. Bills95820182019-04-22 16:25:34 -07001278 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001279 nlohmann::json& bmcLogEntry = logEntryArray.back();
Jason M. Bills95820182019-04-22 16:25:34 -07001280 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
1281 {
1282 messages::internalError(asyncResp->res);
1283 return;
1284 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001285 }
1286 }
1287 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1288 if (skip + top < entryCount)
1289 {
1290 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Bills95820182019-04-22 16:25:34 -07001291 "/redfish/v1/Systems/system/LogServices/EventLog/"
1292 "Entries?$skip=" +
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001293 std::to_string(skip + top);
1294 }
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001295 }
1296};
1297
Jason M. Bills897967d2019-07-29 17:05:30 -07001298class JournalEventLogEntry : public Node
1299{
1300 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001301 JournalEventLogEntry(App& app) :
Jason M. Bills897967d2019-07-29 17:05:30 -07001302 Node(app,
1303 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1304 std::string())
1305 {
1306 entityPrivileges = {
1307 {boost::beast::http::verb::get, {{"Login"}}},
1308 {boost::beast::http::verb::head, {{"Login"}}},
1309 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1310 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1311 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1312 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1313 }
1314
1315 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001316 void doGet(crow::Response& res, const crow::Request& req,
1317 const std::vector<std::string>& params) override
Jason M. Bills897967d2019-07-29 17:05:30 -07001318 {
1319 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1320 if (params.size() != 1)
1321 {
1322 messages::internalError(asyncResp->res);
1323 return;
1324 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001325 const std::string& targetID = params[0];
Jason M. Bills897967d2019-07-29 17:05:30 -07001326
1327 // Go through the log files and check the unique ID for each entry to
1328 // find the target entry
1329 std::vector<std::filesystem::path> redfishLogFiles;
1330 getRedfishLogFiles(redfishLogFiles);
1331 std::string logEntry;
1332
1333 // Oldest logs are in the last file, so start there and loop backwards
1334 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1335 it++)
1336 {
1337 std::ifstream logStream(*it);
1338 if (!logStream.is_open())
1339 {
1340 continue;
1341 }
1342
1343 // Reset the unique ID on the first entry
1344 bool firstEntry = true;
1345 while (std::getline(logStream, logEntry))
1346 {
1347 std::string idStr;
1348 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1349 {
1350 continue;
1351 }
1352
1353 if (firstEntry)
1354 {
1355 firstEntry = false;
1356 }
1357
1358 if (idStr == targetID)
1359 {
1360 if (fillEventLogEntryJson(idStr, logEntry,
1361 asyncResp->res.jsonValue) != 0)
1362 {
1363 messages::internalError(asyncResp->res);
1364 return;
1365 }
1366 return;
1367 }
1368 }
1369 }
1370 // Requested ID was not found
1371 messages::resourceMissingAtURI(asyncResp->res, targetID);
1372 }
1373};
1374
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001375class DBusEventLogEntryCollection : public Node
1376{
1377 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001378 DBusEventLogEntryCollection(App& app) :
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001379 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1380 {
1381 entityPrivileges = {
1382 {boost::beast::http::verb::get, {{"Login"}}},
1383 {boost::beast::http::verb::head, {{"Login"}}},
1384 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1385 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1386 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1387 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1388 }
1389
1390 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001391 void doGet(crow::Response& res, const crow::Request& req,
1392 const std::vector<std::string>& params) override
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001393 {
1394 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1395
1396 // Collections don't include the static data added by SubRoute because
1397 // it has a duplicate entry for members
1398 asyncResp->res.jsonValue["@odata.type"] =
1399 "#LogEntryCollection.LogEntryCollection";
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001400 asyncResp->res.jsonValue["@odata.id"] =
1401 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1402 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1403 asyncResp->res.jsonValue["Description"] =
1404 "Collection of System Event Log Entries";
1405
Andrew Geisslercb92c032018-08-17 07:56:14 -07001406 // DBus implementation of EventLog/Entries
1407 // Make call to Logging Service to find all log entry objects
1408 crow::connections::systemBus->async_method_call(
1409 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001410 GetManagedObjectsType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001411 if (ec)
1412 {
1413 // TODO Handle for specific error code
1414 BMCWEB_LOG_ERROR
1415 << "getLogEntriesIfaceData resp_handler got error "
1416 << ec;
1417 messages::internalError(asyncResp->res);
1418 return;
1419 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001420 nlohmann::json& entriesArray =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001421 asyncResp->res.jsonValue["Members"];
1422 entriesArray = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001423 for (auto& objectPath : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001424 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001425 for (auto& interfaceMap : objectPath.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001426 {
1427 if (interfaceMap.first !=
1428 "xyz.openbmc_project.Logging.Entry")
1429 {
1430 BMCWEB_LOG_DEBUG << "Bailing early on "
1431 << interfaceMap.first;
1432 continue;
1433 }
1434 entriesArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001435 nlohmann::json& thisEntry = entriesArray.back();
1436 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001437 std::time_t timestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001438 std::string* severity = nullptr;
1439 std::string* message = nullptr;
1440 for (auto& propertyMap : interfaceMap.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001441 {
1442 if (propertyMap.first == "Id")
1443 {
Patrick Williams8d78b7a2020-05-13 11:24:20 -05001444 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001445 if (id == nullptr)
1446 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001447 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001448 }
1449 }
1450 else if (propertyMap.first == "Timestamp")
1451 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001452 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001453 std::get_if<uint64_t>(&propertyMap.second);
1454 if (millisTimeStamp == nullptr)
1455 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001456 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001457 continue;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001458 }
1459 // Retrieve Created property with format:
1460 // yyyy-mm-ddThh:mm:ss
1461 std::chrono::milliseconds chronoTimeStamp(
1462 *millisTimeStamp);
Ed Tanous271584a2019-07-09 16:24:22 -07001463 timestamp = std::chrono::duration_cast<
1464 std::chrono::duration<int>>(
1465 chronoTimeStamp)
1466 .count();
Andrew Geisslercb92c032018-08-17 07:56:14 -07001467 }
1468 else if (propertyMap.first == "Severity")
1469 {
1470 severity = std::get_if<std::string>(
1471 &propertyMap.second);
1472 if (severity == nullptr)
1473 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001474 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001475 }
1476 }
1477 else if (propertyMap.first == "Message")
1478 {
1479 message = std::get_if<std::string>(
1480 &propertyMap.second);
1481 if (message == nullptr)
1482 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001483 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001484 }
1485 }
1486 }
1487 thisEntry = {
1488 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001489 {"@odata.id",
1490 "/redfish/v1/Systems/system/LogServices/EventLog/"
1491 "Entries/" +
1492 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001493 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001494 {"Id", std::to_string(*id)},
1495 {"Message", *message},
1496 {"EntryType", "Event"},
1497 {"Severity",
1498 translateSeverityDbusToRedfish(*severity)},
1499 {"Created", crow::utility::getDateTime(timestamp)}};
1500 }
1501 }
1502 std::sort(entriesArray.begin(), entriesArray.end(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001503 [](const nlohmann::json& left,
1504 const nlohmann::json& right) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001505 return (left["Id"] <= right["Id"]);
1506 });
1507 asyncResp->res.jsonValue["Members@odata.count"] =
1508 entriesArray.size();
1509 },
1510 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
1511 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001512 }
1513};
1514
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001515class DBusEventLogEntry : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001516{
1517 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001518 DBusEventLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001519 Node(app,
Ed Tanous029573d2019-02-01 10:57:49 -08001520 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1521 std::string())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001522 {
1523 entityPrivileges = {
1524 {boost::beast::http::verb::get, {{"Login"}}},
1525 {boost::beast::http::verb::head, {{"Login"}}},
1526 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1527 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1528 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1529 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1530 }
1531
1532 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001533 void doGet(crow::Response& res, const crow::Request& req,
1534 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001535 {
1536 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous029573d2019-02-01 10:57:49 -08001537 if (params.size() != 1)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001538 {
1539 messages::internalError(asyncResp->res);
1540 return;
1541 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001542 const std::string& entryID = params[0];
Andrew Geisslercb92c032018-08-17 07:56:14 -07001543
Andrew Geisslercb92c032018-08-17 07:56:14 -07001544 // DBus implementation of EventLog/Entries
1545 // Make call to Logging Service to find all log entry objects
1546 crow::connections::systemBus->async_method_call(
1547 [asyncResp, entryID](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001548 GetManagedPropertyType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001549 if (ec)
1550 {
1551 BMCWEB_LOG_ERROR
1552 << "EventLogEntry (DBus) resp_handler got error " << ec;
1553 messages::internalError(asyncResp->res);
1554 return;
1555 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001556 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001557 std::time_t timestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001558 std::string* severity = nullptr;
1559 std::string* message = nullptr;
1560 for (auto& propertyMap : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001561 {
1562 if (propertyMap.first == "Id")
1563 {
1564 id = std::get_if<uint32_t>(&propertyMap.second);
1565 if (id == nullptr)
1566 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001567 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001568 }
1569 }
1570 else if (propertyMap.first == "Timestamp")
1571 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001572 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001573 std::get_if<uint64_t>(&propertyMap.second);
1574 if (millisTimeStamp == nullptr)
1575 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001576 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001577 continue;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001578 }
1579 // Retrieve Created property with format:
1580 // yyyy-mm-ddThh:mm:ss
1581 std::chrono::milliseconds chronoTimeStamp(
1582 *millisTimeStamp);
1583 timestamp =
Ed Tanous271584a2019-07-09 16:24:22 -07001584 std::chrono::duration_cast<
1585 std::chrono::duration<int>>(chronoTimeStamp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001586 .count();
1587 }
1588 else if (propertyMap.first == "Severity")
1589 {
1590 severity =
1591 std::get_if<std::string>(&propertyMap.second);
1592 if (severity == nullptr)
1593 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001594 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001595 }
1596 }
1597 else if (propertyMap.first == "Message")
1598 {
1599 message = std::get_if<std::string>(&propertyMap.second);
1600 if (message == nullptr)
1601 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001602 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001603 }
1604 }
1605 }
Ed Tanous271584a2019-07-09 16:24:22 -07001606 if (id == nullptr || message == nullptr || severity == nullptr)
1607 {
1608 return;
1609 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001610 asyncResp->res.jsonValue = {
1611 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001612 {"@odata.id",
1613 "/redfish/v1/Systems/system/LogServices/EventLog/"
1614 "Entries/" +
1615 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001616 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001617 {"Id", std::to_string(*id)},
1618 {"Message", *message},
1619 {"EntryType", "Event"},
1620 {"Severity", translateSeverityDbusToRedfish(*severity)},
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001621 {"Created", crow::utility::getDateTime(timestamp)}};
Andrew Geisslercb92c032018-08-17 07:56:14 -07001622 },
1623 "xyz.openbmc_project.Logging",
1624 "/xyz/openbmc_project/logging/entry/" + entryID,
1625 "org.freedesktop.DBus.Properties", "GetAll",
1626 "xyz.openbmc_project.Logging.Entry");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001627 }
Chicago Duan336e96c2019-07-15 14:22:08 +08001628
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001629 void doDelete(crow::Response& res, const crow::Request& req,
1630 const std::vector<std::string>& params) override
Chicago Duan336e96c2019-07-15 14:22:08 +08001631 {
1632
1633 BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1634
1635 auto asyncResp = std::make_shared<AsyncResp>(res);
1636
1637 if (params.size() != 1)
1638 {
1639 messages::internalError(asyncResp->res);
1640 return;
1641 }
1642 std::string entryID = params[0];
1643
1644 dbus::utility::escapePathForDbus(entryID);
1645
1646 // Process response from Logging service.
1647 auto respHandler = [asyncResp](const boost::system::error_code ec) {
1648 BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1649 if (ec)
1650 {
1651 // TODO Handle for specific error code
1652 BMCWEB_LOG_ERROR
1653 << "EventLogEntry (DBus) doDelete respHandler got error "
1654 << ec;
1655 asyncResp->res.result(
1656 boost::beast::http::status::internal_server_error);
1657 return;
1658 }
1659
1660 asyncResp->res.result(boost::beast::http::status::ok);
1661 };
1662
1663 // Make call to Logging service to request Delete Log
1664 crow::connections::systemBus->async_method_call(
1665 respHandler, "xyz.openbmc_project.Logging",
1666 "/xyz/openbmc_project/logging/entry/" + entryID,
1667 "xyz.openbmc_project.Object.Delete", "Delete");
1668 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001669};
1670
1671class BMCLogServiceCollection : public Node
1672{
1673 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001674 BMCLogServiceCollection(App& app) :
Ed Tanous4ed77cd2018-10-15 08:08:07 -07001675 Node(app, "/redfish/v1/Managers/bmc/LogServices/")
Ed Tanous1da66f72018-07-27 16:13:37 -07001676 {
Ed Tanous1da66f72018-07-27 16:13:37 -07001677 entityPrivileges = {
Jason M. Billse1f26342018-07-18 12:12:00 -07001678 {boost::beast::http::verb::get, {{"Login"}}},
1679 {boost::beast::http::verb::head, {{"Login"}}},
1680 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1681 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1682 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1683 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07001684 }
1685
1686 private:
1687 /**
1688 * Functions triggers appropriate requests on DBus
1689 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001690 void doGet(crow::Response& res, const crow::Request& req,
1691 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07001692 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001693 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07001694 // Collections don't include the static data added by SubRoute because
1695 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07001696 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001697 "#LogServiceCollection.LogServiceCollection";
Jason M. Billse1f26342018-07-18 12:12:00 -07001698 asyncResp->res.jsonValue["@odata.id"] =
1699 "/redfish/v1/Managers/bmc/LogServices";
1700 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1701 asyncResp->res.jsonValue["Description"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001702 "Collection of LogServices for this Manager";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001703 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001704 logServiceArray = nlohmann::json::array();
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001705#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
1706 logServiceArray.push_back(
1707 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}});
1708#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001709#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
1710 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001711 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001712#endif
Jason M. Billse1f26342018-07-18 12:12:00 -07001713 asyncResp->res.jsonValue["Members@odata.count"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001714 logServiceArray.size();
Ed Tanous1da66f72018-07-27 16:13:37 -07001715 }
1716};
1717
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001718class BMCJournalLogService : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07001719{
1720 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001721 BMCJournalLogService(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001722 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001723 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001724 entityPrivileges = {
1725 {boost::beast::http::verb::get, {{"Login"}}},
1726 {boost::beast::http::verb::head, {{"Login"}}},
1727 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1728 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1729 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1730 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1731 }
1732
1733 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001734 void doGet(crow::Response& res, const crow::Request& req,
1735 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001736 {
1737 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001738 asyncResp->res.jsonValue["@odata.type"] =
1739 "#LogService.v1_1_0.LogService";
Ed Tanous0f74e642018-11-12 15:17:05 -08001740 asyncResp->res.jsonValue["@odata.id"] =
1741 "/redfish/v1/Managers/bmc/LogServices/Journal";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001742 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1743 asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1744 asyncResp->res.jsonValue["Id"] = "BMC Journal";
Jason M. Billse1f26342018-07-18 12:12:00 -07001745 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
Jason M. Billscd50aa42019-02-12 17:09:02 -08001746 asyncResp->res.jsonValue["Entries"] = {
1747 {"@odata.id",
Ed Tanous086be232019-05-23 11:47:09 -07001748 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07001749 }
1750};
1751
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001752static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1753 sd_journal* journal,
1754 nlohmann::json& bmcJournalLogEntryJson)
Jason M. Billse1f26342018-07-18 12:12:00 -07001755{
1756 // Get the Log Entry contents
1757 int ret = 0;
Jason M. Billse1f26342018-07-18 12:12:00 -07001758
Ed Tanous39e77502019-03-04 17:35:53 -08001759 std::string_view msg;
Jason M. Bills16428a12018-11-02 12:42:29 -07001760 ret = getJournalMetadata(journal, "MESSAGE", msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001761 if (ret < 0)
1762 {
1763 BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1764 return 1;
1765 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001766
1767 // Get the severity from the PRIORITY field
Ed Tanous271584a2019-07-09 16:24:22 -07001768 long int severity = 8; // Default to an invalid priority
Jason M. Bills16428a12018-11-02 12:42:29 -07001769 ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
Jason M. Billse1f26342018-07-18 12:12:00 -07001770 if (ret < 0)
1771 {
1772 BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
Jason M. Billse1f26342018-07-18 12:12:00 -07001773 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001774
1775 // Get the Created time from the timestamp
Jason M. Bills16428a12018-11-02 12:42:29 -07001776 std::string entryTimeStr;
1777 if (!getEntryTimestamp(journal, entryTimeStr))
Jason M. Billse1f26342018-07-18 12:12:00 -07001778 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001779 return 1;
Jason M. Billse1f26342018-07-18 12:12:00 -07001780 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001781
1782 // Fill in the log entry with the gathered data
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001783 bmcJournalLogEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001784 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001785 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
1786 bmcJournalLogEntryID},
Jason M. Billse1f26342018-07-18 12:12:00 -07001787 {"Name", "BMC Journal Entry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001788 {"Id", bmcJournalLogEntryID},
Jason M. Bills16428a12018-11-02 12:42:29 -07001789 {"Message", msg},
Jason M. Billse1f26342018-07-18 12:12:00 -07001790 {"EntryType", "Oem"},
1791 {"Severity",
Jason M. Billsb6a61a52019-08-01 14:26:15 -07001792 severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"},
Ed Tanous086be232019-05-23 11:47:09 -07001793 {"OemRecordFormat", "BMC Journal Entry"},
Jason M. Billse1f26342018-07-18 12:12:00 -07001794 {"Created", std::move(entryTimeStr)}};
1795 return 0;
1796}
1797
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001798class BMCJournalLogEntryCollection : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001799{
1800 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001801 BMCJournalLogEntryCollection(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001802 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001803 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001804 entityPrivileges = {
1805 {boost::beast::http::verb::get, {{"Login"}}},
1806 {boost::beast::http::verb::head, {{"Login"}}},
1807 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1808 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1809 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1810 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1811 }
1812
1813 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001814 void doGet(crow::Response& res, const crow::Request& req,
1815 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001816 {
1817 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001818 static constexpr const long maxEntriesPerPage = 1000;
Ed Tanous271584a2019-07-09 16:24:22 -07001819 uint64_t skip = 0;
1820 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Bills16428a12018-11-02 12:42:29 -07001821 if (!getSkipParam(asyncResp->res, req, skip))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001822 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001823 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001824 }
Jason M. Bills16428a12018-11-02 12:42:29 -07001825 if (!getTopParam(asyncResp->res, req, top))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001826 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001827 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001828 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001829 // Collections don't include the static data added by SubRoute because
1830 // it has a duplicate entry for members
1831 asyncResp->res.jsonValue["@odata.type"] =
1832 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08001833 asyncResp->res.jsonValue["@odata.id"] =
1834 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001835 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001836 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001837 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
1838 asyncResp->res.jsonValue["Description"] =
1839 "Collection of BMC Journal Entries";
Ed Tanous0f74e642018-11-12 15:17:05 -08001840 asyncResp->res.jsonValue["@odata.id"] =
1841 "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001842 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07001843 logEntryArray = nlohmann::json::array();
1844
1845 // Go through the journal and use the timestamp to create a unique ID
1846 // for each entry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001847 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001848 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1849 if (ret < 0)
1850 {
1851 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001852 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001853 return;
1854 }
1855 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1856 journalTmp, sd_journal_close);
1857 journalTmp = nullptr;
Ed Tanousb01bf292019-03-25 19:25:26 +00001858 uint64_t entryCount = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001859 // Reset the unique ID on the first entry
1860 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001861 SD_JOURNAL_FOREACH(journal.get())
1862 {
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001863 entryCount++;
1864 // Handle paging using skip (number of entries to skip from the
1865 // start) and top (number of entries to display)
1866 if (entryCount <= skip || entryCount > skip + top)
1867 {
1868 continue;
1869 }
1870
Jason M. Bills16428a12018-11-02 12:42:29 -07001871 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001872 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
Jason M. Billse1f26342018-07-18 12:12:00 -07001873 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001874 continue;
1875 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001876
Jason M. Billse85d6b12019-07-29 17:01:15 -07001877 if (firstEntry)
1878 {
1879 firstEntry = false;
1880 }
1881
Jason M. Billse1f26342018-07-18 12:12:00 -07001882 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001883 nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001884 if (fillBMCJournalLogEntryJson(idStr, journal.get(),
1885 bmcJournalLogEntry) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001886 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001887 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001888 return;
1889 }
1890 }
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001891 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1892 if (skip + top < entryCount)
1893 {
1894 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001895 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001896 std::to_string(skip + top);
1897 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001898 }
1899};
1900
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001901class BMCJournalLogEntry : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001902{
1903 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001904 BMCJournalLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001905 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
Jason M. Billse1f26342018-07-18 12:12:00 -07001906 std::string())
1907 {
1908 entityPrivileges = {
1909 {boost::beast::http::verb::get, {{"Login"}}},
1910 {boost::beast::http::verb::head, {{"Login"}}},
1911 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1912 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1913 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1914 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1915 }
1916
1917 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001918 void doGet(crow::Response& res, const crow::Request& req,
1919 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001920 {
1921 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1922 if (params.size() != 1)
1923 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001924 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001925 return;
1926 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001927 const std::string& entryID = params[0];
Jason M. Billse1f26342018-07-18 12:12:00 -07001928 // Convert the unique ID back to a timestamp to find the entry
Jason M. Billse1f26342018-07-18 12:12:00 -07001929 uint64_t ts = 0;
Ed Tanous271584a2019-07-09 16:24:22 -07001930 uint64_t index = 0;
Jason M. Bills16428a12018-11-02 12:42:29 -07001931 if (!getTimestampFromID(asyncResp->res, entryID, ts, index))
Jason M. Billse1f26342018-07-18 12:12:00 -07001932 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001933 return;
Jason M. Billse1f26342018-07-18 12:12:00 -07001934 }
1935
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001936 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001937 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1938 if (ret < 0)
1939 {
1940 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001941 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001942 return;
1943 }
1944 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1945 journalTmp, sd_journal_close);
1946 journalTmp = nullptr;
1947 // Go to the timestamp in the log and move to the entry at the index
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001948 // tracking the unique ID
1949 std::string idStr;
1950 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001951 ret = sd_journal_seek_realtime_usec(journal.get(), ts);
Manojkiran Eda2056b6d2020-05-28 08:57:36 +05301952 if (ret < 0)
1953 {
1954 BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
1955 << strerror(-ret);
1956 messages::internalError(asyncResp->res);
1957 return;
1958 }
Ed Tanous271584a2019-07-09 16:24:22 -07001959 for (uint64_t i = 0; i <= index; i++)
Jason M. Billse1f26342018-07-18 12:12:00 -07001960 {
1961 sd_journal_next(journal.get());
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001962 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
1963 {
1964 messages::internalError(asyncResp->res);
1965 return;
1966 }
1967 if (firstEntry)
1968 {
1969 firstEntry = false;
1970 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001971 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001972 // Confirm that the entry ID matches what was requested
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001973 if (idStr != entryID)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001974 {
1975 messages::resourceMissingAtURI(asyncResp->res, entryID);
1976 return;
1977 }
1978
1979 if (fillBMCJournalLogEntryJson(entryID, journal.get(),
1980 asyncResp->res.jsonValue) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001981 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001982 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001983 return;
1984 }
1985 }
1986};
1987
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001988class BMCDumpService : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06001989{
1990 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001991 BMCDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001992 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
raviteja-bc9bb6862020-02-03 11:53:32 -06001993 {
1994 entityPrivileges = {
1995 {boost::beast::http::verb::get, {{"Login"}}},
1996 {boost::beast::http::verb::head, {{"Login"}}},
1997 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1998 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1999 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2000 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2001 }
2002
2003 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002004 void doGet(crow::Response& res, const crow::Request& req,
2005 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002006 {
2007 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2008
2009 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002010 "/redfish/v1/Managers/bmc/LogServices/Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002011 asyncResp->res.jsonValue["@odata.type"] =
2012 "#LogService.v1_1_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002013 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2014 asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
2015 asyncResp->res.jsonValue["Id"] = "Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002016 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
raviteja-bc9bb6862020-02-03 11:53:32 -06002017 asyncResp->res.jsonValue["Entries"] = {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002018 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
2019 asyncResp->res.jsonValue["Actions"] = {
2020 {"#LogService.ClearLog",
2021 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2022 "Actions/LogService.ClearLog"}}},
2023 {"Oem",
2024 {{"#OemLogService.CollectDiagnosticData",
2025 {{"target",
2026 "/redfish/v1/Managers/bmc/LogServices/Dump/"
2027 "Actions/Oem/OemLogService.CollectDiagnosticData"}}}}}};
raviteja-bc9bb6862020-02-03 11:53:32 -06002028 }
2029};
2030
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002031class BMCDumpEntryCollection : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002032{
2033 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002034 BMCDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002035 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002036 {
2037 entityPrivileges = {
2038 {boost::beast::http::verb::get, {{"Login"}}},
2039 {boost::beast::http::verb::head, {{"Login"}}},
2040 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2041 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2042 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2043 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2044 }
2045
2046 private:
2047 /**
2048 * Functions triggers appropriate requests on DBus
2049 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002050 void doGet(crow::Response& res, const crow::Request& req,
2051 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002052 {
2053 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2054
2055 asyncResp->res.jsonValue["@odata.type"] =
2056 "#LogEntryCollection.LogEntryCollection";
2057 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002058 "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
2059 asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002060 asyncResp->res.jsonValue["Description"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002061 "Collection of BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002062
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002063 getDumpEntryCollection(asyncResp, "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002064 }
2065};
2066
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002067class BMCDumpEntry : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002068{
2069 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002070 BMCDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002071 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
raviteja-bc9bb6862020-02-03 11:53:32 -06002072 std::string())
2073 {
2074 entityPrivileges = {
2075 {boost::beast::http::verb::get, {{"Login"}}},
2076 {boost::beast::http::verb::head, {{"Login"}}},
2077 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2078 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2079 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2080 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2081 }
2082
2083 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002084 void doGet(crow::Response& res, const crow::Request& req,
2085 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002086 {
2087 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2088 if (params.size() != 1)
2089 {
2090 messages::internalError(asyncResp->res);
2091 return;
2092 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002093 getDumpEntryById(asyncResp, params[0], "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002094 }
2095
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002096 void doDelete(crow::Response& res, const crow::Request& req,
2097 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002098 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002099 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002100 if (params.size() != 1)
2101 {
2102 messages::internalError(asyncResp->res);
2103 return;
2104 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002105 deleteDumpEntry(asyncResp->res, params[0]);
2106 }
2107};
raviteja-bc9bb6862020-02-03 11:53:32 -06002108
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002109class BMCDumpCreate : public Node
2110{
2111 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002112 BMCDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002113 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2114 "Actions/Oem/"
2115 "OemLogService.CollectDiagnosticData/")
2116 {
2117 entityPrivileges = {
2118 {boost::beast::http::verb::get, {{"Login"}}},
2119 {boost::beast::http::verb::head, {{"Login"}}},
2120 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2121 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2122 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2123 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2124 }
2125
2126 private:
2127 void doPost(crow::Response& res, const crow::Request& req,
2128 const std::vector<std::string>& params) override
2129 {
2130 createDump(res, req, "BMC");
2131 }
2132};
2133
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002134class BMCDumpEntryDownload : public Node
2135{
2136 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002137 BMCDumpEntryDownload(App& app) :
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002138 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/attachment/<str>/",
2139 std::string())
2140 {
2141 entityPrivileges = {
2142 {boost::beast::http::verb::get, {{"Login"}}},
2143 {boost::beast::http::verb::head, {{"Login"}}},
2144 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2145 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2146 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2147 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2148 }
2149
2150 private:
2151 void doGet(crow::Response& res, const crow::Request& req,
2152 const std::vector<std::string>& params) override
2153 {
2154 if (params.size() != 1)
2155 {
2156 messages::internalError(res);
2157 return;
2158 }
2159 const std::string& entryID = params[0];
2160 crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID);
2161 }
2162};
2163
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002164class BMCDumpClear : public Node
2165{
2166 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002167 BMCDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002168 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2169 "Actions/"
2170 "LogService.ClearLog/")
2171 {
2172 entityPrivileges = {
2173 {boost::beast::http::verb::get, {{"Login"}}},
2174 {boost::beast::http::verb::head, {{"Login"}}},
2175 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2176 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2177 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2178 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2179 }
2180
2181 private:
2182 void doPost(crow::Response& res, const crow::Request& req,
2183 const std::vector<std::string>& params) override
2184 {
2185 clearDump(res, "xyz.openbmc_project.Dump.Entry.BMC");
2186 }
2187};
2188
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002189class SystemDumpService : public Node
2190{
2191 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002192 SystemDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002193 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
2194 {
2195 entityPrivileges = {
2196 {boost::beast::http::verb::get, {{"Login"}}},
2197 {boost::beast::http::verb::head, {{"Login"}}},
2198 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2199 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2200 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2201 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2202 }
raviteja-bc9bb6862020-02-03 11:53:32 -06002203
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002204 private:
2205 void doGet(crow::Response& res, const crow::Request& req,
2206 const std::vector<std::string>& params) override
2207 {
2208 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002209
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002210 asyncResp->res.jsonValue["@odata.id"] =
2211 "/redfish/v1/Systems/system/LogServices/Dump";
2212 asyncResp->res.jsonValue["@odata.type"] =
2213 "#LogService.v1_1_0.LogService";
2214 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2215 asyncResp->res.jsonValue["Description"] = "System Dump LogService";
2216 asyncResp->res.jsonValue["Id"] = "Dump";
2217 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2218 asyncResp->res.jsonValue["Entries"] = {
2219 {"@odata.id",
2220 "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
2221 asyncResp->res.jsonValue["Actions"] = {
2222 {"#LogService.ClearLog",
2223 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2224 "LogService.ClearLog"}}},
2225 {"Oem",
2226 {{"#OemLogService.CollectDiagnosticData",
2227 {{"target",
2228 "/redfish/v1/Systems/system/LogServices/Dump/Actions/Oem/"
2229 "OemLogService.CollectDiagnosticData"}}}}}};
2230 }
2231};
2232
2233class SystemDumpEntryCollection : public Node
2234{
2235 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002236 SystemDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002237 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
2238 {
2239 entityPrivileges = {
2240 {boost::beast::http::verb::get, {{"Login"}}},
2241 {boost::beast::http::verb::head, {{"Login"}}},
2242 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2243 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2244 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2245 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2246 }
2247
2248 private:
2249 /**
2250 * Functions triggers appropriate requests on DBus
2251 */
2252 void doGet(crow::Response& res, const crow::Request& req,
2253 const std::vector<std::string>& params) override
2254 {
2255 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2256
2257 asyncResp->res.jsonValue["@odata.type"] =
2258 "#LogEntryCollection.LogEntryCollection";
2259 asyncResp->res.jsonValue["@odata.id"] =
2260 "/redfish/v1/Systems/system/LogServices/Dump/Entries";
2261 asyncResp->res.jsonValue["Name"] = "System Dump Entries";
2262 asyncResp->res.jsonValue["Description"] =
2263 "Collection of System Dump Entries";
2264
2265 getDumpEntryCollection(asyncResp, "System");
2266 }
2267};
2268
2269class SystemDumpEntry : public Node
2270{
2271 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002272 SystemDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002273 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
2274 std::string())
2275 {
2276 entityPrivileges = {
2277 {boost::beast::http::verb::get, {{"Login"}}},
2278 {boost::beast::http::verb::head, {{"Login"}}},
2279 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2280 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2281 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2282 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2283 }
2284
2285 private:
2286 void doGet(crow::Response& res, const crow::Request& req,
2287 const std::vector<std::string>& params) override
2288 {
2289 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2290 if (params.size() != 1)
2291 {
2292 messages::internalError(asyncResp->res);
2293 return;
2294 }
2295 getDumpEntryById(asyncResp, params[0], "System");
2296 }
2297
2298 void doDelete(crow::Response& res, const crow::Request& req,
2299 const std::vector<std::string>& params) override
2300 {
2301 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2302 if (params.size() != 1)
2303 {
2304 messages::internalError(asyncResp->res);
2305 return;
2306 }
2307 deleteDumpEntry(asyncResp->res, params[0]);
raviteja-bc9bb6862020-02-03 11:53:32 -06002308 }
2309};
2310
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002311class SystemDumpCreate : public Node
2312{
2313 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002314 SystemDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002315 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
2316 "Actions/Oem/"
2317 "OemLogService.CollectDiagnosticData/")
2318 {
2319 entityPrivileges = {
2320 {boost::beast::http::verb::get, {{"Login"}}},
2321 {boost::beast::http::verb::head, {{"Login"}}},
2322 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2323 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2324 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2325 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2326 }
2327
2328 private:
2329 void doPost(crow::Response& res, const crow::Request& req,
2330 const std::vector<std::string>& params) override
2331 {
2332 createDump(res, req, "System");
2333 }
2334};
2335
raviteja-b06578432020-02-03 12:50:42 -06002336class SystemDumpEntryDownload : public Node
2337{
2338 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002339 SystemDumpEntryDownload(App& app) :
raviteja-b06578432020-02-03 12:50:42 -06002340 Node(app,
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002341 "/redfish/v1/Systems/system/LogServices/Dump/attachment/<str>/",
raviteja-b06578432020-02-03 12:50:42 -06002342 std::string())
2343 {
2344 entityPrivileges = {
2345 {boost::beast::http::verb::get, {{"Login"}}},
2346 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002347 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2348 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2349 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b06578432020-02-03 12:50:42 -06002350 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2351 }
2352
2353 private:
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002354 void doGet(crow::Response& res, const crow::Request& req,
2355 const std::vector<std::string>& params) override
raviteja-b06578432020-02-03 12:50:42 -06002356 {
2357 if (params.size() != 1)
2358 {
2359 messages::internalError(res);
2360 return;
2361 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002362 const std::string& entryID = params[0];
raviteja-b06578432020-02-03 12:50:42 -06002363 crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID);
2364 }
2365};
2366
raviteja-b013487e2020-03-03 03:20:48 -06002367class SystemDumpClear : public Node
2368{
2369 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002370 SystemDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002371 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
raviteja-b013487e2020-03-03 03:20:48 -06002372 "Actions/"
2373 "LogService.ClearLog/")
2374 {
2375 entityPrivileges = {
2376 {boost::beast::http::verb::get, {{"Login"}}},
2377 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002378 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2379 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2380 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b013487e2020-03-03 03:20:48 -06002381 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2382 }
2383
2384 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002385 void doPost(crow::Response& res, const crow::Request& req,
2386 const std::vector<std::string>& params) override
raviteja-b013487e2020-03-03 03:20:48 -06002387 {
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002388 clearDump(res, "xyz.openbmc_project.Dump.Entry.System");
raviteja-b013487e2020-03-03 03:20:48 -06002389 }
2390};
2391
Jason M. Bills424c4172019-03-21 13:50:33 -07002392class CrashdumpService : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002393{
2394 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002395 CrashdumpService(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002396 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002397 {
AppaRao Puli39460282020-04-07 17:03:04 +05302398 // Note: Deviated from redfish privilege registry for GET & HEAD
2399 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002400 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302401 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2402 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002403 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2404 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2405 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2406 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002407 }
2408
2409 private:
2410 /**
2411 * Functions triggers appropriate requests on DBus
2412 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002413 void doGet(crow::Response& res, const crow::Request& req,
2414 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002415 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002416 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002417 // Copy over the static data to include the entries added by SubRoute
Ed Tanous0f74e642018-11-12 15:17:05 -08002418 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002419 "/redfish/v1/Systems/system/LogServices/Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002420 asyncResp->res.jsonValue["@odata.type"] =
2421 "#LogService.v1_1_0.LogService";
Gunnar Mills4f50ae42020-02-06 15:29:57 -06002422 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2423 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2424 asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002425 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2426 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Jason M. Billscd50aa42019-02-12 17:09:02 -08002427 asyncResp->res.jsonValue["Entries"] = {
2428 {"@odata.id",
Jason M. Bills424c4172019-03-21 13:50:33 -07002429 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07002430 asyncResp->res.jsonValue["Actions"] = {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002431 {"#LogService.ClearLog",
2432 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2433 "Actions/LogService.ClearLog"}}},
Ed Tanous1da66f72018-07-27 16:13:37 -07002434 {"Oem",
Jason M. Bills424c4172019-03-21 13:50:33 -07002435 {{"#Crashdump.OnDemand",
2436 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002437 "Actions/Oem/Crashdump.OnDemand"}}},
2438 {"#Crashdump.Telemetry",
2439 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2440 "Actions/Oem/Crashdump.Telemetry"}}}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002441
2442#ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
Jason M. Billse1f26342018-07-18 12:12:00 -07002443 asyncResp->res.jsonValue["Actions"]["Oem"].push_back(
Jason M. Bills424c4172019-03-21 13:50:33 -07002444 {"#Crashdump.SendRawPeci",
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05002445 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2446 "Actions/Oem/Crashdump.SendRawPeci"}}});
Ed Tanous1da66f72018-07-27 16:13:37 -07002447#endif
Ed Tanous1da66f72018-07-27 16:13:37 -07002448 }
2449};
2450
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002451class CrashdumpClear : public Node
2452{
2453 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002454 CrashdumpClear(App& app) :
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002455 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2456 "LogService.ClearLog/")
2457 {
AppaRao Puli39460282020-04-07 17:03:04 +05302458 // Note: Deviated from redfish privilege registry for GET & HEAD
2459 // method for security reasons.
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002460 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302461 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2462 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002463 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2464 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2465 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2466 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2467 }
2468
2469 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002470 void doPost(crow::Response& res, const crow::Request& req,
2471 const std::vector<std::string>& params) override
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002472 {
2473 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2474
2475 crow::connections::systemBus->async_method_call(
2476 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002477 const std::string& resp) {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002478 if (ec)
2479 {
2480 messages::internalError(asyncResp->res);
2481 return;
2482 }
2483 messages::success(asyncResp->res);
2484 },
2485 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
2486 }
2487};
2488
Jason M. Billse855dd22019-10-08 11:37:48 -07002489static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002490 const std::string& logID,
2491 nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002492{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002493 auto getStoredLogCallback =
2494 [asyncResp, logID, &logEntryJson](
2495 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002496 const std::vector<std::pair<std::string, VariantType>>& params) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002497 if (ec)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002498 {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002499 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
2500 if (ec.value() ==
2501 boost::system::linux_error::bad_request_descriptor)
2502 {
2503 messages::resourceNotFound(asyncResp->res, "LogEntry",
2504 logID);
2505 }
2506 else
2507 {
2508 messages::internalError(asyncResp->res);
2509 }
2510 return;
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002511 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002512
Johnathan Mantey043a0532020-03-10 17:15:28 -07002513 std::string timestamp{};
2514 std::string filename{};
2515 std::string logfile{};
2516 ParseCrashdumpParameters(params, filename, timestamp, logfile);
2517
2518 if (filename.empty() || timestamp.empty())
2519 {
2520 messages::resourceMissingAtURI(asyncResp->res, logID);
2521 return;
2522 }
2523
2524 std::string crashdumpURI =
2525 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2526 logID + "/" + filename;
2527 logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
2528 {"@odata.id", "/redfish/v1/Systems/system/"
2529 "LogServices/Crashdump/Entries/" +
2530 logID},
2531 {"Name", "CPU Crashdump"},
2532 {"Id", logID},
2533 {"EntryType", "Oem"},
2534 {"OemRecordFormat", "Crashdump URI"},
2535 {"Message", std::move(crashdumpURI)},
2536 {"Created", std::move(timestamp)}};
2537 };
Jason M. Billse855dd22019-10-08 11:37:48 -07002538 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002539 std::move(getStoredLogCallback), crashdumpObject,
2540 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002541 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Jason M. Billse855dd22019-10-08 11:37:48 -07002542}
2543
Jason M. Bills424c4172019-03-21 13:50:33 -07002544class CrashdumpEntryCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002545{
2546 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002547 CrashdumpEntryCollection(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002548 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002549 {
AppaRao Puli39460282020-04-07 17:03:04 +05302550 // Note: Deviated from redfish privilege registry for GET & HEAD
2551 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002552 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302553 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2554 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002555 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2556 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2557 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2558 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002559 }
2560
2561 private:
2562 /**
2563 * Functions triggers appropriate requests on DBus
2564 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002565 void doGet(crow::Response& res, const crow::Request& req,
2566 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002567 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002568 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002569 // Collections don't include the static data added by SubRoute because
2570 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07002571 auto getLogEntriesCallback = [asyncResp](
2572 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002573 const std::vector<std::string>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002574 if (ec)
2575 {
2576 if (ec.value() !=
2577 boost::system::errc::no_such_file_or_directory)
Ed Tanous1da66f72018-07-27 16:13:37 -07002578 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002579 BMCWEB_LOG_DEBUG << "failed to get entries ec: "
2580 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002581 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002582 return;
Ed Tanous1da66f72018-07-27 16:13:37 -07002583 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002584 }
2585 asyncResp->res.jsonValue["@odata.type"] =
2586 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08002587 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002588 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
Jason M. Bills424c4172019-03-21 13:50:33 -07002589 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002590 asyncResp->res.jsonValue["Description"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002591 "Collection of Crashdump Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002592 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07002593 logEntryArray = nlohmann::json::array();
Jason M. Billse855dd22019-10-08 11:37:48 -07002594 std::vector<std::string> logIDs;
2595 // Get the list of log entries and build up an empty array big
2596 // enough to hold them
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002597 for (const std::string& objpath : resp)
Jason M. Billse1f26342018-07-18 12:12:00 -07002598 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002599 // Get the log ID
Jason M. Billse1f26342018-07-18 12:12:00 -07002600 std::size_t lastPos = objpath.rfind("/");
Jason M. Billse855dd22019-10-08 11:37:48 -07002601 if (lastPos == std::string::npos)
Jason M. Billse1f26342018-07-18 12:12:00 -07002602 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002603 continue;
Jason M. Billse1f26342018-07-18 12:12:00 -07002604 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002605 logIDs.emplace_back(objpath.substr(lastPos + 1));
2606
2607 // Add a space for the log entry to the array
2608 logEntryArray.push_back({});
2609 }
2610 // Now go through and set up async calls to fill in the entries
2611 size_t index = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002612 for (const std::string& logID : logIDs)
Jason M. Billse855dd22019-10-08 11:37:48 -07002613 {
2614 // Add the log entry to the array
2615 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
Jason M. Billse1f26342018-07-18 12:12:00 -07002616 }
2617 asyncResp->res.jsonValue["Members@odata.count"] =
2618 logEntryArray.size();
2619 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002620 crow::connections::systemBus->async_method_call(
2621 std::move(getLogEntriesCallback),
2622 "xyz.openbmc_project.ObjectMapper",
2623 "/xyz/openbmc_project/object_mapper",
2624 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002625 std::array<const char*, 1>{crashdumpInterface});
Ed Tanous1da66f72018-07-27 16:13:37 -07002626 }
2627};
2628
Jason M. Bills424c4172019-03-21 13:50:33 -07002629class CrashdumpEntry : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002630{
2631 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002632 CrashdumpEntry(App& app) :
Jason M. Billsd53dd412019-02-12 17:16:22 -08002633 Node(app,
Jason M. Bills424c4172019-03-21 13:50:33 -07002634 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
Ed Tanous1da66f72018-07-27 16:13:37 -07002635 std::string())
2636 {
AppaRao Puli39460282020-04-07 17:03:04 +05302637 // Note: Deviated from redfish privilege registry for GET & HEAD
2638 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002639 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302640 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2641 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002642 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2643 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2644 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2645 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002646 }
2647
2648 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002649 void doGet(crow::Response& res, const crow::Request& req,
2650 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002651 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002652 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002653 if (params.size() != 1)
2654 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002655 messages::internalError(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002656 return;
2657 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002658 const std::string& logID = params[0];
Jason M. Billse855dd22019-10-08 11:37:48 -07002659 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2660 }
2661};
2662
2663class CrashdumpFile : public Node
2664{
2665 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002666 CrashdumpFile(App& app) :
Jason M. Billse855dd22019-10-08 11:37:48 -07002667 Node(app,
2668 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2669 "<str>/",
2670 std::string(), std::string())
2671 {
AppaRao Puli39460282020-04-07 17:03:04 +05302672 // Note: Deviated from redfish privilege registry for GET & HEAD
2673 // method for security reasons.
Jason M. Billse855dd22019-10-08 11:37:48 -07002674 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302675 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2676 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse855dd22019-10-08 11:37:48 -07002677 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2678 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2679 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2680 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2681 }
2682
2683 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002684 void doGet(crow::Response& res, const crow::Request& req,
2685 const std::vector<std::string>& params) override
Jason M. Billse855dd22019-10-08 11:37:48 -07002686 {
2687 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2688 if (params.size() != 2)
2689 {
2690 messages::internalError(asyncResp->res);
2691 return;
2692 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002693 const std::string& logID = params[0];
2694 const std::string& fileName = params[1];
Jason M. Billse855dd22019-10-08 11:37:48 -07002695
Johnathan Mantey043a0532020-03-10 17:15:28 -07002696 auto getStoredLogCallback =
2697 [asyncResp, logID, fileName](
2698 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002699 const std::vector<std::pair<std::string, VariantType>>& resp) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002700 if (ec)
2701 {
2702 BMCWEB_LOG_DEBUG << "failed to get log ec: "
2703 << ec.message();
2704 messages::internalError(asyncResp->res);
2705 return;
2706 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002707
Johnathan Mantey043a0532020-03-10 17:15:28 -07002708 std::string dbusFilename{};
2709 std::string dbusTimestamp{};
2710 std::string dbusFilepath{};
Jason M. Billse855dd22019-10-08 11:37:48 -07002711
Johnathan Mantey043a0532020-03-10 17:15:28 -07002712 ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
2713 dbusFilepath);
2714
2715 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2716 dbusFilepath.empty())
2717 {
2718 messages::resourceMissingAtURI(asyncResp->res, fileName);
2719 return;
2720 }
2721
2722 // Verify the file name parameter is correct
2723 if (fileName != dbusFilename)
2724 {
2725 messages::resourceMissingAtURI(asyncResp->res, fileName);
2726 return;
2727 }
2728
2729 if (!std::filesystem::exists(dbusFilepath))
2730 {
2731 messages::resourceMissingAtURI(asyncResp->res, fileName);
2732 return;
2733 }
2734 std::ifstream ifs(dbusFilepath, std::ios::in |
2735 std::ios::binary |
2736 std::ios::ate);
2737 std::ifstream::pos_type fileSize = ifs.tellg();
2738 if (fileSize < 0)
2739 {
2740 messages::generalError(asyncResp->res);
2741 return;
2742 }
2743 ifs.seekg(0, std::ios::beg);
2744
2745 auto crashData = std::make_unique<char[]>(
2746 static_cast<unsigned int>(fileSize));
2747
2748 ifs.read(crashData.get(), static_cast<int>(fileSize));
2749
2750 // The cast to std::string is intentional in order to use the
2751 // assign() that applies move mechanics
2752 asyncResp->res.body().assign(
2753 static_cast<std::string>(crashData.get()));
2754
2755 // Configure this to be a file download when accessed from
2756 // a browser
2757 asyncResp->res.addHeader("Content-Disposition", "attachment");
2758 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002759 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002760 std::move(getStoredLogCallback), crashdumpObject,
2761 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002762 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Ed Tanous1da66f72018-07-27 16:13:37 -07002763 }
2764};
2765
Jason M. Bills424c4172019-03-21 13:50:33 -07002766class OnDemandCrashdump : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002767{
2768 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002769 OnDemandCrashdump(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002770 Node(app,
2771 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2772 "Crashdump.OnDemand/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002773 {
AppaRao Puli39460282020-04-07 17:03:04 +05302774 // Note: Deviated from redfish privilege registry for GET & HEAD
2775 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002776 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302777 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2778 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2779 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2780 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2781 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2782 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002783 }
2784
2785 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002786 void doPost(crow::Response& res, const crow::Request& req,
2787 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002788 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002789 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002790
James Feistfe306722020-03-12 16:32:08 -07002791 auto generateonDemandLogCallback = [asyncResp,
2792 req](const boost::system::error_code
2793 ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002794 const std::string& resp) {
James Feist46229572020-02-19 15:11:58 -08002795 if (ec)
2796 {
2797 if (ec.value() == boost::system::errc::operation_not_supported)
Ed Tanous1da66f72018-07-27 16:13:37 -07002798 {
James Feist46229572020-02-19 15:11:58 -08002799 messages::resourceInStandby(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002800 }
James Feist46229572020-02-19 15:11:58 -08002801 else if (ec.value() ==
2802 boost::system::errc::device_or_resource_busy)
2803 {
2804 messages::serviceTemporarilyUnavailable(asyncResp->res,
2805 "60");
2806 }
2807 else
2808 {
2809 messages::internalError(asyncResp->res);
2810 }
2811 return;
2812 }
2813 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002814 [](boost::system::error_code err, sdbusplus::message::message&,
2815 const std::shared_ptr<task::TaskData>& taskData) {
James Feist66afe4f2020-02-24 13:09:58 -08002816 if (!err)
2817 {
James Feiste5d50062020-05-11 17:29:00 -07002818 taskData->messages.emplace_back(
2819 messages::taskCompletedOK(
2820 std::to_string(taskData->index)));
James Feist831d6b02020-03-12 16:31:30 -07002821 taskData->state = "Completed";
James Feist66afe4f2020-02-24 13:09:58 -08002822 }
James Feist32898ce2020-03-10 16:16:52 -07002823 return task::completed;
James Feist66afe4f2020-02-24 13:09:58 -08002824 },
James Feist46229572020-02-19 15:11:58 -08002825 "type='signal',interface='org.freedesktop.DBus.Properties',"
2826 "member='PropertiesChanged',arg0namespace='com.intel."
2827 "crashdump'");
2828 task->startTimer(std::chrono::minutes(5));
2829 task->populateResp(asyncResp->res);
James Feistfe306722020-03-12 16:32:08 -07002830 task->payload.emplace(req);
James Feist46229572020-02-19 15:11:58 -08002831 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002832 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002833 std::move(generateonDemandLogCallback), crashdumpObject,
2834 crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog");
Ed Tanous1da66f72018-07-27 16:13:37 -07002835 }
2836};
2837
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002838class TelemetryCrashdump : public Node
2839{
2840 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002841 TelemetryCrashdump(App& app) :
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002842 Node(app,
2843 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2844 "Crashdump.Telemetry/")
2845 {
2846 // Note: Deviated from redfish privilege registry for GET & HEAD
2847 // method for security reasons.
2848 entityPrivileges = {
2849 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2850 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2851 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2852 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2853 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2854 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2855 }
2856
2857 private:
2858 void doPost(crow::Response& res, const crow::Request& req,
2859 const std::vector<std::string>& params) override
2860 {
2861 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2862
2863 auto generateTelemetryLogCallback = [asyncResp, req](
2864 const boost::system::error_code
2865 ec,
2866 const std::string& resp) {
2867 if (ec)
2868 {
2869 if (ec.value() == boost::system::errc::operation_not_supported)
2870 {
2871 messages::resourceInStandby(asyncResp->res);
2872 }
2873 else if (ec.value() ==
2874 boost::system::errc::device_or_resource_busy)
2875 {
2876 messages::serviceTemporarilyUnavailable(asyncResp->res,
2877 "60");
2878 }
2879 else
2880 {
2881 messages::internalError(asyncResp->res);
2882 }
2883 return;
2884 }
2885 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
2886 [](boost::system::error_code err, sdbusplus::message::message&,
2887 const std::shared_ptr<task::TaskData>& taskData) {
2888 if (!err)
2889 {
2890 taskData->messages.emplace_back(
2891 messages::taskCompletedOK(
2892 std::to_string(taskData->index)));
2893 taskData->state = "Completed";
2894 }
2895 return task::completed;
2896 },
2897 "type='signal',interface='org.freedesktop.DBus.Properties',"
2898 "member='PropertiesChanged',arg0namespace='com.intel."
2899 "crashdump'");
2900 task->startTimer(std::chrono::minutes(5));
2901 task->populateResp(asyncResp->res);
2902 task->payload.emplace(req);
2903 };
2904 crow::connections::systemBus->async_method_call(
2905 std::move(generateTelemetryLogCallback), crashdumpObject,
2906 crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog");
2907 }
2908};
2909
Jason M. Billse1f26342018-07-18 12:12:00 -07002910class SendRawPECI : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002911{
2912 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002913 SendRawPECI(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002914 Node(app,
2915 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2916 "Crashdump.SendRawPeci/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002917 {
AppaRao Puli39460282020-04-07 17:03:04 +05302918 // Note: Deviated from redfish privilege registry for GET & HEAD
2919 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002920 entityPrivileges = {
2921 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2922 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2923 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2924 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2925 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2926 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2927 }
2928
2929 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002930 void doPost(crow::Response& res, const crow::Request& req,
2931 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002932 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002933 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002934 std::vector<std::vector<uint8_t>> peciCommands;
Ed Tanousb1556422018-10-16 14:09:17 -07002935
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002936 nlohmann::json reqJson =
2937 nlohmann::json::parse(req.body, nullptr, false);
2938 if (reqJson.find("PECICommands") != reqJson.end())
2939 {
2940 if (!json_util::readJson(req, res, "PECICommands", peciCommands))
2941 {
2942 return;
2943 }
2944 uint32_t idx = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002945 for (auto const& cmd : peciCommands)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002946 {
2947 if (cmd.size() < 3)
2948 {
2949 std::string s("[");
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002950 for (auto const& val : cmd)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002951 {
2952 if (val != *cmd.begin())
2953 {
2954 s += ",";
2955 }
2956 s += std::to_string(val);
2957 }
2958 s += "]";
2959 messages::actionParameterValueFormatError(
2960 res, s, "PECICommands[" + std::to_string(idx) + "]",
2961 "SendRawPeci");
2962 return;
2963 }
2964 idx++;
2965 }
2966 }
2967 else
2968 {
2969 /* This interface is deprecated */
2970 uint8_t clientAddress = 0;
2971 uint8_t readLength = 0;
2972 std::vector<uint8_t> peciCommand;
2973 if (!json_util::readJson(req, res, "ClientAddress", clientAddress,
2974 "ReadLength", readLength, "PECICommand",
2975 peciCommand))
2976 {
2977 return;
2978 }
2979 peciCommands.push_back({clientAddress, 0, readLength});
2980 peciCommands[0].insert(peciCommands[0].end(), peciCommand.begin(),
2981 peciCommand.end());
2982 }
Ed Tanous1da66f72018-07-27 16:13:37 -07002983 // Callback to return the Raw PECI response
Jason M. Billse1f26342018-07-18 12:12:00 -07002984 auto sendRawPECICallback =
2985 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002986 const std::vector<std::vector<uint8_t>>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002987 if (ec)
2988 {
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002989 BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: "
Jason M. Billse1f26342018-07-18 12:12:00 -07002990 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002991 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002992 return;
2993 }
2994 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
2995 {"PECIResponse", resp}};
2996 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002997 // Call the SendRawPECI command with the provided data
2998 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002999 std::move(sendRawPECICallback), crashdumpObject, crashdumpPath,
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08003000 crashdumpRawPECIInterface, "SendRawPeci", peciCommands);
Ed Tanous1da66f72018-07-27 16:13:37 -07003001 }
3002};
3003
Andrew Geisslercb92c032018-08-17 07:56:14 -07003004/**
3005 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
3006 */
3007class DBusLogServiceActionsClear : public Node
3008{
3009 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003010 DBusLogServiceActionsClear(App& app) :
Andrew Geisslercb92c032018-08-17 07:56:14 -07003011 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
Gunnar Mills7af91512020-04-14 22:16:57 -05003012 "LogService.ClearLog/")
Andrew Geisslercb92c032018-08-17 07:56:14 -07003013 {
3014 entityPrivileges = {
3015 {boost::beast::http::verb::get, {{"Login"}}},
3016 {boost::beast::http::verb::head, {{"Login"}}},
3017 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3018 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3019 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3020 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3021 }
3022
3023 private:
3024 /**
3025 * Function handles POST method request.
3026 * The Clear Log actions does not require any parameter.The action deletes
3027 * all entries found in the Entries collection for this Log Service.
3028 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003029 void doPost(crow::Response& res, const crow::Request& req,
3030 const std::vector<std::string>& params) override
Andrew Geisslercb92c032018-08-17 07:56:14 -07003031 {
3032 BMCWEB_LOG_DEBUG << "Do delete all entries.";
3033
3034 auto asyncResp = std::make_shared<AsyncResp>(res);
3035 // Process response from Logging service.
3036 auto resp_handler = [asyncResp](const boost::system::error_code ec) {
3037 BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3038 if (ec)
3039 {
3040 // TODO Handle for specific error code
3041 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3042 asyncResp->res.result(
3043 boost::beast::http::status::internal_server_error);
3044 return;
3045 }
3046
3047 asyncResp->res.result(boost::beast::http::status::no_content);
3048 };
3049
3050 // Make call to Logging service to request Clear Log
3051 crow::connections::systemBus->async_method_call(
3052 resp_handler, "xyz.openbmc_project.Logging",
3053 "/xyz/openbmc_project/logging",
3054 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3055 }
3056};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003057
3058/****************************************************
3059 * Redfish PostCode interfaces
3060 * using DBUS interface: getPostCodesTS
3061 ******************************************************/
3062class PostCodesLogService : public Node
3063{
3064 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003065 PostCodesLogService(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003066 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
3067 {
3068 entityPrivileges = {
3069 {boost::beast::http::verb::get, {{"Login"}}},
3070 {boost::beast::http::verb::head, {{"Login"}}},
3071 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3072 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3073 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3074 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3075 }
3076
3077 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003078 void doGet(crow::Response& res, const crow::Request& req,
3079 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003080 {
3081 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3082
3083 asyncResp->res.jsonValue = {
3084 {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
3085 {"@odata.type", "#LogService.v1_1_0.LogService"},
3086 {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"},
3087 {"Name", "POST Code Log Service"},
3088 {"Description", "POST Code Log Service"},
3089 {"Id", "BIOS POST Code Log"},
3090 {"OverWritePolicy", "WrapsWhenFull"},
3091 {"Entries",
3092 {{"@odata.id",
3093 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
3094 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
3095 {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
3096 "Actions/LogService.ClearLog"}};
3097 }
3098};
3099
3100class PostCodesClear : public Node
3101{
3102 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003103 PostCodesClear(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003104 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3105 "LogService.ClearLog/")
3106 {
3107 entityPrivileges = {
3108 {boost::beast::http::verb::get, {{"Login"}}},
3109 {boost::beast::http::verb::head, {{"Login"}}},
AppaRao Puli39460282020-04-07 17:03:04 +05303110 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
3111 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
3112 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
3113 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003114 }
3115
3116 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003117 void doPost(crow::Response& res, const crow::Request& req,
3118 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003119 {
3120 BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3121
3122 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3123 // Make call to post-code service to request clear all
3124 crow::connections::systemBus->async_method_call(
3125 [asyncResp](const boost::system::error_code ec) {
3126 if (ec)
3127 {
3128 // TODO Handle for specific error code
3129 BMCWEB_LOG_ERROR
3130 << "doClearPostCodes resp_handler got error " << ec;
3131 asyncResp->res.result(
3132 boost::beast::http::status::internal_server_error);
3133 messages::internalError(asyncResp->res);
3134 return;
3135 }
3136 },
3137 "xyz.openbmc_project.State.Boot.PostCode",
3138 "/xyz/openbmc_project/State/Boot/PostCode",
3139 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3140 }
3141};
3142
3143static void fillPostCodeEntry(
3144 std::shared_ptr<AsyncResp> aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003145 const boost::container::flat_map<uint64_t, uint64_t>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003146 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3147 const uint64_t skip = 0, const uint64_t top = 0)
3148{
3149 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003150 const message_registries::Message* message =
ZhikuiRena3316fc2020-01-29 14:58:08 -08003151 message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003152
3153 uint64_t currentCodeIndex = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003154 nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003155
3156 uint64_t firstCodeTimeUs = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003157 for (const std::pair<uint64_t, uint64_t>& code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003158 {
3159 currentCodeIndex++;
3160 std::string postcodeEntryID =
3161 "B" + std::to_string(bootIndex) + "-" +
3162 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3163
3164 uint64_t usecSinceEpoch = code.first;
3165 uint64_t usTimeOffset = 0;
3166
3167 if (1 == currentCodeIndex)
3168 { // already incremented
3169 firstCodeTimeUs = code.first;
3170 }
3171 else
3172 {
3173 usTimeOffset = code.first - firstCodeTimeUs;
3174 }
3175
3176 // skip if no specific codeIndex is specified and currentCodeIndex does
3177 // not fall between top and skip
3178 if ((codeIndex == 0) &&
3179 (currentCodeIndex <= skip || currentCodeIndex > top))
3180 {
3181 continue;
3182 }
3183
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003184 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003185 // currentIndex
3186 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3187 {
3188 // This is done for simplicity. 1st entry is needed to calculate
3189 // time offset. To improve efficiency, one can get to the entry
3190 // directly (possibly with flatmap's nth method)
3191 continue;
3192 }
3193
3194 // currentCodeIndex is within top and skip or equal to specified code
3195 // index
3196
3197 // Get the Created time from the timestamp
3198 std::string entryTimeStr;
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003199 entryTimeStr = crow::utility::getDateTime(
3200 static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003201
3202 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3203 std::ostringstream hexCode;
3204 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
3205 << code.second;
3206 std::ostringstream timeOffsetStr;
3207 // Set Fixed -Point Notation
3208 timeOffsetStr << std::fixed;
3209 // Set precision to 4 digits
3210 timeOffsetStr << std::setprecision(4);
3211 // Add double to stream
3212 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3213 std::vector<std::string> messageArgs = {
3214 std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3215
3216 // Get MessageArgs template from message registry
3217 std::string msg;
3218 if (message != nullptr)
3219 {
3220 msg = message->message;
3221
3222 // fill in this post code value
3223 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003224 for (const std::string& messageArg : messageArgs)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003225 {
3226 std::string argStr = "%" + std::to_string(++i);
3227 size_t argPos = msg.find(argStr);
3228 if (argPos != std::string::npos)
3229 {
3230 msg.replace(argPos, argStr.length(), messageArg);
3231 }
3232 }
3233 }
3234
Tim Leed4342a92020-04-27 11:47:58 +08003235 // Get Severity template from message registry
3236 std::string severity;
3237 if (message != nullptr)
3238 {
3239 severity = message->severity;
3240 }
3241
ZhikuiRena3316fc2020-01-29 14:58:08 -08003242 // add to AsyncResp
3243 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003244 nlohmann::json& bmcLogEntry = logEntryArray.back();
ZhikuiRena3316fc2020-01-29 14:58:08 -08003245 bmcLogEntry = {
3246 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3247 {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"},
3248 {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3249 "PostCodes/Entries/" +
3250 postcodeEntryID},
3251 {"Name", "POST Code Log Entry"},
3252 {"Id", postcodeEntryID},
3253 {"Message", std::move(msg)},
3254 {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"},
3255 {"MessageArgs", std::move(messageArgs)},
3256 {"EntryType", "Event"},
3257 {"Severity", std::move(severity)},
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003258 {"Created", entryTimeStr}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003259 }
3260}
3261
3262static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp,
3263 const uint16_t bootIndex,
3264 const uint64_t codeIndex)
3265{
3266 crow::connections::systemBus->async_method_call(
3267 [aResp, bootIndex, codeIndex](
3268 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003269 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003270 if (ec)
3271 {
3272 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3273 messages::internalError(aResp->res);
3274 return;
3275 }
3276
3277 // skip the empty postcode boots
3278 if (postcode.empty())
3279 {
3280 return;
3281 }
3282
3283 fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3284
3285 aResp->res.jsonValue["Members@odata.count"] =
3286 aResp->res.jsonValue["Members"].size();
3287 },
3288 "xyz.openbmc_project.State.Boot.PostCode",
3289 "/xyz/openbmc_project/State/Boot/PostCode",
3290 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3291 bootIndex);
3292}
3293
3294static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp,
3295 const uint16_t bootIndex,
3296 const uint16_t bootCount,
3297 const uint64_t entryCount, const uint64_t skip,
3298 const uint64_t top)
3299{
3300 crow::connections::systemBus->async_method_call(
3301 [aResp, bootIndex, bootCount, entryCount, skip,
3302 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003303 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003304 if (ec)
3305 {
3306 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3307 messages::internalError(aResp->res);
3308 return;
3309 }
3310
3311 uint64_t endCount = entryCount;
3312 if (!postcode.empty())
3313 {
3314 endCount = entryCount + postcode.size();
3315
3316 if ((skip < endCount) && ((top + skip) > entryCount))
3317 {
3318 uint64_t thisBootSkip =
3319 std::max(skip, entryCount) - entryCount;
3320 uint64_t thisBootTop =
3321 std::min(top + skip, endCount) - entryCount;
3322
3323 fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3324 thisBootSkip, thisBootTop);
3325 }
3326 aResp->res.jsonValue["Members@odata.count"] = endCount;
3327 }
3328
3329 // continue to previous bootIndex
3330 if (bootIndex < bootCount)
3331 {
3332 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3333 bootCount, endCount, skip, top);
3334 }
3335 else
3336 {
3337 aResp->res.jsonValue["Members@odata.nextLink"] =
3338 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3339 "Entries?$skip=" +
3340 std::to_string(skip + top);
3341 }
3342 },
3343 "xyz.openbmc_project.State.Boot.PostCode",
3344 "/xyz/openbmc_project/State/Boot/PostCode",
3345 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3346 bootIndex);
3347}
3348
3349static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp,
3350 const uint64_t skip, const uint64_t top)
3351{
3352 uint64_t entryCount = 0;
3353 crow::connections::systemBus->async_method_call(
3354 [aResp, entryCount, skip,
3355 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003356 const std::variant<uint16_t>& bootCount) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003357 if (ec)
3358 {
3359 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3360 messages::internalError(aResp->res);
3361 return;
3362 }
3363 auto pVal = std::get_if<uint16_t>(&bootCount);
3364 if (pVal)
3365 {
3366 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3367 }
3368 else
3369 {
3370 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3371 }
3372 },
3373 "xyz.openbmc_project.State.Boot.PostCode",
3374 "/xyz/openbmc_project/State/Boot/PostCode",
3375 "org.freedesktop.DBus.Properties", "Get",
3376 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3377}
3378
3379class PostCodesEntryCollection : public Node
3380{
3381 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003382 PostCodesEntryCollection(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003383 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3384 {
3385 entityPrivileges = {
3386 {boost::beast::http::verb::get, {{"Login"}}},
3387 {boost::beast::http::verb::head, {{"Login"}}},
3388 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3389 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3390 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3391 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3392 }
3393
3394 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003395 void doGet(crow::Response& res, const crow::Request& req,
3396 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003397 {
3398 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3399
3400 asyncResp->res.jsonValue["@odata.type"] =
3401 "#LogEntryCollection.LogEntryCollection";
3402 asyncResp->res.jsonValue["@odata.context"] =
3403 "/redfish/v1/"
3404 "$metadata#LogEntryCollection.LogEntryCollection";
3405 asyncResp->res.jsonValue["@odata.id"] =
3406 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3407 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3408 asyncResp->res.jsonValue["Description"] =
3409 "Collection of POST Code Log Entries";
3410 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3411 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3412
3413 uint64_t skip = 0;
3414 uint64_t top = maxEntriesPerPage; // Show max entries by default
3415 if (!getSkipParam(asyncResp->res, req, skip))
3416 {
3417 return;
3418 }
3419 if (!getTopParam(asyncResp->res, req, top))
3420 {
3421 return;
3422 }
3423 getCurrentBootNumber(asyncResp, skip, top);
3424 }
3425};
3426
3427class PostCodesEntry : public Node
3428{
3429 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003430 PostCodesEntry(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003431 Node(app,
3432 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3433 std::string())
3434 {
3435 entityPrivileges = {
3436 {boost::beast::http::verb::get, {{"Login"}}},
3437 {boost::beast::http::verb::head, {{"Login"}}},
3438 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3439 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3440 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3441 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3442 }
3443
3444 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003445 void doGet(crow::Response& res, const crow::Request& req,
3446 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003447 {
3448 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3449 if (params.size() != 1)
3450 {
3451 messages::internalError(asyncResp->res);
3452 return;
3453 }
3454
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003455 const std::string& targetID = params[0];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003456
3457 size_t bootPos = targetID.find('B');
3458 if (bootPos == std::string::npos)
3459 {
3460 // Requested ID was not found
3461 messages::resourceMissingAtURI(asyncResp->res, targetID);
3462 return;
3463 }
3464 std::string_view bootIndexStr(targetID);
3465 bootIndexStr.remove_prefix(bootPos + 1);
3466 uint16_t bootIndex = 0;
3467 uint64_t codeIndex = 0;
3468 size_t dashPos = bootIndexStr.find('-');
3469
3470 if (dashPos == std::string::npos)
3471 {
3472 return;
3473 }
3474 std::string_view codeIndexStr(bootIndexStr);
3475 bootIndexStr.remove_suffix(dashPos);
3476 codeIndexStr.remove_prefix(dashPos + 1);
3477
3478 bootIndex = static_cast<uint16_t>(
Ed Tanous23a21a12020-07-25 04:45:05 +00003479 strtoul(std::string(bootIndexStr).c_str(), nullptr, 0));
3480 codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003481 if (bootIndex == 0 || codeIndex == 0)
3482 {
3483 BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3484 << params[0];
3485 }
3486
3487 asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
3488 asyncResp->res.jsonValue["@odata.context"] =
3489 "/redfish/v1/$metadata#LogEntry.LogEntry";
3490 asyncResp->res.jsonValue["@odata.id"] =
3491 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3492 "Entries";
3493 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3494 asyncResp->res.jsonValue["Description"] =
3495 "Collection of POST Code Log Entries";
3496 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3497 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3498
3499 getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3500 }
3501};
3502
Ed Tanous1da66f72018-07-27 16:13:37 -07003503} // namespace redfish