blob: 6a23e6e6256d2e5628250cbb55d6ed3a367d88cb [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(
Ed Tanouscb13a392020-07-25 19:02:03 +0000733 [dumpId, dumpPath, dumpType, asyncResp](
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500734 boost::system::error_code err, sdbusplus::message::message& m,
735 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000736 if (err)
737 {
738 messages::internalError(asyncResp->res);
739 return false;
740 }
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500741 std::vector<std::pair<
742 std::string,
743 std::vector<std::pair<std::string, std::variant<std::string>>>>>
744 interfacesList;
745
746 sdbusplus::message::object_path objPath;
747
748 m.read(objPath, interfacesList);
749
750 for (auto& interface : interfacesList)
751 {
752 if (interface.first ==
753 ("xyz.openbmc_project.Dump.Entry." + dumpType))
754 {
755 nlohmann::json retMessage = messages::success();
756 taskData->messages.emplace_back(retMessage);
757
758 std::string headerLoc =
759 "Location: " + dumpPath + std::to_string(dumpId);
760 taskData->payload->httpHeaders.emplace_back(
761 std::move(headerLoc));
762
763 taskData->state = "Completed";
764 return task::completed;
765 }
766 }
767 return !task::completed;
768 },
769 "type='signal',interface='org.freedesktop.DBus."
770 "ObjectManager',"
771 "member='InterfacesAdded', "
772 "path='/xyz/openbmc_project/dump'");
773
774 task->startTimer(std::chrono::minutes(3));
775 task->populateResp(asyncResp->res);
776 task->payload.emplace(req);
777}
778
779inline void createDump(crow::Response& res, const crow::Request& req,
780 const std::string& dumpType)
781{
782 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
783
784 std::string dumpPath;
785 if (dumpType == "BMC")
786 {
787 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
788 }
789 else if (dumpType == "System")
790 {
791 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
792 }
793 else
794 {
795 BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
796 messages::internalError(asyncResp->res);
797 return;
798 }
799
800 std::optional<std::string> diagnosticDataType;
801 std::optional<std::string> oemDiagnosticDataType;
802
803 if (!redfish::json_util::readJson(
804 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
805 "OEMDiagnosticDataType", oemDiagnosticDataType))
806 {
807 return;
808 }
809
810 if (dumpType == "System")
811 {
812 if (!oemDiagnosticDataType || !diagnosticDataType)
813 {
814 BMCWEB_LOG_ERROR << "CreateDump action parameter "
815 "'DiagnosticDataType'/"
816 "'OEMDiagnosticDataType' value not found!";
817 messages::actionParameterMissing(
818 asyncResp->res, "CollectDiagnosticData",
819 "DiagnosticDataType & OEMDiagnosticDataType");
820 return;
821 }
822 else if ((*oemDiagnosticDataType != "System") ||
823 (*diagnosticDataType != "OEM"))
824 {
825 BMCWEB_LOG_ERROR << "Wrong parameter values passed";
826 messages::invalidObject(asyncResp->res,
827 "System Dump creation parameters");
828 return;
829 }
830 }
831 else if (dumpType == "BMC")
832 {
833 if (!diagnosticDataType)
834 {
835 BMCWEB_LOG_ERROR << "CreateDump action parameter "
836 "'DiagnosticDataType' not found!";
837 messages::actionParameterMissing(
838 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
839 return;
840 }
841 else if (*diagnosticDataType != "Manager")
842 {
843 BMCWEB_LOG_ERROR
844 << "Wrong parameter value passed for 'DiagnosticDataType'";
845 messages::invalidObject(asyncResp->res,
846 "BMC Dump creation parameters");
847 return;
848 }
849 }
850
851 crow::connections::systemBus->async_method_call(
852 [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
853 const uint32_t& dumpId) {
854 if (ec)
855 {
856 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
857 messages::internalError(asyncResp->res);
858 return;
859 }
860 BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
861
862 createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
863 },
864 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
865 "xyz.openbmc_project.Dump.Create", "CreateDump");
866}
867
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500868inline void clearDump(crow::Response& res, const std::string& dumpInterface)
869{
870 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
871 crow::connections::systemBus->async_method_call(
872 [asyncResp](const boost::system::error_code ec,
873 const std::vector<std::string>& subTreePaths) {
874 if (ec)
875 {
876 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
877 messages::internalError(asyncResp->res);
878 return;
879 }
880
881 for (const std::string& path : subTreePaths)
882 {
883 std::size_t pos = path.rfind("/");
884 if (pos != std::string::npos)
885 {
886 std::string logID = path.substr(pos + 1);
887 deleteDumpEntry(asyncResp->res, logID);
888 }
889 }
890 },
891 "xyz.openbmc_project.ObjectMapper",
892 "/xyz/openbmc_project/object_mapper",
893 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
894 "/xyz/openbmc_project/dump", 0,
895 std::array<std::string, 1>{dumpInterface});
896}
897
Johnathan Mantey043a0532020-03-10 17:15:28 -0700898static void ParseCrashdumpParameters(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500899 const std::vector<std::pair<std::string, VariantType>>& params,
900 std::string& filename, std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -0700901{
902 for (auto property : params)
903 {
904 if (property.first == "Timestamp")
905 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500906 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500907 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700908 if (value != nullptr)
909 {
910 timestamp = *value;
911 }
912 }
913 else if (property.first == "Filename")
914 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500915 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500916 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700917 if (value != nullptr)
918 {
919 filename = *value;
920 }
921 }
922 else if (property.first == "Log")
923 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500924 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500925 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700926 if (value != nullptr)
927 {
928 logfile = *value;
929 }
930 }
931 }
932}
933
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500934constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800935class SystemLogServiceCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -0700936{
937 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700938 SystemLogServiceCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800939 Node(app, "/redfish/v1/Systems/system/LogServices/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800940 {
941 entityPrivileges = {
942 {boost::beast::http::verb::get, {{"Login"}}},
943 {boost::beast::http::verb::head, {{"Login"}}},
944 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
945 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
946 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
947 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
948 }
949
950 private:
951 /**
952 * Functions triggers appropriate requests on DBus
953 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000954 void doGet(crow::Response& res, const crow::Request&,
955 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800956 {
957 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800958 // Collections don't include the static data added by SubRoute because
959 // it has a duplicate entry for members
960 asyncResp->res.jsonValue["@odata.type"] =
961 "#LogServiceCollection.LogServiceCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800962 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800963 "/redfish/v1/Systems/system/LogServices";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800964 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
965 asyncResp->res.jsonValue["Description"] =
966 "Collection of LogServices for this Computer System";
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500967 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800968 logServiceArray = nlohmann::json::array();
Ed Tanous029573d2019-02-01 10:57:49 -0800969 logServiceArray.push_back(
970 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500971#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
raviteja-bc9bb6862020-02-03 11:53:32 -0600972 logServiceArray.push_back(
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500973 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
raviteja-bc9bb6862020-02-03 11:53:32 -0600974#endif
975
Jason M. Billsd53dd412019-02-12 17:16:22 -0800976#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
977 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -0500978 {{"@odata.id",
979 "/redfish/v1/Systems/system/LogServices/Crashdump"}});
Jason M. Billsd53dd412019-02-12 17:16:22 -0800980#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800981 asyncResp->res.jsonValue["Members@odata.count"] =
982 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800983
984 crow::connections::systemBus->async_method_call(
985 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500986 const std::vector<std::string>& subtreePath) {
ZhikuiRena3316fc2020-01-29 14:58:08 -0800987 if (ec)
988 {
989 BMCWEB_LOG_ERROR << ec;
990 return;
991 }
992
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500993 for (auto& pathStr : subtreePath)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800994 {
995 if (pathStr.find("PostCode") != std::string::npos)
996 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000997 nlohmann::json& logServiceArrayLocal =
ZhikuiRena3316fc2020-01-29 14:58:08 -0800998 asyncResp->res.jsonValue["Members"];
Ed Tanous23a21a12020-07-25 04:45:05 +0000999 logServiceArrayLocal.push_back(
ZhikuiRena3316fc2020-01-29 14:58:08 -08001000 {{"@odata.id", "/redfish/v1/Systems/system/"
1001 "LogServices/PostCodes"}});
1002 asyncResp->res.jsonValue["Members@odata.count"] =
Ed Tanous23a21a12020-07-25 04:45:05 +00001003 logServiceArrayLocal.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -08001004 return;
1005 }
1006 }
1007 },
1008 "xyz.openbmc_project.ObjectMapper",
1009 "/xyz/openbmc_project/object_mapper",
1010 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001011 std::array<const char*, 1>{postCodeIface});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001012 }
1013};
1014
1015class EventLogService : public Node
1016{
1017 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001018 EventLogService(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001019 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001020 {
1021 entityPrivileges = {
1022 {boost::beast::http::verb::get, {{"Login"}}},
1023 {boost::beast::http::verb::head, {{"Login"}}},
1024 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1025 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1026 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1027 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1028 }
1029
1030 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001031 void doGet(crow::Response& res, const crow::Request&,
1032 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001033 {
1034 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1035
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001036 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001037 "/redfish/v1/Systems/system/LogServices/EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001038 asyncResp->res.jsonValue["@odata.type"] =
1039 "#LogService.v1_1_0.LogService";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001040 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1041 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
Gunnar Mills73ec8302020-04-14 16:02:42 -05001042 asyncResp->res.jsonValue["Id"] = "EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001043 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1044 asyncResp->res.jsonValue["Entries"] = {
1045 {"@odata.id",
Ed Tanous029573d2019-02-01 10:57:49 -08001046 "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
Gunnar Millse7d6c8b2019-07-03 11:30:01 -05001047 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1048
1049 {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1050 "Actions/LogService.ClearLog"}};
Jason M. Bills489640c2019-05-17 09:56:36 -07001051 }
1052};
1053
Tim Lee1f56a3a2019-10-09 10:17:57 +08001054class JournalEventLogClear : public Node
Jason M. Bills489640c2019-05-17 09:56:36 -07001055{
1056 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001057 JournalEventLogClear(App& app) :
Jason M. Bills489640c2019-05-17 09:56:36 -07001058 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1059 "LogService.ClearLog/")
1060 {
1061 entityPrivileges = {
1062 {boost::beast::http::verb::get, {{"Login"}}},
1063 {boost::beast::http::verb::head, {{"Login"}}},
1064 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1065 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1066 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1067 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1068 }
1069
1070 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001071 void doPost(crow::Response& res, const crow::Request&,
1072 const std::vector<std::string>&) override
Jason M. Bills489640c2019-05-17 09:56:36 -07001073 {
1074 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1075
1076 // Clear the EventLog by deleting the log files
1077 std::vector<std::filesystem::path> redfishLogFiles;
1078 if (getRedfishLogFiles(redfishLogFiles))
1079 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001080 for (const std::filesystem::path& file : redfishLogFiles)
Jason M. Bills489640c2019-05-17 09:56:36 -07001081 {
1082 std::error_code ec;
1083 std::filesystem::remove(file, ec);
1084 }
1085 }
1086
1087 // Reload rsyslog so it knows to start new log files
1088 crow::connections::systemBus->async_method_call(
1089 [asyncResp](const boost::system::error_code ec) {
1090 if (ec)
1091 {
1092 BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1093 messages::internalError(asyncResp->res);
1094 return;
1095 }
1096
1097 messages::success(asyncResp->res);
1098 },
1099 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1100 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1101 "replace");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001102 }
1103};
1104
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001105static int fillEventLogEntryJson(const std::string& logEntryID,
Jason M. Bills95820182019-04-22 16:25:34 -07001106 const std::string logEntry,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001107 nlohmann::json& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001108{
Jason M. Bills95820182019-04-22 16:25:34 -07001109 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001110 // First get the Timestamp
1111 size_t space = logEntry.find_first_of(" ");
1112 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001113 {
1114 return 1;
1115 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001116 std::string timestamp = logEntry.substr(0, space);
1117 // Then get the log contents
1118 size_t entryStart = logEntry.find_first_not_of(" ", space);
1119 if (entryStart == std::string::npos)
1120 {
1121 return 1;
1122 }
1123 std::string_view entry(logEntry);
1124 entry.remove_prefix(entryStart);
1125 // Use split to separate the entry into its fields
1126 std::vector<std::string> logEntryFields;
1127 boost::split(logEntryFields, entry, boost::is_any_of(","),
1128 boost::token_compress_on);
1129 // We need at least a MessageId to be valid
1130 if (logEntryFields.size() < 1)
1131 {
1132 return 1;
1133 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001134 std::string& messageID = logEntryFields[0];
Jason M. Bills95820182019-04-22 16:25:34 -07001135
Jason M. Bills4851d452019-03-28 11:27:48 -07001136 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001137 const message_registries::Message* message =
Jason M. Bills4851d452019-03-28 11:27:48 -07001138 message_registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001139
Jason M. Bills4851d452019-03-28 11:27:48 -07001140 std::string msg;
1141 std::string severity;
1142 if (message != nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001143 {
Jason M. Bills4851d452019-03-28 11:27:48 -07001144 msg = message->message;
1145 severity = message->severity;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001146 }
1147
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001148 // Get the MessageArgs from the log if there are any
1149 boost::beast::span<std::string> messageArgs;
1150 if (logEntryFields.size() > 1)
Jason M. Bills4851d452019-03-28 11:27:48 -07001151 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001152 std::string& messageArgsStart = logEntryFields[1];
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001153 // If the first string is empty, assume there are no MessageArgs
1154 std::size_t messageArgsSize = 0;
1155 if (!messageArgsStart.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001156 {
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001157 messageArgsSize = logEntryFields.size() - 1;
1158 }
1159
Ed Tanous23a21a12020-07-25 04:45:05 +00001160 messageArgs = {&messageArgsStart, messageArgsSize};
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001161
1162 // Fill the MessageArgs into the Message
1163 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001164 for (const std::string& messageArg : messageArgs)
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001165 {
1166 std::string argStr = "%" + std::to_string(++i);
1167 size_t argPos = msg.find(argStr);
1168 if (argPos != std::string::npos)
1169 {
1170 msg.replace(argPos, argStr.length(), messageArg);
1171 }
Jason M. Bills4851d452019-03-28 11:27:48 -07001172 }
1173 }
1174
Jason M. Bills95820182019-04-22 16:25:34 -07001175 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1176 // format which matches the Redfish format except for the fractional seconds
1177 // between the '.' and the '+', so just remove them.
1178 std::size_t dot = timestamp.find_first_of(".");
1179 std::size_t plus = timestamp.find_first_of("+");
1180 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001181 {
Jason M. Bills95820182019-04-22 16:25:34 -07001182 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001183 }
1184
1185 // Fill in the log entry with the gathered data
Jason M. Bills95820182019-04-22 16:25:34 -07001186 logEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001187 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Ed Tanous029573d2019-02-01 10:57:49 -08001188 {"@odata.id",
Jason M. Bills897967d2019-07-29 17:05:30 -07001189 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
Jason M. Bills95820182019-04-22 16:25:34 -07001190 logEntryID},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001191 {"Name", "System Event Log Entry"},
Jason M. Bills95820182019-04-22 16:25:34 -07001192 {"Id", logEntryID},
1193 {"Message", std::move(msg)},
1194 {"MessageId", std::move(messageID)},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001195 {"MessageArgs", std::move(messageArgs)},
1196 {"EntryType", "Event"},
Jason M. Bills95820182019-04-22 16:25:34 -07001197 {"Severity", std::move(severity)},
1198 {"Created", std::move(timestamp)}};
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001199 return 0;
1200}
1201
Anthony Wilson27062602019-04-22 02:10:09 -05001202class JournalEventLogEntryCollection : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001203{
1204 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001205 JournalEventLogEntryCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001206 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001207 {
1208 entityPrivileges = {
1209 {boost::beast::http::verb::get, {{"Login"}}},
1210 {boost::beast::http::verb::head, {{"Login"}}},
1211 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1212 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1213 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1214 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1215 }
1216
1217 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001218 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001219 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001220 {
1221 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous271584a2019-07-09 16:24:22 -07001222 uint64_t skip = 0;
1223 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001224 if (!getSkipParam(asyncResp->res, req, skip))
1225 {
1226 return;
1227 }
1228 if (!getTopParam(asyncResp->res, req, top))
1229 {
1230 return;
1231 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001232 // Collections don't include the static data added by SubRoute because
1233 // it has a duplicate entry for members
1234 asyncResp->res.jsonValue["@odata.type"] =
1235 "#LogEntryCollection.LogEntryCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001236 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001237 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001238 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1239 asyncResp->res.jsonValue["Description"] =
1240 "Collection of System Event Log Entries";
Andrew Geisslercb92c032018-08-17 07:56:14 -07001241
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001242 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001243 logEntryArray = nlohmann::json::array();
Jason M. Bills95820182019-04-22 16:25:34 -07001244 // Go through the log files and create a unique ID for each entry
1245 std::vector<std::filesystem::path> redfishLogFiles;
1246 getRedfishLogFiles(redfishLogFiles);
Ed Tanousb01bf292019-03-25 19:25:26 +00001247 uint64_t entryCount = 0;
Jason M. Billscd225da2019-05-08 15:31:57 -07001248 std::string logEntry;
Jason M. Bills95820182019-04-22 16:25:34 -07001249
1250 // Oldest logs are in the last file, so start there and loop backwards
Jason M. Billscd225da2019-05-08 15:31:57 -07001251 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1252 it++)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001253 {
Jason M. Billscd225da2019-05-08 15:31:57 -07001254 std::ifstream logStream(*it);
Jason M. Bills95820182019-04-22 16:25:34 -07001255 if (!logStream.is_open())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001256 {
1257 continue;
1258 }
1259
Jason M. Billse85d6b12019-07-29 17:01:15 -07001260 // Reset the unique ID on the first entry
1261 bool firstEntry = true;
Jason M. Bills95820182019-04-22 16:25:34 -07001262 while (std::getline(logStream, logEntry))
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001263 {
Jason M. Bills95820182019-04-22 16:25:34 -07001264 entryCount++;
1265 // Handle paging using skip (number of entries to skip from the
1266 // start) and top (number of entries to display)
1267 if (entryCount <= skip || entryCount > skip + top)
1268 {
1269 continue;
1270 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001271
Jason M. Bills95820182019-04-22 16:25:34 -07001272 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001273 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Jason M. Bills95820182019-04-22 16:25:34 -07001274 {
1275 continue;
1276 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001277
Jason M. Billse85d6b12019-07-29 17:01:15 -07001278 if (firstEntry)
1279 {
1280 firstEntry = false;
1281 }
1282
Jason M. Bills95820182019-04-22 16:25:34 -07001283 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001284 nlohmann::json& bmcLogEntry = logEntryArray.back();
Jason M. Bills95820182019-04-22 16:25:34 -07001285 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
1286 {
1287 messages::internalError(asyncResp->res);
1288 return;
1289 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001290 }
1291 }
1292 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1293 if (skip + top < entryCount)
1294 {
1295 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Bills95820182019-04-22 16:25:34 -07001296 "/redfish/v1/Systems/system/LogServices/EventLog/"
1297 "Entries?$skip=" +
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001298 std::to_string(skip + top);
1299 }
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001300 }
1301};
1302
Jason M. Bills897967d2019-07-29 17:05:30 -07001303class JournalEventLogEntry : public Node
1304{
1305 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001306 JournalEventLogEntry(App& app) :
Jason M. Bills897967d2019-07-29 17:05:30 -07001307 Node(app,
1308 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1309 std::string())
1310 {
1311 entityPrivileges = {
1312 {boost::beast::http::verb::get, {{"Login"}}},
1313 {boost::beast::http::verb::head, {{"Login"}}},
1314 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1315 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1316 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1317 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1318 }
1319
1320 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001321 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001322 const std::vector<std::string>& params) override
Jason M. Bills897967d2019-07-29 17:05:30 -07001323 {
1324 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1325 if (params.size() != 1)
1326 {
1327 messages::internalError(asyncResp->res);
1328 return;
1329 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001330 const std::string& targetID = params[0];
Jason M. Bills897967d2019-07-29 17:05:30 -07001331
1332 // Go through the log files and check the unique ID for each entry to
1333 // find the target entry
1334 std::vector<std::filesystem::path> redfishLogFiles;
1335 getRedfishLogFiles(redfishLogFiles);
1336 std::string logEntry;
1337
1338 // Oldest logs are in the last file, so start there and loop backwards
1339 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1340 it++)
1341 {
1342 std::ifstream logStream(*it);
1343 if (!logStream.is_open())
1344 {
1345 continue;
1346 }
1347
1348 // Reset the unique ID on the first entry
1349 bool firstEntry = true;
1350 while (std::getline(logStream, logEntry))
1351 {
1352 std::string idStr;
1353 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1354 {
1355 continue;
1356 }
1357
1358 if (firstEntry)
1359 {
1360 firstEntry = false;
1361 }
1362
1363 if (idStr == targetID)
1364 {
1365 if (fillEventLogEntryJson(idStr, logEntry,
1366 asyncResp->res.jsonValue) != 0)
1367 {
1368 messages::internalError(asyncResp->res);
1369 return;
1370 }
1371 return;
1372 }
1373 }
1374 }
1375 // Requested ID was not found
1376 messages::resourceMissingAtURI(asyncResp->res, targetID);
1377 }
1378};
1379
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001380class DBusEventLogEntryCollection : public Node
1381{
1382 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001383 DBusEventLogEntryCollection(App& app) :
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001384 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1385 {
1386 entityPrivileges = {
1387 {boost::beast::http::verb::get, {{"Login"}}},
1388 {boost::beast::http::verb::head, {{"Login"}}},
1389 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1390 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1391 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1392 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1393 }
1394
1395 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001396 void doGet(crow::Response& res, const crow::Request&,
1397 const std::vector<std::string>&) override
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001398 {
1399 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1400
1401 // Collections don't include the static data added by SubRoute because
1402 // it has a duplicate entry for members
1403 asyncResp->res.jsonValue["@odata.type"] =
1404 "#LogEntryCollection.LogEntryCollection";
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001405 asyncResp->res.jsonValue["@odata.id"] =
1406 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1407 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1408 asyncResp->res.jsonValue["Description"] =
1409 "Collection of System Event Log Entries";
1410
Andrew Geisslercb92c032018-08-17 07:56:14 -07001411 // DBus implementation of EventLog/Entries
1412 // Make call to Logging Service to find all log entry objects
1413 crow::connections::systemBus->async_method_call(
1414 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001415 GetManagedObjectsType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001416 if (ec)
1417 {
1418 // TODO Handle for specific error code
1419 BMCWEB_LOG_ERROR
1420 << "getLogEntriesIfaceData resp_handler got error "
1421 << ec;
1422 messages::internalError(asyncResp->res);
1423 return;
1424 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001425 nlohmann::json& entriesArray =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001426 asyncResp->res.jsonValue["Members"];
1427 entriesArray = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001428 for (auto& objectPath : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001429 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001430 for (auto& interfaceMap : objectPath.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001431 {
1432 if (interfaceMap.first !=
1433 "xyz.openbmc_project.Logging.Entry")
1434 {
1435 BMCWEB_LOG_DEBUG << "Bailing early on "
1436 << interfaceMap.first;
1437 continue;
1438 }
1439 entriesArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001440 nlohmann::json& thisEntry = entriesArray.back();
1441 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001442 std::time_t timestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001443 std::string* severity = nullptr;
1444 std::string* message = nullptr;
1445 for (auto& propertyMap : interfaceMap.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001446 {
1447 if (propertyMap.first == "Id")
1448 {
Patrick Williams8d78b7a2020-05-13 11:24:20 -05001449 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001450 if (id == nullptr)
1451 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001452 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001453 }
1454 }
1455 else if (propertyMap.first == "Timestamp")
1456 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001457 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001458 std::get_if<uint64_t>(&propertyMap.second);
1459 if (millisTimeStamp == nullptr)
1460 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001461 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001462 continue;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001463 }
1464 // Retrieve Created property with format:
1465 // yyyy-mm-ddThh:mm:ss
1466 std::chrono::milliseconds chronoTimeStamp(
1467 *millisTimeStamp);
Ed Tanous271584a2019-07-09 16:24:22 -07001468 timestamp = std::chrono::duration_cast<
1469 std::chrono::duration<int>>(
1470 chronoTimeStamp)
1471 .count();
Andrew Geisslercb92c032018-08-17 07:56:14 -07001472 }
1473 else if (propertyMap.first == "Severity")
1474 {
1475 severity = std::get_if<std::string>(
1476 &propertyMap.second);
1477 if (severity == nullptr)
1478 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001479 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001480 }
1481 }
1482 else if (propertyMap.first == "Message")
1483 {
1484 message = std::get_if<std::string>(
1485 &propertyMap.second);
1486 if (message == nullptr)
1487 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001488 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001489 }
1490 }
1491 }
1492 thisEntry = {
1493 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001494 {"@odata.id",
1495 "/redfish/v1/Systems/system/LogServices/EventLog/"
1496 "Entries/" +
1497 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001498 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001499 {"Id", std::to_string(*id)},
1500 {"Message", *message},
1501 {"EntryType", "Event"},
1502 {"Severity",
1503 translateSeverityDbusToRedfish(*severity)},
1504 {"Created", crow::utility::getDateTime(timestamp)}};
1505 }
1506 }
1507 std::sort(entriesArray.begin(), entriesArray.end(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001508 [](const nlohmann::json& left,
1509 const nlohmann::json& right) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001510 return (left["Id"] <= right["Id"]);
1511 });
1512 asyncResp->res.jsonValue["Members@odata.count"] =
1513 entriesArray.size();
1514 },
1515 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
1516 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001517 }
1518};
1519
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001520class DBusEventLogEntry : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001521{
1522 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001523 DBusEventLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001524 Node(app,
Ed Tanous029573d2019-02-01 10:57:49 -08001525 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1526 std::string())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001527 {
1528 entityPrivileges = {
1529 {boost::beast::http::verb::get, {{"Login"}}},
1530 {boost::beast::http::verb::head, {{"Login"}}},
1531 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1532 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1533 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1534 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1535 }
1536
1537 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001538 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001539 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001540 {
1541 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous029573d2019-02-01 10:57:49 -08001542 if (params.size() != 1)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001543 {
1544 messages::internalError(asyncResp->res);
1545 return;
1546 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001547 const std::string& entryID = params[0];
Andrew Geisslercb92c032018-08-17 07:56:14 -07001548
Andrew Geisslercb92c032018-08-17 07:56:14 -07001549 // DBus implementation of EventLog/Entries
1550 // Make call to Logging Service to find all log entry objects
1551 crow::connections::systemBus->async_method_call(
1552 [asyncResp, entryID](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001553 GetManagedPropertyType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001554 if (ec)
1555 {
1556 BMCWEB_LOG_ERROR
1557 << "EventLogEntry (DBus) resp_handler got error " << ec;
1558 messages::internalError(asyncResp->res);
1559 return;
1560 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001561 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001562 std::time_t timestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001563 std::string* severity = nullptr;
1564 std::string* message = nullptr;
1565 for (auto& propertyMap : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001566 {
1567 if (propertyMap.first == "Id")
1568 {
1569 id = std::get_if<uint32_t>(&propertyMap.second);
1570 if (id == nullptr)
1571 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001572 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001573 }
1574 }
1575 else if (propertyMap.first == "Timestamp")
1576 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001577 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001578 std::get_if<uint64_t>(&propertyMap.second);
1579 if (millisTimeStamp == nullptr)
1580 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001581 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001582 continue;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001583 }
1584 // Retrieve Created property with format:
1585 // yyyy-mm-ddThh:mm:ss
1586 std::chrono::milliseconds chronoTimeStamp(
1587 *millisTimeStamp);
1588 timestamp =
Ed Tanous271584a2019-07-09 16:24:22 -07001589 std::chrono::duration_cast<
1590 std::chrono::duration<int>>(chronoTimeStamp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001591 .count();
1592 }
1593 else if (propertyMap.first == "Severity")
1594 {
1595 severity =
1596 std::get_if<std::string>(&propertyMap.second);
1597 if (severity == nullptr)
1598 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001599 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001600 }
1601 }
1602 else if (propertyMap.first == "Message")
1603 {
1604 message = std::get_if<std::string>(&propertyMap.second);
1605 if (message == nullptr)
1606 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001607 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001608 }
1609 }
1610 }
Ed Tanous271584a2019-07-09 16:24:22 -07001611 if (id == nullptr || message == nullptr || severity == nullptr)
1612 {
1613 return;
1614 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001615 asyncResp->res.jsonValue = {
1616 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001617 {"@odata.id",
1618 "/redfish/v1/Systems/system/LogServices/EventLog/"
1619 "Entries/" +
1620 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001621 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001622 {"Id", std::to_string(*id)},
1623 {"Message", *message},
1624 {"EntryType", "Event"},
1625 {"Severity", translateSeverityDbusToRedfish(*severity)},
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001626 {"Created", crow::utility::getDateTime(timestamp)}};
Andrew Geisslercb92c032018-08-17 07:56:14 -07001627 },
1628 "xyz.openbmc_project.Logging",
1629 "/xyz/openbmc_project/logging/entry/" + entryID,
1630 "org.freedesktop.DBus.Properties", "GetAll",
1631 "xyz.openbmc_project.Logging.Entry");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001632 }
Chicago Duan336e96c2019-07-15 14:22:08 +08001633
Ed Tanouscb13a392020-07-25 19:02:03 +00001634 void doDelete(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001635 const std::vector<std::string>& params) override
Chicago Duan336e96c2019-07-15 14:22:08 +08001636 {
1637
1638 BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1639
1640 auto asyncResp = std::make_shared<AsyncResp>(res);
1641
1642 if (params.size() != 1)
1643 {
1644 messages::internalError(asyncResp->res);
1645 return;
1646 }
1647 std::string entryID = params[0];
1648
1649 dbus::utility::escapePathForDbus(entryID);
1650
1651 // Process response from Logging service.
1652 auto respHandler = [asyncResp](const boost::system::error_code ec) {
1653 BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1654 if (ec)
1655 {
1656 // TODO Handle for specific error code
1657 BMCWEB_LOG_ERROR
1658 << "EventLogEntry (DBus) doDelete respHandler got error "
1659 << ec;
1660 asyncResp->res.result(
1661 boost::beast::http::status::internal_server_error);
1662 return;
1663 }
1664
1665 asyncResp->res.result(boost::beast::http::status::ok);
1666 };
1667
1668 // Make call to Logging service to request Delete Log
1669 crow::connections::systemBus->async_method_call(
1670 respHandler, "xyz.openbmc_project.Logging",
1671 "/xyz/openbmc_project/logging/entry/" + entryID,
1672 "xyz.openbmc_project.Object.Delete", "Delete");
1673 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001674};
1675
1676class BMCLogServiceCollection : public Node
1677{
1678 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001679 BMCLogServiceCollection(App& app) :
Ed Tanous4ed77cd2018-10-15 08:08:07 -07001680 Node(app, "/redfish/v1/Managers/bmc/LogServices/")
Ed Tanous1da66f72018-07-27 16:13:37 -07001681 {
Ed Tanous1da66f72018-07-27 16:13:37 -07001682 entityPrivileges = {
Jason M. Billse1f26342018-07-18 12:12:00 -07001683 {boost::beast::http::verb::get, {{"Login"}}},
1684 {boost::beast::http::verb::head, {{"Login"}}},
1685 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1686 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1687 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1688 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07001689 }
1690
1691 private:
1692 /**
1693 * Functions triggers appropriate requests on DBus
1694 */
Ed Tanouscb13a392020-07-25 19:02:03 +00001695 void doGet(crow::Response& res, const crow::Request&,
1696 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07001697 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001698 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07001699 // Collections don't include the static data added by SubRoute because
1700 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07001701 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001702 "#LogServiceCollection.LogServiceCollection";
Jason M. Billse1f26342018-07-18 12:12:00 -07001703 asyncResp->res.jsonValue["@odata.id"] =
1704 "/redfish/v1/Managers/bmc/LogServices";
1705 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1706 asyncResp->res.jsonValue["Description"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001707 "Collection of LogServices for this Manager";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001708 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001709 logServiceArray = nlohmann::json::array();
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001710#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
1711 logServiceArray.push_back(
1712 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}});
1713#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001714#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
1715 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001716 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001717#endif
Jason M. Billse1f26342018-07-18 12:12:00 -07001718 asyncResp->res.jsonValue["Members@odata.count"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001719 logServiceArray.size();
Ed Tanous1da66f72018-07-27 16:13:37 -07001720 }
1721};
1722
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001723class BMCJournalLogService : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07001724{
1725 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001726 BMCJournalLogService(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001727 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001728 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001729 entityPrivileges = {
1730 {boost::beast::http::verb::get, {{"Login"}}},
1731 {boost::beast::http::verb::head, {{"Login"}}},
1732 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1733 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1734 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1735 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1736 }
1737
1738 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001739 void doGet(crow::Response& res, const crow::Request&,
1740 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001741 {
1742 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001743 asyncResp->res.jsonValue["@odata.type"] =
1744 "#LogService.v1_1_0.LogService";
Ed Tanous0f74e642018-11-12 15:17:05 -08001745 asyncResp->res.jsonValue["@odata.id"] =
1746 "/redfish/v1/Managers/bmc/LogServices/Journal";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001747 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1748 asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1749 asyncResp->res.jsonValue["Id"] = "BMC Journal";
Jason M. Billse1f26342018-07-18 12:12:00 -07001750 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
Jason M. Billscd50aa42019-02-12 17:09:02 -08001751 asyncResp->res.jsonValue["Entries"] = {
1752 {"@odata.id",
Ed Tanous086be232019-05-23 11:47:09 -07001753 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07001754 }
1755};
1756
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001757static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1758 sd_journal* journal,
1759 nlohmann::json& bmcJournalLogEntryJson)
Jason M. Billse1f26342018-07-18 12:12:00 -07001760{
1761 // Get the Log Entry contents
1762 int ret = 0;
Jason M. Billse1f26342018-07-18 12:12:00 -07001763
Ed Tanous39e77502019-03-04 17:35:53 -08001764 std::string_view msg;
Jason M. Bills16428a12018-11-02 12:42:29 -07001765 ret = getJournalMetadata(journal, "MESSAGE", msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001766 if (ret < 0)
1767 {
1768 BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1769 return 1;
1770 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001771
1772 // Get the severity from the PRIORITY field
Ed Tanous271584a2019-07-09 16:24:22 -07001773 long int severity = 8; // Default to an invalid priority
Jason M. Bills16428a12018-11-02 12:42:29 -07001774 ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
Jason M. Billse1f26342018-07-18 12:12:00 -07001775 if (ret < 0)
1776 {
1777 BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
Jason M. Billse1f26342018-07-18 12:12:00 -07001778 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001779
1780 // Get the Created time from the timestamp
Jason M. Bills16428a12018-11-02 12:42:29 -07001781 std::string entryTimeStr;
1782 if (!getEntryTimestamp(journal, entryTimeStr))
Jason M. Billse1f26342018-07-18 12:12:00 -07001783 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001784 return 1;
Jason M. Billse1f26342018-07-18 12:12:00 -07001785 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001786
1787 // Fill in the log entry with the gathered data
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001788 bmcJournalLogEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001789 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001790 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
1791 bmcJournalLogEntryID},
Jason M. Billse1f26342018-07-18 12:12:00 -07001792 {"Name", "BMC Journal Entry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001793 {"Id", bmcJournalLogEntryID},
Jason M. Bills16428a12018-11-02 12:42:29 -07001794 {"Message", msg},
Jason M. Billse1f26342018-07-18 12:12:00 -07001795 {"EntryType", "Oem"},
1796 {"Severity",
Jason M. Billsb6a61a52019-08-01 14:26:15 -07001797 severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"},
Ed Tanous086be232019-05-23 11:47:09 -07001798 {"OemRecordFormat", "BMC Journal Entry"},
Jason M. Billse1f26342018-07-18 12:12:00 -07001799 {"Created", std::move(entryTimeStr)}};
1800 return 0;
1801}
1802
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001803class BMCJournalLogEntryCollection : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001804{
1805 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001806 BMCJournalLogEntryCollection(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001807 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001808 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001809 entityPrivileges = {
1810 {boost::beast::http::verb::get, {{"Login"}}},
1811 {boost::beast::http::verb::head, {{"Login"}}},
1812 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1813 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1814 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1815 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1816 }
1817
1818 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001819 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001820 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001821 {
1822 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001823 static constexpr const long maxEntriesPerPage = 1000;
Ed Tanous271584a2019-07-09 16:24:22 -07001824 uint64_t skip = 0;
1825 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Bills16428a12018-11-02 12:42:29 -07001826 if (!getSkipParam(asyncResp->res, req, skip))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001827 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001828 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001829 }
Jason M. Bills16428a12018-11-02 12:42:29 -07001830 if (!getTopParam(asyncResp->res, req, top))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001831 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001832 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001833 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001834 // Collections don't include the static data added by SubRoute because
1835 // it has a duplicate entry for members
1836 asyncResp->res.jsonValue["@odata.type"] =
1837 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08001838 asyncResp->res.jsonValue["@odata.id"] =
1839 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001840 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001841 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001842 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
1843 asyncResp->res.jsonValue["Description"] =
1844 "Collection of BMC Journal Entries";
Ed Tanous0f74e642018-11-12 15:17:05 -08001845 asyncResp->res.jsonValue["@odata.id"] =
1846 "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001847 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07001848 logEntryArray = nlohmann::json::array();
1849
1850 // Go through the journal and use the timestamp to create a unique ID
1851 // for each entry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001852 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001853 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1854 if (ret < 0)
1855 {
1856 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001857 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001858 return;
1859 }
1860 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1861 journalTmp, sd_journal_close);
1862 journalTmp = nullptr;
Ed Tanousb01bf292019-03-25 19:25:26 +00001863 uint64_t entryCount = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001864 // Reset the unique ID on the first entry
1865 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001866 SD_JOURNAL_FOREACH(journal.get())
1867 {
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001868 entryCount++;
1869 // Handle paging using skip (number of entries to skip from the
1870 // start) and top (number of entries to display)
1871 if (entryCount <= skip || entryCount > skip + top)
1872 {
1873 continue;
1874 }
1875
Jason M. Bills16428a12018-11-02 12:42:29 -07001876 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001877 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
Jason M. Billse1f26342018-07-18 12:12:00 -07001878 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001879 continue;
1880 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001881
Jason M. Billse85d6b12019-07-29 17:01:15 -07001882 if (firstEntry)
1883 {
1884 firstEntry = false;
1885 }
1886
Jason M. Billse1f26342018-07-18 12:12:00 -07001887 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001888 nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001889 if (fillBMCJournalLogEntryJson(idStr, journal.get(),
1890 bmcJournalLogEntry) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001891 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001892 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001893 return;
1894 }
1895 }
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001896 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1897 if (skip + top < entryCount)
1898 {
1899 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001900 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001901 std::to_string(skip + top);
1902 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001903 }
1904};
1905
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001906class BMCJournalLogEntry : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001907{
1908 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001909 BMCJournalLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001910 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
Jason M. Billse1f26342018-07-18 12:12:00 -07001911 std::string())
1912 {
1913 entityPrivileges = {
1914 {boost::beast::http::verb::get, {{"Login"}}},
1915 {boost::beast::http::verb::head, {{"Login"}}},
1916 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1917 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1918 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1919 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1920 }
1921
1922 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001923 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001924 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001925 {
1926 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1927 if (params.size() != 1)
1928 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001929 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001930 return;
1931 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001932 const std::string& entryID = params[0];
Jason M. Billse1f26342018-07-18 12:12:00 -07001933 // Convert the unique ID back to a timestamp to find the entry
Jason M. Billse1f26342018-07-18 12:12:00 -07001934 uint64_t ts = 0;
Ed Tanous271584a2019-07-09 16:24:22 -07001935 uint64_t index = 0;
Jason M. Bills16428a12018-11-02 12:42:29 -07001936 if (!getTimestampFromID(asyncResp->res, entryID, ts, index))
Jason M. Billse1f26342018-07-18 12:12:00 -07001937 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001938 return;
Jason M. Billse1f26342018-07-18 12:12:00 -07001939 }
1940
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001941 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001942 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1943 if (ret < 0)
1944 {
1945 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001946 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001947 return;
1948 }
1949 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1950 journalTmp, sd_journal_close);
1951 journalTmp = nullptr;
1952 // Go to the timestamp in the log and move to the entry at the index
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001953 // tracking the unique ID
1954 std::string idStr;
1955 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001956 ret = sd_journal_seek_realtime_usec(journal.get(), ts);
Manojkiran Eda2056b6d2020-05-28 08:57:36 +05301957 if (ret < 0)
1958 {
1959 BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
1960 << strerror(-ret);
1961 messages::internalError(asyncResp->res);
1962 return;
1963 }
Ed Tanous271584a2019-07-09 16:24:22 -07001964 for (uint64_t i = 0; i <= index; i++)
Jason M. Billse1f26342018-07-18 12:12:00 -07001965 {
1966 sd_journal_next(journal.get());
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001967 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
1968 {
1969 messages::internalError(asyncResp->res);
1970 return;
1971 }
1972 if (firstEntry)
1973 {
1974 firstEntry = false;
1975 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001976 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001977 // Confirm that the entry ID matches what was requested
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001978 if (idStr != entryID)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001979 {
1980 messages::resourceMissingAtURI(asyncResp->res, entryID);
1981 return;
1982 }
1983
1984 if (fillBMCJournalLogEntryJson(entryID, journal.get(),
1985 asyncResp->res.jsonValue) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001986 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001987 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001988 return;
1989 }
1990 }
1991};
1992
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001993class BMCDumpService : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06001994{
1995 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001996 BMCDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001997 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
raviteja-bc9bb6862020-02-03 11:53:32 -06001998 {
1999 entityPrivileges = {
2000 {boost::beast::http::verb::get, {{"Login"}}},
2001 {boost::beast::http::verb::head, {{"Login"}}},
2002 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2003 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2004 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2005 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2006 }
2007
2008 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002009 void doGet(crow::Response& res, const crow::Request&,
2010 const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002011 {
2012 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2013
2014 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002015 "/redfish/v1/Managers/bmc/LogServices/Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002016 asyncResp->res.jsonValue["@odata.type"] =
2017 "#LogService.v1_1_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002018 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2019 asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
2020 asyncResp->res.jsonValue["Id"] = "Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002021 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
raviteja-bc9bb6862020-02-03 11:53:32 -06002022 asyncResp->res.jsonValue["Entries"] = {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002023 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
2024 asyncResp->res.jsonValue["Actions"] = {
2025 {"#LogService.ClearLog",
2026 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2027 "Actions/LogService.ClearLog"}}},
2028 {"Oem",
2029 {{"#OemLogService.CollectDiagnosticData",
2030 {{"target",
2031 "/redfish/v1/Managers/bmc/LogServices/Dump/"
2032 "Actions/Oem/OemLogService.CollectDiagnosticData"}}}}}};
raviteja-bc9bb6862020-02-03 11:53:32 -06002033 }
2034};
2035
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002036class BMCDumpEntryCollection : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002037{
2038 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002039 BMCDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002040 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002041 {
2042 entityPrivileges = {
2043 {boost::beast::http::verb::get, {{"Login"}}},
2044 {boost::beast::http::verb::head, {{"Login"}}},
2045 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2046 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2047 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2048 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2049 }
2050
2051 private:
2052 /**
2053 * Functions triggers appropriate requests on DBus
2054 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002055 void doGet(crow::Response& res, const crow::Request&,
2056 const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002057 {
2058 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2059
2060 asyncResp->res.jsonValue["@odata.type"] =
2061 "#LogEntryCollection.LogEntryCollection";
2062 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002063 "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
2064 asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002065 asyncResp->res.jsonValue["Description"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002066 "Collection of BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002067
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002068 getDumpEntryCollection(asyncResp, "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002069 }
2070};
2071
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002072class BMCDumpEntry : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002073{
2074 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002075 BMCDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002076 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
raviteja-bc9bb6862020-02-03 11:53:32 -06002077 std::string())
2078 {
2079 entityPrivileges = {
2080 {boost::beast::http::verb::get, {{"Login"}}},
2081 {boost::beast::http::verb::head, {{"Login"}}},
2082 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2083 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2084 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2085 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2086 }
2087
2088 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002089 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002090 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002091 {
2092 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2093 if (params.size() != 1)
2094 {
2095 messages::internalError(asyncResp->res);
2096 return;
2097 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002098 getDumpEntryById(asyncResp, params[0], "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002099 }
2100
Ed Tanouscb13a392020-07-25 19:02:03 +00002101 void doDelete(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002102 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002103 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002104 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002105 if (params.size() != 1)
2106 {
2107 messages::internalError(asyncResp->res);
2108 return;
2109 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002110 deleteDumpEntry(asyncResp->res, params[0]);
2111 }
2112};
raviteja-bc9bb6862020-02-03 11:53:32 -06002113
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002114class BMCDumpCreate : public Node
2115{
2116 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002117 BMCDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002118 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2119 "Actions/Oem/"
2120 "OemLogService.CollectDiagnosticData/")
2121 {
2122 entityPrivileges = {
2123 {boost::beast::http::verb::get, {{"Login"}}},
2124 {boost::beast::http::verb::head, {{"Login"}}},
2125 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2126 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2127 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2128 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2129 }
2130
2131 private:
2132 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002133 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002134 {
2135 createDump(res, req, "BMC");
2136 }
2137};
2138
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002139class BMCDumpEntryDownload : public Node
2140{
2141 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002142 BMCDumpEntryDownload(App& app) :
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002143 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/attachment/<str>/",
2144 std::string())
2145 {
2146 entityPrivileges = {
2147 {boost::beast::http::verb::get, {{"Login"}}},
2148 {boost::beast::http::verb::head, {{"Login"}}},
2149 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2150 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2151 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2152 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2153 }
2154
2155 private:
2156 void doGet(crow::Response& res, const crow::Request& req,
2157 const std::vector<std::string>& params) override
2158 {
2159 if (params.size() != 1)
2160 {
2161 messages::internalError(res);
2162 return;
2163 }
2164 const std::string& entryID = params[0];
2165 crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID);
2166 }
2167};
2168
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002169class BMCDumpClear : public Node
2170{
2171 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002172 BMCDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002173 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2174 "Actions/"
2175 "LogService.ClearLog/")
2176 {
2177 entityPrivileges = {
2178 {boost::beast::http::verb::get, {{"Login"}}},
2179 {boost::beast::http::verb::head, {{"Login"}}},
2180 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2181 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2182 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2183 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2184 }
2185
2186 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002187 void doPost(crow::Response& res, const crow::Request&,
2188 const std::vector<std::string>&) override
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002189 {
2190 clearDump(res, "xyz.openbmc_project.Dump.Entry.BMC");
2191 }
2192};
2193
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002194class SystemDumpService : public Node
2195{
2196 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002197 SystemDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002198 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
2199 {
2200 entityPrivileges = {
2201 {boost::beast::http::verb::get, {{"Login"}}},
2202 {boost::beast::http::verb::head, {{"Login"}}},
2203 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2204 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2205 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2206 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2207 }
raviteja-bc9bb6862020-02-03 11:53:32 -06002208
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002209 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002210 void doGet(crow::Response& res, const crow::Request&,
2211 const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002212 {
2213 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002214
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002215 asyncResp->res.jsonValue["@odata.id"] =
2216 "/redfish/v1/Systems/system/LogServices/Dump";
2217 asyncResp->res.jsonValue["@odata.type"] =
2218 "#LogService.v1_1_0.LogService";
2219 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2220 asyncResp->res.jsonValue["Description"] = "System Dump LogService";
2221 asyncResp->res.jsonValue["Id"] = "Dump";
2222 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2223 asyncResp->res.jsonValue["Entries"] = {
2224 {"@odata.id",
2225 "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
2226 asyncResp->res.jsonValue["Actions"] = {
2227 {"#LogService.ClearLog",
2228 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2229 "LogService.ClearLog"}}},
2230 {"Oem",
2231 {{"#OemLogService.CollectDiagnosticData",
2232 {{"target",
2233 "/redfish/v1/Systems/system/LogServices/Dump/Actions/Oem/"
2234 "OemLogService.CollectDiagnosticData"}}}}}};
2235 }
2236};
2237
2238class SystemDumpEntryCollection : public Node
2239{
2240 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002241 SystemDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002242 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
2243 {
2244 entityPrivileges = {
2245 {boost::beast::http::verb::get, {{"Login"}}},
2246 {boost::beast::http::verb::head, {{"Login"}}},
2247 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2248 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2249 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2250 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2251 }
2252
2253 private:
2254 /**
2255 * Functions triggers appropriate requests on DBus
2256 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002257 void doGet(crow::Response& res, const crow::Request&,
2258 const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002259 {
2260 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2261
2262 asyncResp->res.jsonValue["@odata.type"] =
2263 "#LogEntryCollection.LogEntryCollection";
2264 asyncResp->res.jsonValue["@odata.id"] =
2265 "/redfish/v1/Systems/system/LogServices/Dump/Entries";
2266 asyncResp->res.jsonValue["Name"] = "System Dump Entries";
2267 asyncResp->res.jsonValue["Description"] =
2268 "Collection of System Dump Entries";
2269
2270 getDumpEntryCollection(asyncResp, "System");
2271 }
2272};
2273
2274class SystemDumpEntry : public Node
2275{
2276 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002277 SystemDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002278 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
2279 std::string())
2280 {
2281 entityPrivileges = {
2282 {boost::beast::http::verb::get, {{"Login"}}},
2283 {boost::beast::http::verb::head, {{"Login"}}},
2284 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2285 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2286 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2287 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2288 }
2289
2290 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002291 void doGet(crow::Response& res, const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002292 const std::vector<std::string>& params) override
2293 {
2294 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2295 if (params.size() != 1)
2296 {
2297 messages::internalError(asyncResp->res);
2298 return;
2299 }
2300 getDumpEntryById(asyncResp, params[0], "System");
2301 }
2302
Ed Tanouscb13a392020-07-25 19:02:03 +00002303 void doDelete(crow::Response& res, const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002304 const std::vector<std::string>& params) override
2305 {
2306 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2307 if (params.size() != 1)
2308 {
2309 messages::internalError(asyncResp->res);
2310 return;
2311 }
2312 deleteDumpEntry(asyncResp->res, params[0]);
raviteja-bc9bb6862020-02-03 11:53:32 -06002313 }
2314};
2315
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002316class SystemDumpCreate : public Node
2317{
2318 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002319 SystemDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002320 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
2321 "Actions/Oem/"
2322 "OemLogService.CollectDiagnosticData/")
2323 {
2324 entityPrivileges = {
2325 {boost::beast::http::verb::get, {{"Login"}}},
2326 {boost::beast::http::verb::head, {{"Login"}}},
2327 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2328 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2329 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2330 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2331 }
2332
2333 private:
2334 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002335 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002336 {
2337 createDump(res, req, "System");
2338 }
2339};
2340
raviteja-b06578432020-02-03 12:50:42 -06002341class SystemDumpEntryDownload : public Node
2342{
2343 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002344 SystemDumpEntryDownload(App& app) :
raviteja-b06578432020-02-03 12:50:42 -06002345 Node(app,
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002346 "/redfish/v1/Systems/system/LogServices/Dump/attachment/<str>/",
raviteja-b06578432020-02-03 12:50:42 -06002347 std::string())
2348 {
2349 entityPrivileges = {
2350 {boost::beast::http::verb::get, {{"Login"}}},
2351 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002352 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2353 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2354 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b06578432020-02-03 12:50:42 -06002355 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2356 }
2357
2358 private:
Asmitha Karunanithif71882f2020-05-07 06:21:47 -05002359 void doGet(crow::Response& res, const crow::Request& req,
2360 const std::vector<std::string>& params) override
raviteja-b06578432020-02-03 12:50:42 -06002361 {
2362 if (params.size() != 1)
2363 {
2364 messages::internalError(res);
2365 return;
2366 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002367 const std::string& entryID = params[0];
raviteja-b06578432020-02-03 12:50:42 -06002368 crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID);
2369 }
2370};
2371
raviteja-b013487e2020-03-03 03:20:48 -06002372class SystemDumpClear : public Node
2373{
2374 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002375 SystemDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002376 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
raviteja-b013487e2020-03-03 03:20:48 -06002377 "Actions/"
2378 "LogService.ClearLog/")
2379 {
2380 entityPrivileges = {
2381 {boost::beast::http::verb::get, {{"Login"}}},
2382 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002383 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2384 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2385 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b013487e2020-03-03 03:20:48 -06002386 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2387 }
2388
2389 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002390 void doPost(crow::Response& res, const crow::Request&,
2391 const std::vector<std::string>&) override
raviteja-b013487e2020-03-03 03:20:48 -06002392 {
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002393 clearDump(res, "xyz.openbmc_project.Dump.Entry.System");
raviteja-b013487e2020-03-03 03:20:48 -06002394 }
2395};
2396
Jason M. Bills424c4172019-03-21 13:50:33 -07002397class CrashdumpService : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002398{
2399 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002400 CrashdumpService(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002401 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002402 {
AppaRao Puli39460282020-04-07 17:03:04 +05302403 // Note: Deviated from redfish privilege registry for GET & HEAD
2404 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002405 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302406 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2407 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002408 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2409 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2410 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2411 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002412 }
2413
2414 private:
2415 /**
2416 * Functions triggers appropriate requests on DBus
2417 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002418 void doGet(crow::Response& res, const crow::Request&,
2419 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002420 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002421 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002422 // Copy over the static data to include the entries added by SubRoute
Ed Tanous0f74e642018-11-12 15:17:05 -08002423 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002424 "/redfish/v1/Systems/system/LogServices/Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002425 asyncResp->res.jsonValue["@odata.type"] =
2426 "#LogService.v1_1_0.LogService";
Gunnar Mills4f50ae42020-02-06 15:29:57 -06002427 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2428 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2429 asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002430 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2431 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Jason M. Billscd50aa42019-02-12 17:09:02 -08002432 asyncResp->res.jsonValue["Entries"] = {
2433 {"@odata.id",
Jason M. Bills424c4172019-03-21 13:50:33 -07002434 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07002435 asyncResp->res.jsonValue["Actions"] = {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002436 {"#LogService.ClearLog",
2437 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2438 "Actions/LogService.ClearLog"}}},
Ed Tanous1da66f72018-07-27 16:13:37 -07002439 {"Oem",
Jason M. Bills424c4172019-03-21 13:50:33 -07002440 {{"#Crashdump.OnDemand",
2441 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002442 "Actions/Oem/Crashdump.OnDemand"}}},
2443 {"#Crashdump.Telemetry",
2444 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2445 "Actions/Oem/Crashdump.Telemetry"}}}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002446
2447#ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
Jason M. Billse1f26342018-07-18 12:12:00 -07002448 asyncResp->res.jsonValue["Actions"]["Oem"].push_back(
Jason M. Bills424c4172019-03-21 13:50:33 -07002449 {"#Crashdump.SendRawPeci",
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05002450 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2451 "Actions/Oem/Crashdump.SendRawPeci"}}});
Ed Tanous1da66f72018-07-27 16:13:37 -07002452#endif
Ed Tanous1da66f72018-07-27 16:13:37 -07002453 }
2454};
2455
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002456class CrashdumpClear : public Node
2457{
2458 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002459 CrashdumpClear(App& app) :
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002460 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2461 "LogService.ClearLog/")
2462 {
AppaRao Puli39460282020-04-07 17:03:04 +05302463 // Note: Deviated from redfish privilege registry for GET & HEAD
2464 // method for security reasons.
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002465 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302466 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2467 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002468 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2469 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2470 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2471 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2472 }
2473
2474 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002475 void doPost(crow::Response& res, const crow::Request&,
2476 const std::vector<std::string>&) override
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002477 {
2478 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2479
2480 crow::connections::systemBus->async_method_call(
2481 [asyncResp](const boost::system::error_code ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002482 const std::string&) {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002483 if (ec)
2484 {
2485 messages::internalError(asyncResp->res);
2486 return;
2487 }
2488 messages::success(asyncResp->res);
2489 },
2490 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
2491 }
2492};
2493
Jason M. Billse855dd22019-10-08 11:37:48 -07002494static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002495 const std::string& logID,
2496 nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002497{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002498 auto getStoredLogCallback =
2499 [asyncResp, logID, &logEntryJson](
2500 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002501 const std::vector<std::pair<std::string, VariantType>>& params) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002502 if (ec)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002503 {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002504 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
2505 if (ec.value() ==
2506 boost::system::linux_error::bad_request_descriptor)
2507 {
2508 messages::resourceNotFound(asyncResp->res, "LogEntry",
2509 logID);
2510 }
2511 else
2512 {
2513 messages::internalError(asyncResp->res);
2514 }
2515 return;
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002516 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002517
Johnathan Mantey043a0532020-03-10 17:15:28 -07002518 std::string timestamp{};
2519 std::string filename{};
2520 std::string logfile{};
2521 ParseCrashdumpParameters(params, filename, timestamp, logfile);
2522
2523 if (filename.empty() || timestamp.empty())
2524 {
2525 messages::resourceMissingAtURI(asyncResp->res, logID);
2526 return;
2527 }
2528
2529 std::string crashdumpURI =
2530 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2531 logID + "/" + filename;
2532 logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
2533 {"@odata.id", "/redfish/v1/Systems/system/"
2534 "LogServices/Crashdump/Entries/" +
2535 logID},
2536 {"Name", "CPU Crashdump"},
2537 {"Id", logID},
2538 {"EntryType", "Oem"},
2539 {"OemRecordFormat", "Crashdump URI"},
2540 {"Message", std::move(crashdumpURI)},
2541 {"Created", std::move(timestamp)}};
2542 };
Jason M. Billse855dd22019-10-08 11:37:48 -07002543 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002544 std::move(getStoredLogCallback), crashdumpObject,
2545 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002546 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Jason M. Billse855dd22019-10-08 11:37:48 -07002547}
2548
Jason M. Bills424c4172019-03-21 13:50:33 -07002549class CrashdumpEntryCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002550{
2551 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002552 CrashdumpEntryCollection(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002553 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002554 {
AppaRao Puli39460282020-04-07 17:03:04 +05302555 // Note: Deviated from redfish privilege registry for GET & HEAD
2556 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002557 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302558 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2559 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002560 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2561 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2562 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2563 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002564 }
2565
2566 private:
2567 /**
2568 * Functions triggers appropriate requests on DBus
2569 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002570 void doGet(crow::Response& res, const crow::Request&,
2571 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002572 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002573 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002574 // Collections don't include the static data added by SubRoute because
2575 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07002576 auto getLogEntriesCallback = [asyncResp](
2577 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002578 const std::vector<std::string>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002579 if (ec)
2580 {
2581 if (ec.value() !=
2582 boost::system::errc::no_such_file_or_directory)
Ed Tanous1da66f72018-07-27 16:13:37 -07002583 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002584 BMCWEB_LOG_DEBUG << "failed to get entries ec: "
2585 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002586 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002587 return;
Ed Tanous1da66f72018-07-27 16:13:37 -07002588 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002589 }
2590 asyncResp->res.jsonValue["@odata.type"] =
2591 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08002592 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002593 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
Jason M. Bills424c4172019-03-21 13:50:33 -07002594 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002595 asyncResp->res.jsonValue["Description"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002596 "Collection of Crashdump Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002597 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07002598 logEntryArray = nlohmann::json::array();
Jason M. Billse855dd22019-10-08 11:37:48 -07002599 std::vector<std::string> logIDs;
2600 // Get the list of log entries and build up an empty array big
2601 // enough to hold them
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002602 for (const std::string& objpath : resp)
Jason M. Billse1f26342018-07-18 12:12:00 -07002603 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002604 // Get the log ID
Jason M. Billse1f26342018-07-18 12:12:00 -07002605 std::size_t lastPos = objpath.rfind("/");
Jason M. Billse855dd22019-10-08 11:37:48 -07002606 if (lastPos == std::string::npos)
Jason M. Billse1f26342018-07-18 12:12:00 -07002607 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002608 continue;
Jason M. Billse1f26342018-07-18 12:12:00 -07002609 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002610 logIDs.emplace_back(objpath.substr(lastPos + 1));
2611
2612 // Add a space for the log entry to the array
2613 logEntryArray.push_back({});
2614 }
2615 // Now go through and set up async calls to fill in the entries
2616 size_t index = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002617 for (const std::string& logID : logIDs)
Jason M. Billse855dd22019-10-08 11:37:48 -07002618 {
2619 // Add the log entry to the array
2620 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
Jason M. Billse1f26342018-07-18 12:12:00 -07002621 }
2622 asyncResp->res.jsonValue["Members@odata.count"] =
2623 logEntryArray.size();
2624 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002625 crow::connections::systemBus->async_method_call(
2626 std::move(getLogEntriesCallback),
2627 "xyz.openbmc_project.ObjectMapper",
2628 "/xyz/openbmc_project/object_mapper",
2629 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002630 std::array<const char*, 1>{crashdumpInterface});
Ed Tanous1da66f72018-07-27 16:13:37 -07002631 }
2632};
2633
Jason M. Bills424c4172019-03-21 13:50:33 -07002634class CrashdumpEntry : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002635{
2636 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002637 CrashdumpEntry(App& app) :
Jason M. Billsd53dd412019-02-12 17:16:22 -08002638 Node(app,
Jason M. Bills424c4172019-03-21 13:50:33 -07002639 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
Ed Tanous1da66f72018-07-27 16:13:37 -07002640 std::string())
2641 {
AppaRao Puli39460282020-04-07 17:03:04 +05302642 // Note: Deviated from redfish privilege registry for GET & HEAD
2643 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002644 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302645 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2646 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002647 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2648 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2649 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2650 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002651 }
2652
2653 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002654 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002655 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002656 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002657 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002658 if (params.size() != 1)
2659 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002660 messages::internalError(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002661 return;
2662 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002663 const std::string& logID = params[0];
Jason M. Billse855dd22019-10-08 11:37:48 -07002664 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2665 }
2666};
2667
2668class CrashdumpFile : public Node
2669{
2670 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002671 CrashdumpFile(App& app) :
Jason M. Billse855dd22019-10-08 11:37:48 -07002672 Node(app,
2673 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2674 "<str>/",
2675 std::string(), std::string())
2676 {
AppaRao Puli39460282020-04-07 17:03:04 +05302677 // Note: Deviated from redfish privilege registry for GET & HEAD
2678 // method for security reasons.
Jason M. Billse855dd22019-10-08 11:37:48 -07002679 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302680 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2681 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse855dd22019-10-08 11:37:48 -07002682 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2683 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2684 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2685 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2686 }
2687
2688 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002689 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002690 const std::vector<std::string>& params) override
Jason M. Billse855dd22019-10-08 11:37:48 -07002691 {
2692 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2693 if (params.size() != 2)
2694 {
2695 messages::internalError(asyncResp->res);
2696 return;
2697 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002698 const std::string& logID = params[0];
2699 const std::string& fileName = params[1];
Jason M. Billse855dd22019-10-08 11:37:48 -07002700
Johnathan Mantey043a0532020-03-10 17:15:28 -07002701 auto getStoredLogCallback =
2702 [asyncResp, logID, fileName](
2703 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002704 const std::vector<std::pair<std::string, VariantType>>& resp) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002705 if (ec)
2706 {
2707 BMCWEB_LOG_DEBUG << "failed to get log ec: "
2708 << ec.message();
2709 messages::internalError(asyncResp->res);
2710 return;
2711 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002712
Johnathan Mantey043a0532020-03-10 17:15:28 -07002713 std::string dbusFilename{};
2714 std::string dbusTimestamp{};
2715 std::string dbusFilepath{};
Jason M. Billse855dd22019-10-08 11:37:48 -07002716
Johnathan Mantey043a0532020-03-10 17:15:28 -07002717 ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
2718 dbusFilepath);
2719
2720 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2721 dbusFilepath.empty())
2722 {
2723 messages::resourceMissingAtURI(asyncResp->res, fileName);
2724 return;
2725 }
2726
2727 // Verify the file name parameter is correct
2728 if (fileName != dbusFilename)
2729 {
2730 messages::resourceMissingAtURI(asyncResp->res, fileName);
2731 return;
2732 }
2733
2734 if (!std::filesystem::exists(dbusFilepath))
2735 {
2736 messages::resourceMissingAtURI(asyncResp->res, fileName);
2737 return;
2738 }
2739 std::ifstream ifs(dbusFilepath, std::ios::in |
2740 std::ios::binary |
2741 std::ios::ate);
2742 std::ifstream::pos_type fileSize = ifs.tellg();
2743 if (fileSize < 0)
2744 {
2745 messages::generalError(asyncResp->res);
2746 return;
2747 }
2748 ifs.seekg(0, std::ios::beg);
2749
2750 auto crashData = std::make_unique<char[]>(
2751 static_cast<unsigned int>(fileSize));
2752
2753 ifs.read(crashData.get(), static_cast<int>(fileSize));
2754
2755 // The cast to std::string is intentional in order to use the
2756 // assign() that applies move mechanics
2757 asyncResp->res.body().assign(
2758 static_cast<std::string>(crashData.get()));
2759
2760 // Configure this to be a file download when accessed from
2761 // a browser
2762 asyncResp->res.addHeader("Content-Disposition", "attachment");
2763 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002764 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002765 std::move(getStoredLogCallback), crashdumpObject,
2766 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002767 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Ed Tanous1da66f72018-07-27 16:13:37 -07002768 }
2769};
2770
Jason M. Bills424c4172019-03-21 13:50:33 -07002771class OnDemandCrashdump : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002772{
2773 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002774 OnDemandCrashdump(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002775 Node(app,
2776 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2777 "Crashdump.OnDemand/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002778 {
AppaRao Puli39460282020-04-07 17:03:04 +05302779 // Note: Deviated from redfish privilege registry for GET & HEAD
2780 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002781 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302782 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2783 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2784 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2785 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2786 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2787 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002788 }
2789
2790 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002791 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002792 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002793 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002794 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002795
James Feistfe306722020-03-12 16:32:08 -07002796 auto generateonDemandLogCallback = [asyncResp,
2797 req](const boost::system::error_code
2798 ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002799 const std::string&) {
James Feist46229572020-02-19 15:11:58 -08002800 if (ec)
2801 {
2802 if (ec.value() == boost::system::errc::operation_not_supported)
Ed Tanous1da66f72018-07-27 16:13:37 -07002803 {
James Feist46229572020-02-19 15:11:58 -08002804 messages::resourceInStandby(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002805 }
James Feist46229572020-02-19 15:11:58 -08002806 else if (ec.value() ==
2807 boost::system::errc::device_or_resource_busy)
2808 {
2809 messages::serviceTemporarilyUnavailable(asyncResp->res,
2810 "60");
2811 }
2812 else
2813 {
2814 messages::internalError(asyncResp->res);
2815 }
2816 return;
2817 }
2818 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002819 [](boost::system::error_code err, sdbusplus::message::message&,
2820 const std::shared_ptr<task::TaskData>& taskData) {
James Feist66afe4f2020-02-24 13:09:58 -08002821 if (!err)
2822 {
James Feiste5d50062020-05-11 17:29:00 -07002823 taskData->messages.emplace_back(
2824 messages::taskCompletedOK(
2825 std::to_string(taskData->index)));
James Feist831d6b02020-03-12 16:31:30 -07002826 taskData->state = "Completed";
James Feist66afe4f2020-02-24 13:09:58 -08002827 }
James Feist32898ce2020-03-10 16:16:52 -07002828 return task::completed;
James Feist66afe4f2020-02-24 13:09:58 -08002829 },
James Feist46229572020-02-19 15:11:58 -08002830 "type='signal',interface='org.freedesktop.DBus.Properties',"
2831 "member='PropertiesChanged',arg0namespace='com.intel."
2832 "crashdump'");
2833 task->startTimer(std::chrono::minutes(5));
2834 task->populateResp(asyncResp->res);
James Feistfe306722020-03-12 16:32:08 -07002835 task->payload.emplace(req);
James Feist46229572020-02-19 15:11:58 -08002836 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002837 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002838 std::move(generateonDemandLogCallback), crashdumpObject,
2839 crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog");
Ed Tanous1da66f72018-07-27 16:13:37 -07002840 }
2841};
2842
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002843class TelemetryCrashdump : public Node
2844{
2845 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002846 TelemetryCrashdump(App& app) :
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002847 Node(app,
2848 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2849 "Crashdump.Telemetry/")
2850 {
2851 // Note: Deviated from redfish privilege registry for GET & HEAD
2852 // method for security reasons.
2853 entityPrivileges = {
2854 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2855 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2856 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2857 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2858 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2859 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2860 }
2861
2862 private:
2863 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002864 const std::vector<std::string>&) override
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002865 {
2866 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2867
2868 auto generateTelemetryLogCallback = [asyncResp, req](
2869 const boost::system::error_code
2870 ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002871 const std::string&) {
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002872 if (ec)
2873 {
2874 if (ec.value() == boost::system::errc::operation_not_supported)
2875 {
2876 messages::resourceInStandby(asyncResp->res);
2877 }
2878 else if (ec.value() ==
2879 boost::system::errc::device_or_resource_busy)
2880 {
2881 messages::serviceTemporarilyUnavailable(asyncResp->res,
2882 "60");
2883 }
2884 else
2885 {
2886 messages::internalError(asyncResp->res);
2887 }
2888 return;
2889 }
2890 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
2891 [](boost::system::error_code err, sdbusplus::message::message&,
2892 const std::shared_ptr<task::TaskData>& taskData) {
2893 if (!err)
2894 {
2895 taskData->messages.emplace_back(
2896 messages::taskCompletedOK(
2897 std::to_string(taskData->index)));
2898 taskData->state = "Completed";
2899 }
2900 return task::completed;
2901 },
2902 "type='signal',interface='org.freedesktop.DBus.Properties',"
2903 "member='PropertiesChanged',arg0namespace='com.intel."
2904 "crashdump'");
2905 task->startTimer(std::chrono::minutes(5));
2906 task->populateResp(asyncResp->res);
2907 task->payload.emplace(req);
2908 };
2909 crow::connections::systemBus->async_method_call(
2910 std::move(generateTelemetryLogCallback), crashdumpObject,
2911 crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog");
2912 }
2913};
2914
Jason M. Billse1f26342018-07-18 12:12:00 -07002915class SendRawPECI : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002916{
2917 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002918 SendRawPECI(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002919 Node(app,
2920 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2921 "Crashdump.SendRawPeci/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002922 {
AppaRao Puli39460282020-04-07 17:03:04 +05302923 // Note: Deviated from redfish privilege registry for GET & HEAD
2924 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002925 entityPrivileges = {
2926 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2927 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2928 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2929 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2930 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2931 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2932 }
2933
2934 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002935 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002936 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002937 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002938 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002939 std::vector<std::vector<uint8_t>> peciCommands;
Ed Tanousb1556422018-10-16 14:09:17 -07002940
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002941 if (!json_util::readJson(req, res, "PECICommands", peciCommands))
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002942 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002943 return;
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002944 }
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002945 uint32_t idx = 0;
2946 for (auto const& cmd : peciCommands)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002947 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002948 if (cmd.size() < 3)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002949 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002950 std::string s("[");
2951 for (auto const& val : cmd)
2952 {
2953 if (val != *cmd.begin())
2954 {
2955 s += ",";
2956 }
2957 s += std::to_string(val);
2958 }
2959 s += "]";
2960 messages::actionParameterValueFormatError(
2961 res, s, "PECICommands[" + std::to_string(idx) + "]",
2962 "SendRawPeci");
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002963 return;
2964 }
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002965 idx++;
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002966 }
Ed Tanous1da66f72018-07-27 16:13:37 -07002967 // Callback to return the Raw PECI response
Jason M. Billse1f26342018-07-18 12:12:00 -07002968 auto sendRawPECICallback =
2969 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002970 const std::vector<std::vector<uint8_t>>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002971 if (ec)
2972 {
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002973 BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: "
Jason M. Billse1f26342018-07-18 12:12:00 -07002974 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002975 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002976 return;
2977 }
2978 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
2979 {"PECIResponse", resp}};
2980 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002981 // Call the SendRawPECI command with the provided data
2982 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002983 std::move(sendRawPECICallback), crashdumpObject, crashdumpPath,
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002984 crashdumpRawPECIInterface, "SendRawPeci", peciCommands);
Ed Tanous1da66f72018-07-27 16:13:37 -07002985 }
2986};
2987
Andrew Geisslercb92c032018-08-17 07:56:14 -07002988/**
2989 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
2990 */
2991class DBusLogServiceActionsClear : public Node
2992{
2993 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002994 DBusLogServiceActionsClear(App& app) :
Andrew Geisslercb92c032018-08-17 07:56:14 -07002995 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
Gunnar Mills7af91512020-04-14 22:16:57 -05002996 "LogService.ClearLog/")
Andrew Geisslercb92c032018-08-17 07:56:14 -07002997 {
2998 entityPrivileges = {
2999 {boost::beast::http::verb::get, {{"Login"}}},
3000 {boost::beast::http::verb::head, {{"Login"}}},
3001 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3002 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3003 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3004 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3005 }
3006
3007 private:
3008 /**
3009 * Function handles POST method request.
3010 * The Clear Log actions does not require any parameter.The action deletes
3011 * all entries found in the Entries collection for this Log Service.
3012 */
Ed Tanouscb13a392020-07-25 19:02:03 +00003013 void doPost(crow::Response& res, const crow::Request&,
3014 const std::vector<std::string>&) override
Andrew Geisslercb92c032018-08-17 07:56:14 -07003015 {
3016 BMCWEB_LOG_DEBUG << "Do delete all entries.";
3017
3018 auto asyncResp = std::make_shared<AsyncResp>(res);
3019 // Process response from Logging service.
3020 auto resp_handler = [asyncResp](const boost::system::error_code ec) {
3021 BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3022 if (ec)
3023 {
3024 // TODO Handle for specific error code
3025 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3026 asyncResp->res.result(
3027 boost::beast::http::status::internal_server_error);
3028 return;
3029 }
3030
3031 asyncResp->res.result(boost::beast::http::status::no_content);
3032 };
3033
3034 // Make call to Logging service to request Clear Log
3035 crow::connections::systemBus->async_method_call(
3036 resp_handler, "xyz.openbmc_project.Logging",
3037 "/xyz/openbmc_project/logging",
3038 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3039 }
3040};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003041
3042/****************************************************
3043 * Redfish PostCode interfaces
3044 * using DBUS interface: getPostCodesTS
3045 ******************************************************/
3046class PostCodesLogService : public Node
3047{
3048 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003049 PostCodesLogService(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003050 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
3051 {
3052 entityPrivileges = {
3053 {boost::beast::http::verb::get, {{"Login"}}},
3054 {boost::beast::http::verb::head, {{"Login"}}},
3055 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3056 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3057 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3058 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3059 }
3060
3061 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003062 void doGet(crow::Response& res, const crow::Request&,
3063 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003064 {
3065 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3066
3067 asyncResp->res.jsonValue = {
3068 {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
3069 {"@odata.type", "#LogService.v1_1_0.LogService"},
3070 {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"},
3071 {"Name", "POST Code Log Service"},
3072 {"Description", "POST Code Log Service"},
3073 {"Id", "BIOS POST Code Log"},
3074 {"OverWritePolicy", "WrapsWhenFull"},
3075 {"Entries",
3076 {{"@odata.id",
3077 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
3078 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
3079 {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
3080 "Actions/LogService.ClearLog"}};
3081 }
3082};
3083
3084class PostCodesClear : public Node
3085{
3086 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003087 PostCodesClear(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003088 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3089 "LogService.ClearLog/")
3090 {
3091 entityPrivileges = {
3092 {boost::beast::http::verb::get, {{"Login"}}},
3093 {boost::beast::http::verb::head, {{"Login"}}},
AppaRao Puli39460282020-04-07 17:03:04 +05303094 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
3095 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
3096 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
3097 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003098 }
3099
3100 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003101 void doPost(crow::Response& res, const crow::Request&,
3102 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003103 {
3104 BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3105
3106 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3107 // Make call to post-code service to request clear all
3108 crow::connections::systemBus->async_method_call(
3109 [asyncResp](const boost::system::error_code ec) {
3110 if (ec)
3111 {
3112 // TODO Handle for specific error code
3113 BMCWEB_LOG_ERROR
3114 << "doClearPostCodes resp_handler got error " << ec;
3115 asyncResp->res.result(
3116 boost::beast::http::status::internal_server_error);
3117 messages::internalError(asyncResp->res);
3118 return;
3119 }
3120 },
3121 "xyz.openbmc_project.State.Boot.PostCode",
3122 "/xyz/openbmc_project/State/Boot/PostCode",
3123 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3124 }
3125};
3126
3127static void fillPostCodeEntry(
3128 std::shared_ptr<AsyncResp> aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003129 const boost::container::flat_map<uint64_t, uint64_t>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003130 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3131 const uint64_t skip = 0, const uint64_t top = 0)
3132{
3133 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003134 const message_registries::Message* message =
ZhikuiRena3316fc2020-01-29 14:58:08 -08003135 message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003136
3137 uint64_t currentCodeIndex = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003138 nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003139
3140 uint64_t firstCodeTimeUs = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003141 for (const std::pair<uint64_t, uint64_t>& code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003142 {
3143 currentCodeIndex++;
3144 std::string postcodeEntryID =
3145 "B" + std::to_string(bootIndex) + "-" +
3146 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3147
3148 uint64_t usecSinceEpoch = code.first;
3149 uint64_t usTimeOffset = 0;
3150
3151 if (1 == currentCodeIndex)
3152 { // already incremented
3153 firstCodeTimeUs = code.first;
3154 }
3155 else
3156 {
3157 usTimeOffset = code.first - firstCodeTimeUs;
3158 }
3159
3160 // skip if no specific codeIndex is specified and currentCodeIndex does
3161 // not fall between top and skip
3162 if ((codeIndex == 0) &&
3163 (currentCodeIndex <= skip || currentCodeIndex > top))
3164 {
3165 continue;
3166 }
3167
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003168 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003169 // currentIndex
3170 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3171 {
3172 // This is done for simplicity. 1st entry is needed to calculate
3173 // time offset. To improve efficiency, one can get to the entry
3174 // directly (possibly with flatmap's nth method)
3175 continue;
3176 }
3177
3178 // currentCodeIndex is within top and skip or equal to specified code
3179 // index
3180
3181 // Get the Created time from the timestamp
3182 std::string entryTimeStr;
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003183 entryTimeStr = crow::utility::getDateTime(
3184 static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003185
3186 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3187 std::ostringstream hexCode;
3188 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
3189 << code.second;
3190 std::ostringstream timeOffsetStr;
3191 // Set Fixed -Point Notation
3192 timeOffsetStr << std::fixed;
3193 // Set precision to 4 digits
3194 timeOffsetStr << std::setprecision(4);
3195 // Add double to stream
3196 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3197 std::vector<std::string> messageArgs = {
3198 std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3199
3200 // Get MessageArgs template from message registry
3201 std::string msg;
3202 if (message != nullptr)
3203 {
3204 msg = message->message;
3205
3206 // fill in this post code value
3207 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003208 for (const std::string& messageArg : messageArgs)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003209 {
3210 std::string argStr = "%" + std::to_string(++i);
3211 size_t argPos = msg.find(argStr);
3212 if (argPos != std::string::npos)
3213 {
3214 msg.replace(argPos, argStr.length(), messageArg);
3215 }
3216 }
3217 }
3218
Tim Leed4342a92020-04-27 11:47:58 +08003219 // Get Severity template from message registry
3220 std::string severity;
3221 if (message != nullptr)
3222 {
3223 severity = message->severity;
3224 }
3225
ZhikuiRena3316fc2020-01-29 14:58:08 -08003226 // add to AsyncResp
3227 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003228 nlohmann::json& bmcLogEntry = logEntryArray.back();
ZhikuiRena3316fc2020-01-29 14:58:08 -08003229 bmcLogEntry = {
3230 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3231 {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"},
3232 {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3233 "PostCodes/Entries/" +
3234 postcodeEntryID},
3235 {"Name", "POST Code Log Entry"},
3236 {"Id", postcodeEntryID},
3237 {"Message", std::move(msg)},
3238 {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"},
3239 {"MessageArgs", std::move(messageArgs)},
3240 {"EntryType", "Event"},
3241 {"Severity", std::move(severity)},
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003242 {"Created", entryTimeStr}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003243 }
3244}
3245
3246static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp,
3247 const uint16_t bootIndex,
3248 const uint64_t codeIndex)
3249{
3250 crow::connections::systemBus->async_method_call(
3251 [aResp, bootIndex, codeIndex](
3252 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003253 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003254 if (ec)
3255 {
3256 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3257 messages::internalError(aResp->res);
3258 return;
3259 }
3260
3261 // skip the empty postcode boots
3262 if (postcode.empty())
3263 {
3264 return;
3265 }
3266
3267 fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3268
3269 aResp->res.jsonValue["Members@odata.count"] =
3270 aResp->res.jsonValue["Members"].size();
3271 },
3272 "xyz.openbmc_project.State.Boot.PostCode",
3273 "/xyz/openbmc_project/State/Boot/PostCode",
3274 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3275 bootIndex);
3276}
3277
3278static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp,
3279 const uint16_t bootIndex,
3280 const uint16_t bootCount,
3281 const uint64_t entryCount, const uint64_t skip,
3282 const uint64_t top)
3283{
3284 crow::connections::systemBus->async_method_call(
3285 [aResp, bootIndex, bootCount, entryCount, skip,
3286 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003287 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003288 if (ec)
3289 {
3290 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3291 messages::internalError(aResp->res);
3292 return;
3293 }
3294
3295 uint64_t endCount = entryCount;
3296 if (!postcode.empty())
3297 {
3298 endCount = entryCount + postcode.size();
3299
3300 if ((skip < endCount) && ((top + skip) > entryCount))
3301 {
3302 uint64_t thisBootSkip =
3303 std::max(skip, entryCount) - entryCount;
3304 uint64_t thisBootTop =
3305 std::min(top + skip, endCount) - entryCount;
3306
3307 fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3308 thisBootSkip, thisBootTop);
3309 }
3310 aResp->res.jsonValue["Members@odata.count"] = endCount;
3311 }
3312
3313 // continue to previous bootIndex
3314 if (bootIndex < bootCount)
3315 {
3316 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3317 bootCount, endCount, skip, top);
3318 }
3319 else
3320 {
3321 aResp->res.jsonValue["Members@odata.nextLink"] =
3322 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3323 "Entries?$skip=" +
3324 std::to_string(skip + top);
3325 }
3326 },
3327 "xyz.openbmc_project.State.Boot.PostCode",
3328 "/xyz/openbmc_project/State/Boot/PostCode",
3329 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3330 bootIndex);
3331}
3332
3333static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp,
3334 const uint64_t skip, const uint64_t top)
3335{
3336 uint64_t entryCount = 0;
3337 crow::connections::systemBus->async_method_call(
3338 [aResp, entryCount, skip,
3339 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003340 const std::variant<uint16_t>& bootCount) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003341 if (ec)
3342 {
3343 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3344 messages::internalError(aResp->res);
3345 return;
3346 }
3347 auto pVal = std::get_if<uint16_t>(&bootCount);
3348 if (pVal)
3349 {
3350 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3351 }
3352 else
3353 {
3354 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3355 }
3356 },
3357 "xyz.openbmc_project.State.Boot.PostCode",
3358 "/xyz/openbmc_project/State/Boot/PostCode",
3359 "org.freedesktop.DBus.Properties", "Get",
3360 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3361}
3362
3363class PostCodesEntryCollection : public Node
3364{
3365 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003366 PostCodesEntryCollection(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003367 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3368 {
3369 entityPrivileges = {
3370 {boost::beast::http::verb::get, {{"Login"}}},
3371 {boost::beast::http::verb::head, {{"Login"}}},
3372 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3373 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3374 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3375 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3376 }
3377
3378 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003379 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00003380 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003381 {
3382 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3383
3384 asyncResp->res.jsonValue["@odata.type"] =
3385 "#LogEntryCollection.LogEntryCollection";
3386 asyncResp->res.jsonValue["@odata.context"] =
3387 "/redfish/v1/"
3388 "$metadata#LogEntryCollection.LogEntryCollection";
3389 asyncResp->res.jsonValue["@odata.id"] =
3390 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3391 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3392 asyncResp->res.jsonValue["Description"] =
3393 "Collection of POST Code Log Entries";
3394 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3395 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3396
3397 uint64_t skip = 0;
3398 uint64_t top = maxEntriesPerPage; // Show max entries by default
3399 if (!getSkipParam(asyncResp->res, req, skip))
3400 {
3401 return;
3402 }
3403 if (!getTopParam(asyncResp->res, req, top))
3404 {
3405 return;
3406 }
3407 getCurrentBootNumber(asyncResp, skip, top);
3408 }
3409};
3410
3411class PostCodesEntry : public Node
3412{
3413 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003414 PostCodesEntry(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003415 Node(app,
3416 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3417 std::string())
3418 {
3419 entityPrivileges = {
3420 {boost::beast::http::verb::get, {{"Login"}}},
3421 {boost::beast::http::verb::head, {{"Login"}}},
3422 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3423 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3424 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3425 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3426 }
3427
3428 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003429 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003430 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003431 {
3432 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3433 if (params.size() != 1)
3434 {
3435 messages::internalError(asyncResp->res);
3436 return;
3437 }
3438
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003439 const std::string& targetID = params[0];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003440
3441 size_t bootPos = targetID.find('B');
3442 if (bootPos == std::string::npos)
3443 {
3444 // Requested ID was not found
3445 messages::resourceMissingAtURI(asyncResp->res, targetID);
3446 return;
3447 }
3448 std::string_view bootIndexStr(targetID);
3449 bootIndexStr.remove_prefix(bootPos + 1);
3450 uint16_t bootIndex = 0;
3451 uint64_t codeIndex = 0;
3452 size_t dashPos = bootIndexStr.find('-');
3453
3454 if (dashPos == std::string::npos)
3455 {
3456 return;
3457 }
3458 std::string_view codeIndexStr(bootIndexStr);
3459 bootIndexStr.remove_suffix(dashPos);
3460 codeIndexStr.remove_prefix(dashPos + 1);
3461
3462 bootIndex = static_cast<uint16_t>(
Ed Tanous23a21a12020-07-25 04:45:05 +00003463 strtoul(std::string(bootIndexStr).c_str(), nullptr, 0));
3464 codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003465 if (bootIndex == 0 || codeIndex == 0)
3466 {
3467 BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3468 << params[0];
3469 }
3470
3471 asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
3472 asyncResp->res.jsonValue["@odata.context"] =
3473 "/redfish/v1/$metadata#LogEntry.LogEntry";
3474 asyncResp->res.jsonValue["@odata.id"] =
3475 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3476 "Entries";
3477 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3478 asyncResp->res.jsonValue["Description"] =
3479 "Collection of POST Code Log Entries";
3480 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3481 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3482
3483 getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3484 }
3485};
3486
Ed Tanous1da66f72018-07-27 16:13:37 -07003487} // namespace redfish