blob: b572bbfa4f146d37365c6d7ba47602d9003b9851 [file] [log] [blame]
Ed Tanous1da66f72018-07-27 16:13:37 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
18#include "node.hpp"
Jason M. Bills4851d452019-03-28 11:27:48 -070019#include "registries.hpp"
20#include "registries/base_message_registry.hpp"
21#include "registries/openbmc_message_registry.hpp"
James Feist46229572020-02-19 15:11:58 -080022#include "task.hpp"
Ed Tanous1da66f72018-07-27 16:13:37 -070023
Jason M. Billse1f26342018-07-18 12:12:00 -070024#include <systemd/sd-journal.h>
25
Jason M. Bills4851d452019-03-28 11:27:48 -070026#include <boost/algorithm/string/split.hpp>
27#include <boost/beast/core/span.hpp>
Ed Tanous1da66f72018-07-27 16:13:37 -070028#include <boost/container/flat_map.hpp>
Jason M. Bills1ddcf012019-11-26 14:59:21 -080029#include <boost/system/linux_error.hpp>
raviteja-b06578432020-02-03 12:50:42 -060030#include <dump_offload.hpp>
Andrew Geisslercb92c032018-08-17 07:56:14 -070031#include <error_messages.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050032
James Feist4418c7f2019-04-15 11:09:15 -070033#include <filesystem>
Jason M. Billscd225da2019-05-08 15:31:57 -070034#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080035#include <variant>
Ed Tanous1da66f72018-07-27 16:13:37 -070036
37namespace redfish
38{
39
Gunnar Mills1214b7e2020-06-04 10:11:30 -050040constexpr char const* crashdumpObject = "com.intel.crashdump";
41constexpr char const* crashdumpPath = "/com/intel/crashdump";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050042constexpr char const* crashdumpInterface = "com.intel.crashdump";
43constexpr char const* deleteAllInterface =
Jason M. Bills5b61b5e2019-10-16 10:59:02 -070044 "xyz.openbmc_project.Collection.DeleteAll";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050045constexpr char const* crashdumpOnDemandInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070046 "com.intel.crashdump.OnDemand";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050047constexpr char const* crashdumpRawPECIInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070048 "com.intel.crashdump.SendRawPeci";
Kenny L. Ku6eda7682020-06-19 09:48:36 -070049constexpr char const* crashdumpTelemetryInterface =
50 "com.intel.crashdump.Telemetry";
Ed Tanous1da66f72018-07-27 16:13:37 -070051
Jason M. Bills4851d452019-03-28 11:27:48 -070052namespace message_registries
53{
Gunnar Mills1214b7e2020-06-04 10:11:30 -050054static const Message* getMessageFromRegistry(
55 const std::string& messageKey,
Jason M. Bills4851d452019-03-28 11:27:48 -070056 const boost::beast::span<const MessageEntry> registry)
57{
58 boost::beast::span<const MessageEntry>::const_iterator messageIt =
59 std::find_if(registry.cbegin(), registry.cend(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -050060 [&messageKey](const MessageEntry& messageEntry) {
Jason M. Bills4851d452019-03-28 11:27:48 -070061 return !std::strcmp(messageEntry.first,
62 messageKey.c_str());
63 });
64 if (messageIt != registry.cend())
65 {
66 return &messageIt->second;
67 }
68
69 return nullptr;
70}
71
Gunnar Mills1214b7e2020-06-04 10:11:30 -050072static const Message* getMessage(const std::string_view& messageID)
Jason M. Bills4851d452019-03-28 11:27:48 -070073{
74 // Redfish MessageIds are in the form
75 // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
76 // the right Message
77 std::vector<std::string> fields;
78 fields.reserve(4);
79 boost::split(fields, messageID, boost::is_any_of("."));
Gunnar Mills1214b7e2020-06-04 10:11:30 -050080 std::string& registryName = fields[0];
81 std::string& messageKey = fields[3];
Jason M. Bills4851d452019-03-28 11:27:48 -070082
83 // Find the right registry and check it for the MessageKey
84 if (std::string(base::header.registryPrefix) == registryName)
85 {
86 return getMessageFromRegistry(
87 messageKey, boost::beast::span<const MessageEntry>(base::registry));
88 }
89 if (std::string(openbmc::header.registryPrefix) == registryName)
90 {
91 return getMessageFromRegistry(
92 messageKey,
93 boost::beast::span<const MessageEntry>(openbmc::registry));
94 }
95 return nullptr;
96}
97} // namespace message_registries
98
James Feistf6150402019-01-08 10:36:20 -080099namespace fs = std::filesystem;
Ed Tanous1da66f72018-07-27 16:13:37 -0700100
Andrew Geisslercb92c032018-08-17 07:56:14 -0700101using GetManagedPropertyType = boost::container::flat_map<
Patrick Williams19bd78d2020-05-13 17:38:24 -0500102 std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t,
103 int32_t, uint32_t, int64_t, uint64_t, double>>;
Andrew Geisslercb92c032018-08-17 07:56:14 -0700104
105using GetManagedObjectsType = boost::container::flat_map<
106 sdbusplus::message::object_path,
107 boost::container::flat_map<std::string, GetManagedPropertyType>>;
108
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500109inline std::string translateSeverityDbusToRedfish(const std::string& s)
Andrew Geisslercb92c032018-08-17 07:56:14 -0700110{
111 if (s == "xyz.openbmc_project.Logging.Entry.Level.Alert")
112 {
113 return "Critical";
114 }
115 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Critical")
116 {
117 return "Critical";
118 }
119 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Debug")
120 {
121 return "OK";
122 }
123 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency")
124 {
125 return "Critical";
126 }
127 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Error")
128 {
129 return "Critical";
130 }
131 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Informational")
132 {
133 return "OK";
134 }
135 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Notice")
136 {
137 return "OK";
138 }
139 else if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
140 {
141 return "Warning";
142 }
143 return "";
144}
145
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500146static int getJournalMetadata(sd_journal* journal,
147 const std::string_view& field,
148 std::string_view& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700149{
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500150 const char* data = nullptr;
Jason M. Bills16428a12018-11-02 12:42:29 -0700151 size_t length = 0;
152 int ret = 0;
153 // Get the metadata from the requested field of the journal entry
Ed Tanous271584a2019-07-09 16:24:22 -0700154 ret = sd_journal_get_data(journal, field.data(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500155 reinterpret_cast<const void**>(&data), &length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700156 if (ret < 0)
157 {
158 return ret;
159 }
Ed Tanous39e77502019-03-04 17:35:53 -0800160 contents = std::string_view(data, length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700161 // Only use the content after the "=" character.
162 contents.remove_prefix(std::min(contents.find("=") + 1, contents.size()));
163 return ret;
164}
165
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500166static int getJournalMetadata(sd_journal* journal,
167 const std::string_view& field, const int& base,
168 long int& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700169{
170 int ret = 0;
Ed Tanous39e77502019-03-04 17:35:53 -0800171 std::string_view metadata;
Jason M. Bills16428a12018-11-02 12:42:29 -0700172 // Get the metadata from the requested field of the journal entry
173 ret = getJournalMetadata(journal, field, metadata);
174 if (ret < 0)
175 {
176 return ret;
177 }
Ed Tanousb01bf292019-03-25 19:25:26 +0000178 contents = strtol(metadata.data(), nullptr, base);
Jason M. Bills16428a12018-11-02 12:42:29 -0700179 return ret;
180}
181
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500182static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800183{
184 int ret = 0;
185 uint64_t timestamp = 0;
186 ret = sd_journal_get_realtime_usec(journal, &timestamp);
187 if (ret < 0)
188 {
189 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
190 << strerror(-ret);
191 return false;
192 }
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -0500193 entryTimestamp = crow::utility::getDateTime(
194 static_cast<std::time_t>(timestamp / 1000 / 1000));
195 return true;
ZhikuiRena3316fc2020-01-29 14:58:08 -0800196}
197
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500198static bool getSkipParam(crow::Response& res, const crow::Request& req,
199 uint64_t& skip)
Jason M. Bills16428a12018-11-02 12:42:29 -0700200{
James Feist5a7e8772020-07-22 09:08:38 -0700201 boost::urls::url_view::params_type::iterator it =
202 req.urlParams.find("$skip");
203 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700204 {
James Feist5a7e8772020-07-22 09:08:38 -0700205 std::string skipParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500206 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700207 skip = std::strtoul(skipParam.c_str(), &ptr, 10);
208 if (skipParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700209 {
210
211 messages::queryParameterValueTypeError(res, std::string(skipParam),
212 "$skip");
213 return false;
214 }
Jason M. Bills16428a12018-11-02 12:42:29 -0700215 }
216 return true;
217}
218
Ed Tanous271584a2019-07-09 16:24:22 -0700219static constexpr const uint64_t maxEntriesPerPage = 1000;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500220static bool getTopParam(crow::Response& res, const crow::Request& req,
221 uint64_t& top)
Jason M. Bills16428a12018-11-02 12:42:29 -0700222{
James Feist5a7e8772020-07-22 09:08:38 -0700223 boost::urls::url_view::params_type::iterator it =
224 req.urlParams.find("$top");
225 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700226 {
James Feist5a7e8772020-07-22 09:08:38 -0700227 std::string topParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500228 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700229 top = std::strtoul(topParam.c_str(), &ptr, 10);
230 if (topParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700231 {
232 messages::queryParameterValueTypeError(res, std::string(topParam),
233 "$top");
234 return false;
235 }
Ed Tanous271584a2019-07-09 16:24:22 -0700236 if (top < 1U || top > maxEntriesPerPage)
Jason M. Bills16428a12018-11-02 12:42:29 -0700237 {
238
239 messages::queryParameterOutOfRange(
240 res, std::to_string(top), "$top",
241 "1-" + std::to_string(maxEntriesPerPage));
242 return false;
243 }
244 }
245 return true;
246}
247
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500248static bool getUniqueEntryID(sd_journal* journal, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700249 const bool firstEntry = true)
Jason M. Bills16428a12018-11-02 12:42:29 -0700250{
251 int ret = 0;
252 static uint64_t prevTs = 0;
253 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700254 if (firstEntry)
255 {
256 prevTs = 0;
257 }
258
Jason M. Bills16428a12018-11-02 12:42:29 -0700259 // Get the entry timestamp
260 uint64_t curTs = 0;
261 ret = sd_journal_get_realtime_usec(journal, &curTs);
262 if (ret < 0)
263 {
264 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
265 << strerror(-ret);
266 return false;
267 }
268 // If the timestamp isn't unique, increment the index
269 if (curTs == prevTs)
270 {
271 index++;
272 }
273 else
274 {
275 // Otherwise, reset it
276 index = 0;
277 }
278 // Save the timestamp
279 prevTs = curTs;
280
281 entryID = std::to_string(curTs);
282 if (index > 0)
283 {
284 entryID += "_" + std::to_string(index);
285 }
286 return true;
287}
288
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500289static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700290 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700291{
Ed Tanous271584a2019-07-09 16:24:22 -0700292 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700293 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700294 if (firstEntry)
295 {
296 prevTs = 0;
297 }
298
Jason M. Bills95820182019-04-22 16:25:34 -0700299 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700300 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700301 std::tm timeStruct = {};
302 std::istringstream entryStream(logEntry);
303 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
304 {
305 curTs = std::mktime(&timeStruct);
306 }
307 // If the timestamp isn't unique, increment the index
308 if (curTs == prevTs)
309 {
310 index++;
311 }
312 else
313 {
314 // Otherwise, reset it
315 index = 0;
316 }
317 // Save the timestamp
318 prevTs = curTs;
319
320 entryID = std::to_string(curTs);
321 if (index > 0)
322 {
323 entryID += "_" + std::to_string(index);
324 }
325 return true;
326}
327
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500328static bool getTimestampFromID(crow::Response& res, const std::string& entryID,
329 uint64_t& timestamp, uint64_t& index)
Jason M. Bills16428a12018-11-02 12:42:29 -0700330{
331 if (entryID.empty())
332 {
333 return false;
334 }
335 // Convert the unique ID back to a timestamp to find the entry
Ed Tanous39e77502019-03-04 17:35:53 -0800336 std::string_view tsStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700337
338 auto underscorePos = tsStr.find("_");
339 if (underscorePos != tsStr.npos)
340 {
341 // Timestamp has an index
342 tsStr.remove_suffix(tsStr.size() - underscorePos);
Ed Tanous39e77502019-03-04 17:35:53 -0800343 std::string_view indexStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700344 indexStr.remove_prefix(underscorePos + 1);
345 std::size_t pos;
346 try
347 {
Ed Tanous39e77502019-03-04 17:35:53 -0800348 index = std::stoul(std::string(indexStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700349 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500350 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700351 {
352 messages::resourceMissingAtURI(res, entryID);
353 return false;
354 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500355 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700356 {
357 messages::resourceMissingAtURI(res, entryID);
358 return false;
359 }
360 if (pos != indexStr.size())
361 {
362 messages::resourceMissingAtURI(res, entryID);
363 return false;
364 }
365 }
366 // Timestamp has no index
367 std::size_t pos;
368 try
369 {
Ed Tanous39e77502019-03-04 17:35:53 -0800370 timestamp = std::stoull(std::string(tsStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700371 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500372 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700373 {
374 messages::resourceMissingAtURI(res, entryID);
375 return false;
376 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500377 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700378 {
379 messages::resourceMissingAtURI(res, entryID);
380 return false;
381 }
382 if (pos != tsStr.size())
383 {
384 messages::resourceMissingAtURI(res, entryID);
385 return false;
386 }
387 return true;
388}
389
Jason M. Bills95820182019-04-22 16:25:34 -0700390static bool
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500391 getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700392{
393 static const std::filesystem::path redfishLogDir = "/var/log";
394 static const std::string redfishLogFilename = "redfish";
395
396 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500397 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700398 std::filesystem::directory_iterator(redfishLogDir))
399 {
400 // If we find a redfish log file, save the path
401 std::string filename = dirEnt.path().filename();
402 if (boost::starts_with(filename, redfishLogFilename))
403 {
404 redfishLogFiles.emplace_back(redfishLogDir / filename);
405 }
406 }
407 // As the log files rotate, they are appended with a ".#" that is higher for
408 // the older logs. Since we don't expect more than 10 log files, we
409 // can just sort the list to get them in order from newest to oldest
410 std::sort(redfishLogFiles.begin(), redfishLogFiles.end());
411
412 return !redfishLogFiles.empty();
413}
414
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500415inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp,
416 const std::string& dumpType)
417{
418 std::string dumpPath;
419 if (dumpType == "BMC")
420 {
421 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
422 }
423 else if (dumpType == "System")
424 {
425 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
426 }
427 else
428 {
429 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
430 messages::internalError(asyncResp->res);
431 return;
432 }
433
434 crow::connections::systemBus->async_method_call(
435 [asyncResp, dumpPath, dumpType](const boost::system::error_code ec,
436 GetManagedObjectsType& resp) {
437 if (ec)
438 {
439 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
440 messages::internalError(asyncResp->res);
441 return;
442 }
443
444 nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
445 entriesArray = nlohmann::json::array();
446
447 for (auto& object : resp)
448 {
449 bool foundDumpEntry = false;
450 for (auto& interfaceMap : object.second)
451 {
452 if (interfaceMap.first ==
453 ("xyz.openbmc_project.Dump.Entry." + dumpType))
454 {
455 foundDumpEntry = true;
456 break;
457 }
458 }
459
460 if (foundDumpEntry == false)
461 {
462 continue;
463 }
464 std::time_t timestamp;
465 uint64_t size = 0;
466 entriesArray.push_back({});
467 nlohmann::json& thisEntry = entriesArray.back();
468 const std::string& path =
469 static_cast<const std::string&>(object.first);
470 std::size_t lastPos = path.rfind("/");
471 if (lastPos == std::string::npos)
472 {
473 continue;
474 }
475 std::string entryID = path.substr(lastPos + 1);
476
477 for (auto& interfaceMap : object.second)
478 {
479 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
480 {
481
482 for (auto& propertyMap : interfaceMap.second)
483 {
484 if (propertyMap.first == "Size")
485 {
486 auto sizePtr =
487 std::get_if<uint64_t>(&propertyMap.second);
488 if (sizePtr == nullptr)
489 {
490 messages::internalError(asyncResp->res);
491 break;
492 }
493 size = *sizePtr;
494 break;
495 }
496 }
497 }
498 else if (interfaceMap.first ==
499 "xyz.openbmc_project.Time.EpochTime")
500 {
501
502 for (auto& propertyMap : interfaceMap.second)
503 {
504 if (propertyMap.first == "Elapsed")
505 {
506 const uint64_t* usecsTimeStamp =
507 std::get_if<uint64_t>(&propertyMap.second);
508 if (usecsTimeStamp == nullptr)
509 {
510 messages::internalError(asyncResp->res);
511 break;
512 }
513 timestamp =
514 static_cast<std::time_t>(*usecsTimeStamp);
515 break;
516 }
517 }
518 }
519 }
520
521 thisEntry["@odata.type"] = "#LogEntry.v1_5_1.LogEntry";
522 thisEntry["@odata.id"] = dumpPath + entryID;
523 thisEntry["Id"] = entryID;
524 thisEntry["EntryType"] = "Event";
525 thisEntry["Created"] = crow::utility::getDateTime(timestamp);
526 thisEntry["Name"] = dumpType + " Dump Entry";
527
528 thisEntry["Oem"]["OpenBmc"]["@odata.type"] =
529 "#OemLogEntry.v1_0_0.OpenBmc";
530 thisEntry["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] = size;
531
532 if (dumpType == "BMC")
533 {
534 thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] =
535 "Manager";
536 thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] =
537 "/redfish/v1/Managers/bmc/LogServices/Dump/"
538 "attachment/" +
539 entryID;
540 }
541 else if (dumpType == "System")
542 {
543 thisEntry["Oem"]["OpenBmc"]["DiagnosticDataType"] = "OEM";
544 thisEntry["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] =
545 "System";
546 thisEntry["Oem"]["OpenBmc"]["AdditionalDataURI"] =
547 "/redfish/v1/Systems/system/LogServices/Dump/"
548 "attachment/" +
549 entryID;
550 }
551 }
552 asyncResp->res.jsonValue["Members@odata.count"] =
553 entriesArray.size();
554 },
555 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
556 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
557}
558
559inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp,
560 const std::string& entryID,
561 const std::string& dumpType)
562{
563 std::string dumpPath;
564 if (dumpType == "BMC")
565 {
566 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
567 }
568 else if (dumpType == "System")
569 {
570 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
571 }
572 else
573 {
574 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
575 messages::internalError(asyncResp->res);
576 return;
577 }
578
579 crow::connections::systemBus->async_method_call(
580 [asyncResp, entryID, dumpPath, dumpType](
581 const boost::system::error_code ec, GetManagedObjectsType& resp) {
582 if (ec)
583 {
584 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
585 messages::internalError(asyncResp->res);
586 return;
587 }
588
589 for (auto& objectPath : resp)
590 {
591 if (objectPath.first.str.find(
592 "/xyz/openbmc_project/dump/entry/" + entryID) ==
593 std::string::npos)
594 {
595 continue;
596 }
597
598 bool foundDumpEntry = false;
599 for (auto& interfaceMap : objectPath.second)
600 {
601 if (interfaceMap.first ==
602 ("xyz.openbmc_project.Dump.Entry." + dumpType))
603 {
604 foundDumpEntry = true;
605 break;
606 }
607 }
608 if (foundDumpEntry == false)
609 {
610 BMCWEB_LOG_ERROR << "Can't find Dump Entry";
611 messages::internalError(asyncResp->res);
612 return;
613 }
614
615 std::time_t timestamp;
616 uint64_t size = 0;
617
618 for (auto& interfaceMap : objectPath.second)
619 {
620 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
621 {
622 for (auto& propertyMap : interfaceMap.second)
623 {
624 if (propertyMap.first == "Size")
625 {
626 auto sizePtr =
627 std::get_if<uint64_t>(&propertyMap.second);
628 if (sizePtr == nullptr)
629 {
630 messages::internalError(asyncResp->res);
631 break;
632 }
633 size = *sizePtr;
634 break;
635 }
636 }
637 }
638 else if (interfaceMap.first ==
639 "xyz.openbmc_project.Time.EpochTime")
640 {
641 for (auto& propertyMap : interfaceMap.second)
642 {
643 if (propertyMap.first == "Elapsed")
644 {
645 const uint64_t* usecsTimeStamp =
646 std::get_if<uint64_t>(&propertyMap.second);
647 if (usecsTimeStamp == nullptr)
648 {
649 messages::internalError(asyncResp->res);
650 break;
651 }
652 timestamp =
653 static_cast<std::time_t>(*usecsTimeStamp);
654 break;
655 }
656 }
657 }
658 }
659
660 asyncResp->res.jsonValue["@odata.type"] =
661 "#LogEntry.v1_5_1.LogEntry";
662 asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID;
663 asyncResp->res.jsonValue["Id"] = entryID;
664 asyncResp->res.jsonValue["EntryType"] = "Event";
665 asyncResp->res.jsonValue["Created"] =
666 crow::utility::getDateTime(timestamp);
667 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
668
669 asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] =
670 "#OemLogEntry.v1_0_0.OpenBmc";
671 asyncResp->res
672 .jsonValue["Oem"]["OpenBmc"]["AdditionalDataSizeBytes"] =
673 size;
674
675 if (dumpType == "BMC")
676 {
677 asyncResp->res
678 .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] =
679 "Manager";
680 asyncResp->res
681 .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] =
682 "/redfish/v1/Managers/bmc/LogServices/Dump/"
683 "attachment/" +
684 entryID;
685 }
686 else if (dumpType == "System")
687 {
688 asyncResp->res
689 .jsonValue["Oem"]["OpenBmc"]["DiagnosticDataType"] =
690 "OEM";
691 asyncResp->res
692 .jsonValue["Oem"]["OpenBmc"]["OEMDiagnosticDataType"] =
693 "System";
694 asyncResp->res
695 .jsonValue["Oem"]["OpenBmc"]["AdditionalDataURI"] =
696 "/redfish/v1/Systems/system/LogServices/Dump/"
697 "attachment/" +
698 entryID;
699 }
700 }
701 },
702 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
703 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
704}
705
706inline void deleteDumpEntry(crow::Response& res, const std::string& entryID)
707{
708 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
709
710 auto respHandler = [asyncResp](const boost::system::error_code ec) {
711 BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
712 if (ec)
713 {
714 BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
715 << ec;
716 messages::internalError(asyncResp->res);
717 return;
718 }
719 };
720 crow::connections::systemBus->async_method_call(
721 respHandler, "xyz.openbmc_project.Dump.Manager",
722 "/xyz/openbmc_project/dump/entry/" + entryID,
723 "xyz.openbmc_project.Object.Delete", "Delete");
724}
725
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500726inline void createDumpTaskCallback(const crow::Request& req,
727 std::shared_ptr<AsyncResp> asyncResp,
728 const uint32_t& dumpId,
729 const std::string& dumpPath,
730 const std::string& dumpType)
731{
732 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
733 [dumpId, dumpPath, dumpType](
734 boost::system::error_code err, sdbusplus::message::message& m,
735 const std::shared_ptr<task::TaskData>& taskData) {
736 std::vector<std::pair<
737 std::string,
738 std::vector<std::pair<std::string, std::variant<std::string>>>>>
739 interfacesList;
740
741 sdbusplus::message::object_path objPath;
742
743 m.read(objPath, interfacesList);
744
745 for (auto& interface : interfacesList)
746 {
747 if (interface.first ==
748 ("xyz.openbmc_project.Dump.Entry." + dumpType))
749 {
750 nlohmann::json retMessage = messages::success();
751 taskData->messages.emplace_back(retMessage);
752
753 std::string headerLoc =
754 "Location: " + dumpPath + std::to_string(dumpId);
755 taskData->payload->httpHeaders.emplace_back(
756 std::move(headerLoc));
757
758 taskData->state = "Completed";
759 return task::completed;
760 }
761 }
762 return !task::completed;
763 },
764 "type='signal',interface='org.freedesktop.DBus."
765 "ObjectManager',"
766 "member='InterfacesAdded', "
767 "path='/xyz/openbmc_project/dump'");
768
769 task->startTimer(std::chrono::minutes(3));
770 task->populateResp(asyncResp->res);
771 task->payload.emplace(req);
772}
773
774inline void createDump(crow::Response& res, const crow::Request& req,
775 const std::string& dumpType)
776{
777 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
778
779 std::string dumpPath;
780 if (dumpType == "BMC")
781 {
782 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
783 }
784 else if (dumpType == "System")
785 {
786 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
787 }
788 else
789 {
790 BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
791 messages::internalError(asyncResp->res);
792 return;
793 }
794
795 std::optional<std::string> diagnosticDataType;
796 std::optional<std::string> oemDiagnosticDataType;
797
798 if (!redfish::json_util::readJson(
799 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
800 "OEMDiagnosticDataType", oemDiagnosticDataType))
801 {
802 return;
803 }
804
805 if (dumpType == "System")
806 {
807 if (!oemDiagnosticDataType || !diagnosticDataType)
808 {
809 BMCWEB_LOG_ERROR << "CreateDump action parameter "
810 "'DiagnosticDataType'/"
811 "'OEMDiagnosticDataType' value not found!";
812 messages::actionParameterMissing(
813 asyncResp->res, "CollectDiagnosticData",
814 "DiagnosticDataType & OEMDiagnosticDataType");
815 return;
816 }
817 else if ((*oemDiagnosticDataType != "System") ||
818 (*diagnosticDataType != "OEM"))
819 {
820 BMCWEB_LOG_ERROR << "Wrong parameter values passed";
821 messages::invalidObject(asyncResp->res,
822 "System Dump creation parameters");
823 return;
824 }
825 }
826 else if (dumpType == "BMC")
827 {
828 if (!diagnosticDataType)
829 {
830 BMCWEB_LOG_ERROR << "CreateDump action parameter "
831 "'DiagnosticDataType' not found!";
832 messages::actionParameterMissing(
833 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
834 return;
835 }
836 else if (*diagnosticDataType != "Manager")
837 {
838 BMCWEB_LOG_ERROR
839 << "Wrong parameter value passed for 'DiagnosticDataType'";
840 messages::invalidObject(asyncResp->res,
841 "BMC Dump creation parameters");
842 return;
843 }
844 }
845
846 crow::connections::systemBus->async_method_call(
847 [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
848 const uint32_t& dumpId) {
849 if (ec)
850 {
851 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
852 messages::internalError(asyncResp->res);
853 return;
854 }
855 BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
856
857 createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
858 },
859 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
860 "xyz.openbmc_project.Dump.Create", "CreateDump");
861}
862
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500863inline void clearDump(crow::Response& res, const std::string& dumpInterface)
864{
865 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
866 crow::connections::systemBus->async_method_call(
867 [asyncResp](const boost::system::error_code ec,
868 const std::vector<std::string>& subTreePaths) {
869 if (ec)
870 {
871 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
872 messages::internalError(asyncResp->res);
873 return;
874 }
875
876 for (const std::string& path : subTreePaths)
877 {
878 std::size_t pos = path.rfind("/");
879 if (pos != std::string::npos)
880 {
881 std::string logID = path.substr(pos + 1);
882 deleteDumpEntry(asyncResp->res, logID);
883 }
884 }
885 },
886 "xyz.openbmc_project.ObjectMapper",
887 "/xyz/openbmc_project/object_mapper",
888 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
889 "/xyz/openbmc_project/dump", 0,
890 std::array<std::string, 1>{dumpInterface});
891}
892
Johnathan Mantey043a0532020-03-10 17:15:28 -0700893static void ParseCrashdumpParameters(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500894 const std::vector<std::pair<std::string, VariantType>>& params,
895 std::string& filename, std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -0700896{
897 for (auto property : params)
898 {
899 if (property.first == "Timestamp")
900 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500901 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500902 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700903 if (value != nullptr)
904 {
905 timestamp = *value;
906 }
907 }
908 else if (property.first == "Filename")
909 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500910 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500911 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700912 if (value != nullptr)
913 {
914 filename = *value;
915 }
916 }
917 else if (property.first == "Log")
918 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500919 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500920 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700921 if (value != nullptr)
922 {
923 logfile = *value;
924 }
925 }
926 }
927}
928
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500929constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800930class SystemLogServiceCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -0700931{
932 public:
933 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500934 SystemLogServiceCollection(CrowApp& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800935 Node(app, "/redfish/v1/Systems/system/LogServices/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800936 {
937 entityPrivileges = {
938 {boost::beast::http::verb::get, {{"Login"}}},
939 {boost::beast::http::verb::head, {{"Login"}}},
940 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
941 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
942 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
943 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
944 }
945
946 private:
947 /**
948 * Functions triggers appropriate requests on DBus
949 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500950 void doGet(crow::Response& res, const crow::Request& req,
951 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800952 {
953 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800954 // Collections don't include the static data added by SubRoute because
955 // it has a duplicate entry for members
956 asyncResp->res.jsonValue["@odata.type"] =
957 "#LogServiceCollection.LogServiceCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800958 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800959 "/redfish/v1/Systems/system/LogServices";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800960 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
961 asyncResp->res.jsonValue["Description"] =
962 "Collection of LogServices for this Computer System";
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500963 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800964 logServiceArray = nlohmann::json::array();
Ed Tanous029573d2019-02-01 10:57:49 -0800965 logServiceArray.push_back(
966 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500967#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
raviteja-bc9bb6862020-02-03 11:53:32 -0600968 logServiceArray.push_back(
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500969 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
raviteja-bc9bb6862020-02-03 11:53:32 -0600970#endif
971
Jason M. Billsd53dd412019-02-12 17:16:22 -0800972#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
973 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -0500974 {{"@odata.id",
975 "/redfish/v1/Systems/system/LogServices/Crashdump"}});
Jason M. Billsd53dd412019-02-12 17:16:22 -0800976#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800977 asyncResp->res.jsonValue["Members@odata.count"] =
978 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800979
980 crow::connections::systemBus->async_method_call(
981 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500982 const std::vector<std::string>& subtreePath) {
ZhikuiRena3316fc2020-01-29 14:58:08 -0800983 if (ec)
984 {
985 BMCWEB_LOG_ERROR << ec;
986 return;
987 }
988
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500989 for (auto& pathStr : subtreePath)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800990 {
991 if (pathStr.find("PostCode") != std::string::npos)
992 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500993 nlohmann::json& logServiceArray =
ZhikuiRena3316fc2020-01-29 14:58:08 -0800994 asyncResp->res.jsonValue["Members"];
995 logServiceArray.push_back(
996 {{"@odata.id", "/redfish/v1/Systems/system/"
997 "LogServices/PostCodes"}});
998 asyncResp->res.jsonValue["Members@odata.count"] =
999 logServiceArray.size();
1000 return;
1001 }
1002 }
1003 },
1004 "xyz.openbmc_project.ObjectMapper",
1005 "/xyz/openbmc_project/object_mapper",
1006 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001007 std::array<const char*, 1>{postCodeIface});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001008 }
1009};
1010
1011class EventLogService : public Node
1012{
1013 public:
1014 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001015 EventLogService(CrowApp& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001016 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001017 {
1018 entityPrivileges = {
1019 {boost::beast::http::verb::get, {{"Login"}}},
1020 {boost::beast::http::verb::head, {{"Login"}}},
1021 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1022 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1023 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1024 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1025 }
1026
1027 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001028 void doGet(crow::Response& res, const crow::Request& req,
1029 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001030 {
1031 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1032
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001033 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001034 "/redfish/v1/Systems/system/LogServices/EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001035 asyncResp->res.jsonValue["@odata.type"] =
1036 "#LogService.v1_1_0.LogService";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001037 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1038 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
Gunnar Mills73ec8302020-04-14 16:02:42 -05001039 asyncResp->res.jsonValue["Id"] = "EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001040 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1041 asyncResp->res.jsonValue["Entries"] = {
1042 {"@odata.id",
Ed Tanous029573d2019-02-01 10:57:49 -08001043 "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
Gunnar Millse7d6c8b2019-07-03 11:30:01 -05001044 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1045
1046 {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1047 "Actions/LogService.ClearLog"}};
Jason M. Bills489640c2019-05-17 09:56:36 -07001048 }
1049};
1050
Tim Lee1f56a3a2019-10-09 10:17:57 +08001051class JournalEventLogClear : public Node
Jason M. Bills489640c2019-05-17 09:56:36 -07001052{
1053 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001054 JournalEventLogClear(CrowApp& app) :
Jason M. Bills489640c2019-05-17 09:56:36 -07001055 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1056 "LogService.ClearLog/")
1057 {
1058 entityPrivileges = {
1059 {boost::beast::http::verb::get, {{"Login"}}},
1060 {boost::beast::http::verb::head, {{"Login"}}},
1061 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1062 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1063 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1064 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1065 }
1066
1067 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001068 void doPost(crow::Response& res, const crow::Request& req,
1069 const std::vector<std::string>& params) override
Jason M. Bills489640c2019-05-17 09:56:36 -07001070 {
1071 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1072
1073 // Clear the EventLog by deleting the log files
1074 std::vector<std::filesystem::path> redfishLogFiles;
1075 if (getRedfishLogFiles(redfishLogFiles))
1076 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001077 for (const std::filesystem::path& file : redfishLogFiles)
Jason M. Bills489640c2019-05-17 09:56:36 -07001078 {
1079 std::error_code ec;
1080 std::filesystem::remove(file, ec);
1081 }
1082 }
1083
1084 // Reload rsyslog so it knows to start new log files
1085 crow::connections::systemBus->async_method_call(
1086 [asyncResp](const boost::system::error_code ec) {
1087 if (ec)
1088 {
1089 BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1090 messages::internalError(asyncResp->res);
1091 return;
1092 }
1093
1094 messages::success(asyncResp->res);
1095 },
1096 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1097 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1098 "replace");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001099 }
1100};
1101
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001102static int fillEventLogEntryJson(const std::string& logEntryID,
Jason M. Bills95820182019-04-22 16:25:34 -07001103 const std::string logEntry,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001104 nlohmann::json& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001105{
Jason M. Bills95820182019-04-22 16:25:34 -07001106 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001107 // First get the Timestamp
1108 size_t space = logEntry.find_first_of(" ");
1109 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001110 {
1111 return 1;
1112 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001113 std::string timestamp = logEntry.substr(0, space);
1114 // Then get the log contents
1115 size_t entryStart = logEntry.find_first_not_of(" ", space);
1116 if (entryStart == std::string::npos)
1117 {
1118 return 1;
1119 }
1120 std::string_view entry(logEntry);
1121 entry.remove_prefix(entryStart);
1122 // Use split to separate the entry into its fields
1123 std::vector<std::string> logEntryFields;
1124 boost::split(logEntryFields, entry, boost::is_any_of(","),
1125 boost::token_compress_on);
1126 // We need at least a MessageId to be valid
1127 if (logEntryFields.size() < 1)
1128 {
1129 return 1;
1130 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001131 std::string& messageID = logEntryFields[0];
Jason M. Bills95820182019-04-22 16:25:34 -07001132
Jason M. Bills4851d452019-03-28 11:27:48 -07001133 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001134 const message_registries::Message* message =
Jason M. Bills4851d452019-03-28 11:27:48 -07001135 message_registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001136
Jason M. Bills4851d452019-03-28 11:27:48 -07001137 std::string msg;
1138 std::string severity;
1139 if (message != nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001140 {
Jason M. Bills4851d452019-03-28 11:27:48 -07001141 msg = message->message;
1142 severity = message->severity;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001143 }
1144
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001145 // Get the MessageArgs from the log if there are any
1146 boost::beast::span<std::string> messageArgs;
1147 if (logEntryFields.size() > 1)
Jason M. Bills4851d452019-03-28 11:27:48 -07001148 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001149 std::string& messageArgsStart = logEntryFields[1];
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001150 // If the first string is empty, assume there are no MessageArgs
1151 std::size_t messageArgsSize = 0;
1152 if (!messageArgsStart.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001153 {
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001154 messageArgsSize = logEntryFields.size() - 1;
1155 }
1156
1157 messageArgs = boost::beast::span(&messageArgsStart, messageArgsSize);
1158
1159 // Fill the MessageArgs into the Message
1160 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001161 for (const std::string& messageArg : messageArgs)
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001162 {
1163 std::string argStr = "%" + std::to_string(++i);
1164 size_t argPos = msg.find(argStr);
1165 if (argPos != std::string::npos)
1166 {
1167 msg.replace(argPos, argStr.length(), messageArg);
1168 }
Jason M. Bills4851d452019-03-28 11:27:48 -07001169 }
1170 }
1171
Jason M. Bills95820182019-04-22 16:25:34 -07001172 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1173 // format which matches the Redfish format except for the fractional seconds
1174 // between the '.' and the '+', so just remove them.
1175 std::size_t dot = timestamp.find_first_of(".");
1176 std::size_t plus = timestamp.find_first_of("+");
1177 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001178 {
Jason M. Bills95820182019-04-22 16:25:34 -07001179 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001180 }
1181
1182 // Fill in the log entry with the gathered data
Jason M. Bills95820182019-04-22 16:25:34 -07001183 logEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001184 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Ed Tanous029573d2019-02-01 10:57:49 -08001185 {"@odata.id",
Jason M. Bills897967d2019-07-29 17:05:30 -07001186 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
Jason M. Bills95820182019-04-22 16:25:34 -07001187 logEntryID},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001188 {"Name", "System Event Log Entry"},
Jason M. Bills95820182019-04-22 16:25:34 -07001189 {"Id", logEntryID},
1190 {"Message", std::move(msg)},
1191 {"MessageId", std::move(messageID)},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001192 {"MessageArgs", std::move(messageArgs)},
1193 {"EntryType", "Event"},
Jason M. Bills95820182019-04-22 16:25:34 -07001194 {"Severity", std::move(severity)},
1195 {"Created", std::move(timestamp)}};
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001196 return 0;
1197}
1198
Anthony Wilson27062602019-04-22 02:10:09 -05001199class JournalEventLogEntryCollection : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001200{
1201 public:
1202 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001203 JournalEventLogEntryCollection(CrowApp& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001204 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001205 {
1206 entityPrivileges = {
1207 {boost::beast::http::verb::get, {{"Login"}}},
1208 {boost::beast::http::verb::head, {{"Login"}}},
1209 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1210 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1211 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1212 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1213 }
1214
1215 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001216 void doGet(crow::Response& res, const crow::Request& req,
1217 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001218 {
1219 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous271584a2019-07-09 16:24:22 -07001220 uint64_t skip = 0;
1221 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001222 if (!getSkipParam(asyncResp->res, req, skip))
1223 {
1224 return;
1225 }
1226 if (!getTopParam(asyncResp->res, req, top))
1227 {
1228 return;
1229 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001230 // Collections don't include the static data added by SubRoute because
1231 // it has a duplicate entry for members
1232 asyncResp->res.jsonValue["@odata.type"] =
1233 "#LogEntryCollection.LogEntryCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001234 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001235 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001236 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1237 asyncResp->res.jsonValue["Description"] =
1238 "Collection of System Event Log Entries";
Andrew Geisslercb92c032018-08-17 07:56:14 -07001239
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001240 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001241 logEntryArray = nlohmann::json::array();
Jason M. Bills95820182019-04-22 16:25:34 -07001242 // Go through the log files and create a unique ID for each entry
1243 std::vector<std::filesystem::path> redfishLogFiles;
1244 getRedfishLogFiles(redfishLogFiles);
Ed Tanousb01bf292019-03-25 19:25:26 +00001245 uint64_t entryCount = 0;
Jason M. Billscd225da2019-05-08 15:31:57 -07001246 std::string logEntry;
Jason M. Bills95820182019-04-22 16:25:34 -07001247
1248 // Oldest logs are in the last file, so start there and loop backwards
Jason M. Billscd225da2019-05-08 15:31:57 -07001249 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1250 it++)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001251 {
Jason M. Billscd225da2019-05-08 15:31:57 -07001252 std::ifstream logStream(*it);
Jason M. Bills95820182019-04-22 16:25:34 -07001253 if (!logStream.is_open())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001254 {
1255 continue;
1256 }
1257
Jason M. Billse85d6b12019-07-29 17:01:15 -07001258 // Reset the unique ID on the first entry
1259 bool firstEntry = true;
Jason M. Bills95820182019-04-22 16:25:34 -07001260 while (std::getline(logStream, logEntry))
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001261 {
Jason M. Bills95820182019-04-22 16:25:34 -07001262 entryCount++;
1263 // Handle paging using skip (number of entries to skip from the
1264 // start) and top (number of entries to display)
1265 if (entryCount <= skip || entryCount > skip + top)
1266 {
1267 continue;
1268 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001269
Jason M. Bills95820182019-04-22 16:25:34 -07001270 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001271 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Jason M. Bills95820182019-04-22 16:25:34 -07001272 {
1273 continue;
1274 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001275
Jason M. Billse85d6b12019-07-29 17:01:15 -07001276 if (firstEntry)
1277 {
1278 firstEntry = false;
1279 }
1280
Jason M. Bills95820182019-04-22 16:25:34 -07001281 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001282 nlohmann::json& bmcLogEntry = logEntryArray.back();
Jason M. Bills95820182019-04-22 16:25:34 -07001283 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
1284 {
1285 messages::internalError(asyncResp->res);
1286 return;
1287 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001288 }
1289 }
1290 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1291 if (skip + top < entryCount)
1292 {
1293 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Bills95820182019-04-22 16:25:34 -07001294 "/redfish/v1/Systems/system/LogServices/EventLog/"
1295 "Entries?$skip=" +
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001296 std::to_string(skip + top);
1297 }
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001298 }
1299};
1300
Jason M. Bills897967d2019-07-29 17:05:30 -07001301class JournalEventLogEntry : public Node
1302{
1303 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001304 JournalEventLogEntry(CrowApp& app) :
Jason M. Bills897967d2019-07-29 17:05:30 -07001305 Node(app,
1306 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1307 std::string())
1308 {
1309 entityPrivileges = {
1310 {boost::beast::http::verb::get, {{"Login"}}},
1311 {boost::beast::http::verb::head, {{"Login"}}},
1312 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1313 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1314 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1315 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1316 }
1317
1318 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001319 void doGet(crow::Response& res, const crow::Request& req,
1320 const std::vector<std::string>& params) override
Jason M. Bills897967d2019-07-29 17:05:30 -07001321 {
1322 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1323 if (params.size() != 1)
1324 {
1325 messages::internalError(asyncResp->res);
1326 return;
1327 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001328 const std::string& targetID = params[0];
Jason M. Bills897967d2019-07-29 17:05:30 -07001329
1330 // Go through the log files and check the unique ID for each entry to
1331 // find the target entry
1332 std::vector<std::filesystem::path> redfishLogFiles;
1333 getRedfishLogFiles(redfishLogFiles);
1334 std::string logEntry;
1335
1336 // Oldest logs are in the last file, so start there and loop backwards
1337 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1338 it++)
1339 {
1340 std::ifstream logStream(*it);
1341 if (!logStream.is_open())
1342 {
1343 continue;
1344 }
1345
1346 // Reset the unique ID on the first entry
1347 bool firstEntry = true;
1348 while (std::getline(logStream, logEntry))
1349 {
1350 std::string idStr;
1351 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1352 {
1353 continue;
1354 }
1355
1356 if (firstEntry)
1357 {
1358 firstEntry = false;
1359 }
1360
1361 if (idStr == targetID)
1362 {
1363 if (fillEventLogEntryJson(idStr, logEntry,
1364 asyncResp->res.jsonValue) != 0)
1365 {
1366 messages::internalError(asyncResp->res);
1367 return;
1368 }
1369 return;
1370 }
1371 }
1372 }
1373 // Requested ID was not found
1374 messages::resourceMissingAtURI(asyncResp->res, targetID);
1375 }
1376};
1377
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001378class DBusEventLogEntryCollection : public Node
1379{
1380 public:
1381 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001382 DBusEventLogEntryCollection(CrowApp& app) :
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001383 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1384 {
1385 entityPrivileges = {
1386 {boost::beast::http::verb::get, {{"Login"}}},
1387 {boost::beast::http::verb::head, {{"Login"}}},
1388 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1389 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1390 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1391 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1392 }
1393
1394 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001395 void doGet(crow::Response& res, const crow::Request& req,
1396 const std::vector<std::string>& params) override
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001397 {
1398 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1399
1400 // Collections don't include the static data added by SubRoute because
1401 // it has a duplicate entry for members
1402 asyncResp->res.jsonValue["@odata.type"] =
1403 "#LogEntryCollection.LogEntryCollection";
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001404 asyncResp->res.jsonValue["@odata.id"] =
1405 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1406 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1407 asyncResp->res.jsonValue["Description"] =
1408 "Collection of System Event Log Entries";
1409
Andrew Geisslercb92c032018-08-17 07:56:14 -07001410 // DBus implementation of EventLog/Entries
1411 // Make call to Logging Service to find all log entry objects
1412 crow::connections::systemBus->async_method_call(
1413 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001414 GetManagedObjectsType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001415 if (ec)
1416 {
1417 // TODO Handle for specific error code
1418 BMCWEB_LOG_ERROR
1419 << "getLogEntriesIfaceData resp_handler got error "
1420 << ec;
1421 messages::internalError(asyncResp->res);
1422 return;
1423 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001424 nlohmann::json& entriesArray =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001425 asyncResp->res.jsonValue["Members"];
1426 entriesArray = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001427 for (auto& objectPath : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001428 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001429 for (auto& interfaceMap : objectPath.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001430 {
1431 if (interfaceMap.first !=
1432 "xyz.openbmc_project.Logging.Entry")
1433 {
1434 BMCWEB_LOG_DEBUG << "Bailing early on "
1435 << interfaceMap.first;
1436 continue;
1437 }
1438 entriesArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001439 nlohmann::json& thisEntry = entriesArray.back();
1440 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001441 std::time_t timestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001442 std::string* severity = nullptr;
1443 std::string* message = nullptr;
1444 for (auto& propertyMap : interfaceMap.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001445 {
1446 if (propertyMap.first == "Id")
1447 {
Patrick Williams8d78b7a2020-05-13 11:24:20 -05001448 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001449 if (id == nullptr)
1450 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001451 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001452 }
1453 }
1454 else if (propertyMap.first == "Timestamp")
1455 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001456 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001457 std::get_if<uint64_t>(&propertyMap.second);
1458 if (millisTimeStamp == nullptr)
1459 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001460 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001461 continue;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001462 }
1463 // Retrieve Created property with format:
1464 // yyyy-mm-ddThh:mm:ss
1465 std::chrono::milliseconds chronoTimeStamp(
1466 *millisTimeStamp);
Ed Tanous271584a2019-07-09 16:24:22 -07001467 timestamp = std::chrono::duration_cast<
1468 std::chrono::duration<int>>(
1469 chronoTimeStamp)
1470 .count();
Andrew Geisslercb92c032018-08-17 07:56:14 -07001471 }
1472 else if (propertyMap.first == "Severity")
1473 {
1474 severity = std::get_if<std::string>(
1475 &propertyMap.second);
1476 if (severity == nullptr)
1477 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001478 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001479 }
1480 }
1481 else if (propertyMap.first == "Message")
1482 {
1483 message = std::get_if<std::string>(
1484 &propertyMap.second);
1485 if (message == nullptr)
1486 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001487 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001488 }
1489 }
1490 }
1491 thisEntry = {
1492 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001493 {"@odata.id",
1494 "/redfish/v1/Systems/system/LogServices/EventLog/"
1495 "Entries/" +
1496 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001497 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001498 {"Id", std::to_string(*id)},
1499 {"Message", *message},
1500 {"EntryType", "Event"},
1501 {"Severity",
1502 translateSeverityDbusToRedfish(*severity)},
1503 {"Created", crow::utility::getDateTime(timestamp)}};
1504 }
1505 }
1506 std::sort(entriesArray.begin(), entriesArray.end(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001507 [](const nlohmann::json& left,
1508 const nlohmann::json& right) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001509 return (left["Id"] <= right["Id"]);
1510 });
1511 asyncResp->res.jsonValue["Members@odata.count"] =
1512 entriesArray.size();
1513 },
1514 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
1515 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001516 }
1517};
1518
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001519class DBusEventLogEntry : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001520{
1521 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001522 DBusEventLogEntry(CrowApp& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001523 Node(app,
Ed Tanous029573d2019-02-01 10:57:49 -08001524 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1525 std::string())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001526 {
1527 entityPrivileges = {
1528 {boost::beast::http::verb::get, {{"Login"}}},
1529 {boost::beast::http::verb::head, {{"Login"}}},
1530 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1531 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1532 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1533 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1534 }
1535
1536 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001537 void doGet(crow::Response& res, const crow::Request& req,
1538 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001539 {
1540 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous029573d2019-02-01 10:57:49 -08001541 if (params.size() != 1)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001542 {
1543 messages::internalError(asyncResp->res);
1544 return;
1545 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001546 const std::string& entryID = params[0];
Andrew Geisslercb92c032018-08-17 07:56:14 -07001547
Andrew Geisslercb92c032018-08-17 07:56:14 -07001548 // DBus implementation of EventLog/Entries
1549 // Make call to Logging Service to find all log entry objects
1550 crow::connections::systemBus->async_method_call(
1551 [asyncResp, entryID](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001552 GetManagedPropertyType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001553 if (ec)
1554 {
1555 BMCWEB_LOG_ERROR
1556 << "EventLogEntry (DBus) resp_handler got error " << ec;
1557 messages::internalError(asyncResp->res);
1558 return;
1559 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001560 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001561 std::time_t timestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001562 std::string* severity = nullptr;
1563 std::string* message = nullptr;
1564 for (auto& propertyMap : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001565 {
1566 if (propertyMap.first == "Id")
1567 {
1568 id = std::get_if<uint32_t>(&propertyMap.second);
1569 if (id == nullptr)
1570 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001571 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001572 }
1573 }
1574 else if (propertyMap.first == "Timestamp")
1575 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001576 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001577 std::get_if<uint64_t>(&propertyMap.second);
1578 if (millisTimeStamp == nullptr)
1579 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001580 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001581 continue;
Andrew Geisslercb92c032018-08-17 07:56:14 -07001582 }
1583 // Retrieve Created property with format:
1584 // yyyy-mm-ddThh:mm:ss
1585 std::chrono::milliseconds chronoTimeStamp(
1586 *millisTimeStamp);
1587 timestamp =
Ed Tanous271584a2019-07-09 16:24:22 -07001588 std::chrono::duration_cast<
1589 std::chrono::duration<int>>(chronoTimeStamp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001590 .count();
1591 }
1592 else if (propertyMap.first == "Severity")
1593 {
1594 severity =
1595 std::get_if<std::string>(&propertyMap.second);
1596 if (severity == nullptr)
1597 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001598 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001599 }
1600 }
1601 else if (propertyMap.first == "Message")
1602 {
1603 message = std::get_if<std::string>(&propertyMap.second);
1604 if (message == nullptr)
1605 {
Asmitha Karunanithi0f1d8ed2020-08-02 11:11:47 -05001606 messages::internalError(asyncResp->res);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001607 }
1608 }
1609 }
Ed Tanous271584a2019-07-09 16:24:22 -07001610 if (id == nullptr || message == nullptr || severity == nullptr)
1611 {
1612 return;
1613 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001614 asyncResp->res.jsonValue = {
1615 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001616 {"@odata.id",
1617 "/redfish/v1/Systems/system/LogServices/EventLog/"
1618 "Entries/" +
1619 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001620 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001621 {"Id", std::to_string(*id)},
1622 {"Message", *message},
1623 {"EntryType", "Event"},
1624 {"Severity", translateSeverityDbusToRedfish(*severity)},
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001625 {"Created", crow::utility::getDateTime(timestamp)}};
Andrew Geisslercb92c032018-08-17 07:56:14 -07001626 },
1627 "xyz.openbmc_project.Logging",
1628 "/xyz/openbmc_project/logging/entry/" + entryID,
1629 "org.freedesktop.DBus.Properties", "GetAll",
1630 "xyz.openbmc_project.Logging.Entry");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001631 }
Chicago Duan336e96c2019-07-15 14:22:08 +08001632
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001633 void doDelete(crow::Response& res, const crow::Request& req,
1634 const std::vector<std::string>& params) override
Chicago Duan336e96c2019-07-15 14:22:08 +08001635 {
1636
1637 BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1638
1639 auto asyncResp = std::make_shared<AsyncResp>(res);
1640
1641 if (params.size() != 1)
1642 {
1643 messages::internalError(asyncResp->res);
1644 return;
1645 }
1646 std::string entryID = params[0];
1647
1648 dbus::utility::escapePathForDbus(entryID);
1649
1650 // Process response from Logging service.
1651 auto respHandler = [asyncResp](const boost::system::error_code ec) {
1652 BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1653 if (ec)
1654 {
1655 // TODO Handle for specific error code
1656 BMCWEB_LOG_ERROR
1657 << "EventLogEntry (DBus) doDelete respHandler got error "
1658 << ec;
1659 asyncResp->res.result(
1660 boost::beast::http::status::internal_server_error);
1661 return;
1662 }
1663
1664 asyncResp->res.result(boost::beast::http::status::ok);
1665 };
1666
1667 // Make call to Logging service to request Delete Log
1668 crow::connections::systemBus->async_method_call(
1669 respHandler, "xyz.openbmc_project.Logging",
1670 "/xyz/openbmc_project/logging/entry/" + entryID,
1671 "xyz.openbmc_project.Object.Delete", "Delete");
1672 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001673};
1674
1675class BMCLogServiceCollection : public Node
1676{
1677 public:
1678 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001679 BMCLogServiceCollection(CrowApp& 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 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001695 void doGet(crow::Response& res, const crow::Request& req,
1696 const std::vector<std::string>& params) 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:
1726 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001727 BMCJournalLogService(CrowApp& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001728 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001729 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001730 entityPrivileges = {
1731 {boost::beast::http::verb::get, {{"Login"}}},
1732 {boost::beast::http::verb::head, {{"Login"}}},
1733 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1734 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1735 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1736 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1737 }
1738
1739 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001740 void doGet(crow::Response& res, const crow::Request& req,
1741 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001742 {
1743 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001744 asyncResp->res.jsonValue["@odata.type"] =
1745 "#LogService.v1_1_0.LogService";
Ed Tanous0f74e642018-11-12 15:17:05 -08001746 asyncResp->res.jsonValue["@odata.id"] =
1747 "/redfish/v1/Managers/bmc/LogServices/Journal";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001748 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1749 asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1750 asyncResp->res.jsonValue["Id"] = "BMC Journal";
Jason M. Billse1f26342018-07-18 12:12:00 -07001751 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
Jason M. Billscd50aa42019-02-12 17:09:02 -08001752 asyncResp->res.jsonValue["Entries"] = {
1753 {"@odata.id",
Ed Tanous086be232019-05-23 11:47:09 -07001754 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07001755 }
1756};
1757
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001758static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1759 sd_journal* journal,
1760 nlohmann::json& bmcJournalLogEntryJson)
Jason M. Billse1f26342018-07-18 12:12:00 -07001761{
1762 // Get the Log Entry contents
1763 int ret = 0;
Jason M. Billse1f26342018-07-18 12:12:00 -07001764
Ed Tanous39e77502019-03-04 17:35:53 -08001765 std::string_view msg;
Jason M. Bills16428a12018-11-02 12:42:29 -07001766 ret = getJournalMetadata(journal, "MESSAGE", msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001767 if (ret < 0)
1768 {
1769 BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1770 return 1;
1771 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001772
1773 // Get the severity from the PRIORITY field
Ed Tanous271584a2019-07-09 16:24:22 -07001774 long int severity = 8; // Default to an invalid priority
Jason M. Bills16428a12018-11-02 12:42:29 -07001775 ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
Jason M. Billse1f26342018-07-18 12:12:00 -07001776 if (ret < 0)
1777 {
1778 BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
Jason M. Billse1f26342018-07-18 12:12:00 -07001779 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001780
1781 // Get the Created time from the timestamp
Jason M. Bills16428a12018-11-02 12:42:29 -07001782 std::string entryTimeStr;
1783 if (!getEntryTimestamp(journal, entryTimeStr))
Jason M. Billse1f26342018-07-18 12:12:00 -07001784 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001785 return 1;
Jason M. Billse1f26342018-07-18 12:12:00 -07001786 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001787
1788 // Fill in the log entry with the gathered data
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001789 bmcJournalLogEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001790 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001791 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
1792 bmcJournalLogEntryID},
Jason M. Billse1f26342018-07-18 12:12:00 -07001793 {"Name", "BMC Journal Entry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001794 {"Id", bmcJournalLogEntryID},
Jason M. Bills16428a12018-11-02 12:42:29 -07001795 {"Message", msg},
Jason M. Billse1f26342018-07-18 12:12:00 -07001796 {"EntryType", "Oem"},
1797 {"Severity",
Jason M. Billsb6a61a52019-08-01 14:26:15 -07001798 severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"},
Ed Tanous086be232019-05-23 11:47:09 -07001799 {"OemRecordFormat", "BMC Journal Entry"},
Jason M. Billse1f26342018-07-18 12:12:00 -07001800 {"Created", std::move(entryTimeStr)}};
1801 return 0;
1802}
1803
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001804class BMCJournalLogEntryCollection : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001805{
1806 public:
1807 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001808 BMCJournalLogEntryCollection(CrowApp& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001809 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001810 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001811 entityPrivileges = {
1812 {boost::beast::http::verb::get, {{"Login"}}},
1813 {boost::beast::http::verb::head, {{"Login"}}},
1814 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1815 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1816 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1817 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1818 }
1819
1820 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001821 void doGet(crow::Response& res, const crow::Request& req,
1822 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001823 {
1824 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001825 static constexpr const long maxEntriesPerPage = 1000;
Ed Tanous271584a2019-07-09 16:24:22 -07001826 uint64_t skip = 0;
1827 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Bills16428a12018-11-02 12:42:29 -07001828 if (!getSkipParam(asyncResp->res, req, skip))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001829 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001830 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001831 }
Jason M. Bills16428a12018-11-02 12:42:29 -07001832 if (!getTopParam(asyncResp->res, req, top))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001833 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001834 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001835 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001836 // Collections don't include the static data added by SubRoute because
1837 // it has a duplicate entry for members
1838 asyncResp->res.jsonValue["@odata.type"] =
1839 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08001840 asyncResp->res.jsonValue["@odata.id"] =
1841 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001842 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001843 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001844 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
1845 asyncResp->res.jsonValue["Description"] =
1846 "Collection of BMC Journal Entries";
Ed Tanous0f74e642018-11-12 15:17:05 -08001847 asyncResp->res.jsonValue["@odata.id"] =
1848 "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001849 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07001850 logEntryArray = nlohmann::json::array();
1851
1852 // Go through the journal and use the timestamp to create a unique ID
1853 // for each entry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001854 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001855 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1856 if (ret < 0)
1857 {
1858 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001859 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001860 return;
1861 }
1862 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1863 journalTmp, sd_journal_close);
1864 journalTmp = nullptr;
Ed Tanousb01bf292019-03-25 19:25:26 +00001865 uint64_t entryCount = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001866 // Reset the unique ID on the first entry
1867 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001868 SD_JOURNAL_FOREACH(journal.get())
1869 {
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001870 entryCount++;
1871 // Handle paging using skip (number of entries to skip from the
1872 // start) and top (number of entries to display)
1873 if (entryCount <= skip || entryCount > skip + top)
1874 {
1875 continue;
1876 }
1877
Jason M. Bills16428a12018-11-02 12:42:29 -07001878 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001879 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
Jason M. Billse1f26342018-07-18 12:12:00 -07001880 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001881 continue;
1882 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001883
Jason M. Billse85d6b12019-07-29 17:01:15 -07001884 if (firstEntry)
1885 {
1886 firstEntry = false;
1887 }
1888
Jason M. Billse1f26342018-07-18 12:12:00 -07001889 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001890 nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001891 if (fillBMCJournalLogEntryJson(idStr, journal.get(),
1892 bmcJournalLogEntry) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001893 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001894 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001895 return;
1896 }
1897 }
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001898 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1899 if (skip + top < entryCount)
1900 {
1901 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001902 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001903 std::to_string(skip + top);
1904 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001905 }
1906};
1907
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001908class BMCJournalLogEntry : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001909{
1910 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001911 BMCJournalLogEntry(CrowApp& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001912 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
Jason M. Billse1f26342018-07-18 12:12:00 -07001913 std::string())
1914 {
1915 entityPrivileges = {
1916 {boost::beast::http::verb::get, {{"Login"}}},
1917 {boost::beast::http::verb::head, {{"Login"}}},
1918 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1919 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1920 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1921 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1922 }
1923
1924 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001925 void doGet(crow::Response& res, const crow::Request& req,
1926 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001927 {
1928 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1929 if (params.size() != 1)
1930 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001931 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001932 return;
1933 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001934 const std::string& entryID = params[0];
Jason M. Billse1f26342018-07-18 12:12:00 -07001935 // Convert the unique ID back to a timestamp to find the entry
Jason M. Billse1f26342018-07-18 12:12:00 -07001936 uint64_t ts = 0;
Ed Tanous271584a2019-07-09 16:24:22 -07001937 uint64_t index = 0;
Jason M. Bills16428a12018-11-02 12:42:29 -07001938 if (!getTimestampFromID(asyncResp->res, entryID, ts, index))
Jason M. Billse1f26342018-07-18 12:12:00 -07001939 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001940 return;
Jason M. Billse1f26342018-07-18 12:12:00 -07001941 }
1942
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001943 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001944 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1945 if (ret < 0)
1946 {
1947 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001948 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001949 return;
1950 }
1951 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1952 journalTmp, sd_journal_close);
1953 journalTmp = nullptr;
1954 // Go to the timestamp in the log and move to the entry at the index
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001955 // tracking the unique ID
1956 std::string idStr;
1957 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001958 ret = sd_journal_seek_realtime_usec(journal.get(), ts);
Manojkiran Eda2056b6d2020-05-28 08:57:36 +05301959 if (ret < 0)
1960 {
1961 BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
1962 << strerror(-ret);
1963 messages::internalError(asyncResp->res);
1964 return;
1965 }
Ed Tanous271584a2019-07-09 16:24:22 -07001966 for (uint64_t i = 0; i <= index; i++)
Jason M. Billse1f26342018-07-18 12:12:00 -07001967 {
1968 sd_journal_next(journal.get());
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001969 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
1970 {
1971 messages::internalError(asyncResp->res);
1972 return;
1973 }
1974 if (firstEntry)
1975 {
1976 firstEntry = false;
1977 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001978 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001979 // Confirm that the entry ID matches what was requested
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001980 if (idStr != entryID)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001981 {
1982 messages::resourceMissingAtURI(asyncResp->res, entryID);
1983 return;
1984 }
1985
1986 if (fillBMCJournalLogEntryJson(entryID, journal.get(),
1987 asyncResp->res.jsonValue) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001988 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001989 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001990 return;
1991 }
1992 }
1993};
1994
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001995class BMCDumpService : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06001996{
1997 public:
1998 template <typename CrowApp>
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001999 BMCDumpService(CrowApp& app) :
2000 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002001 {
2002 entityPrivileges = {
2003 {boost::beast::http::verb::get, {{"Login"}}},
2004 {boost::beast::http::verb::head, {{"Login"}}},
2005 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2006 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2007 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2008 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2009 }
2010
2011 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002012 void doGet(crow::Response& res, const crow::Request& req,
2013 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002014 {
2015 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2016
2017 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002018 "/redfish/v1/Managers/bmc/LogServices/Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002019 asyncResp->res.jsonValue["@odata.type"] =
2020 "#LogService.v1_1_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002021 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2022 asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
2023 asyncResp->res.jsonValue["Id"] = "Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002024 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
raviteja-bc9bb6862020-02-03 11:53:32 -06002025 asyncResp->res.jsonValue["Entries"] = {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002026 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
2027 asyncResp->res.jsonValue["Actions"] = {
2028 {"#LogService.ClearLog",
2029 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2030 "Actions/LogService.ClearLog"}}},
2031 {"Oem",
2032 {{"#OemLogService.CollectDiagnosticData",
2033 {{"target",
2034 "/redfish/v1/Managers/bmc/LogServices/Dump/"
2035 "Actions/Oem/OemLogService.CollectDiagnosticData"}}}}}};
raviteja-bc9bb6862020-02-03 11:53:32 -06002036 }
2037};
2038
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002039class BMCDumpEntryCollection : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002040{
2041 public:
2042 template <typename CrowApp>
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002043 BMCDumpEntryCollection(CrowApp& app) :
2044 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002045 {
2046 entityPrivileges = {
2047 {boost::beast::http::verb::get, {{"Login"}}},
2048 {boost::beast::http::verb::head, {{"Login"}}},
2049 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2050 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2051 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2052 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2053 }
2054
2055 private:
2056 /**
2057 * Functions triggers appropriate requests on DBus
2058 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002059 void doGet(crow::Response& res, const crow::Request& req,
2060 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002061 {
2062 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2063
2064 asyncResp->res.jsonValue["@odata.type"] =
2065 "#LogEntryCollection.LogEntryCollection";
2066 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002067 "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
2068 asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002069 asyncResp->res.jsonValue["Description"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002070 "Collection of BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002071
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002072 getDumpEntryCollection(asyncResp, "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002073 }
2074};
2075
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002076class BMCDumpEntry : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002077{
2078 public:
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002079 BMCDumpEntry(CrowApp& app) :
2080 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
raviteja-bc9bb6862020-02-03 11:53:32 -06002081 std::string())
2082 {
2083 entityPrivileges = {
2084 {boost::beast::http::verb::get, {{"Login"}}},
2085 {boost::beast::http::verb::head, {{"Login"}}},
2086 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2087 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2088 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2089 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2090 }
2091
2092 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002093 void doGet(crow::Response& res, const crow::Request& req,
2094 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002095 {
2096 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2097 if (params.size() != 1)
2098 {
2099 messages::internalError(asyncResp->res);
2100 return;
2101 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002102 getDumpEntryById(asyncResp, params[0], "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002103 }
2104
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002105 void doDelete(crow::Response& res, const crow::Request& req,
2106 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002107 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002108 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002109 if (params.size() != 1)
2110 {
2111 messages::internalError(asyncResp->res);
2112 return;
2113 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002114 deleteDumpEntry(asyncResp->res, params[0]);
2115 }
2116};
raviteja-bc9bb6862020-02-03 11:53:32 -06002117
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002118class BMCDumpCreate : public Node
2119{
2120 public:
2121 BMCDumpCreate(CrowApp& app) :
2122 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2123 "Actions/Oem/"
2124 "OemLogService.CollectDiagnosticData/")
2125 {
2126 entityPrivileges = {
2127 {boost::beast::http::verb::get, {{"Login"}}},
2128 {boost::beast::http::verb::head, {{"Login"}}},
2129 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2130 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2131 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2132 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2133 }
2134
2135 private:
2136 void doPost(crow::Response& res, const crow::Request& req,
2137 const std::vector<std::string>& params) override
2138 {
2139 createDump(res, req, "BMC");
2140 }
2141};
2142
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002143class BMCDumpClear : public Node
2144{
2145 public:
2146 BMCDumpClear(CrowApp& app) :
2147 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2148 "Actions/"
2149 "LogService.ClearLog/")
2150 {
2151 entityPrivileges = {
2152 {boost::beast::http::verb::get, {{"Login"}}},
2153 {boost::beast::http::verb::head, {{"Login"}}},
2154 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2155 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2156 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2157 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2158 }
2159
2160 private:
2161 void doPost(crow::Response& res, const crow::Request& req,
2162 const std::vector<std::string>& params) override
2163 {
2164 clearDump(res, "xyz.openbmc_project.Dump.Entry.BMC");
2165 }
2166};
2167
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002168class SystemDumpService : public Node
2169{
2170 public:
2171 template <typename CrowApp>
2172 SystemDumpService(CrowApp& app) :
2173 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
2174 {
2175 entityPrivileges = {
2176 {boost::beast::http::verb::get, {{"Login"}}},
2177 {boost::beast::http::verb::head, {{"Login"}}},
2178 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2179 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2180 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2181 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2182 }
raviteja-bc9bb6862020-02-03 11:53:32 -06002183
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002184 private:
2185 void doGet(crow::Response& res, const crow::Request& req,
2186 const std::vector<std::string>& params) override
2187 {
2188 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002189
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002190 asyncResp->res.jsonValue["@odata.id"] =
2191 "/redfish/v1/Systems/system/LogServices/Dump";
2192 asyncResp->res.jsonValue["@odata.type"] =
2193 "#LogService.v1_1_0.LogService";
2194 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2195 asyncResp->res.jsonValue["Description"] = "System Dump LogService";
2196 asyncResp->res.jsonValue["Id"] = "Dump";
2197 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2198 asyncResp->res.jsonValue["Entries"] = {
2199 {"@odata.id",
2200 "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
2201 asyncResp->res.jsonValue["Actions"] = {
2202 {"#LogService.ClearLog",
2203 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2204 "LogService.ClearLog"}}},
2205 {"Oem",
2206 {{"#OemLogService.CollectDiagnosticData",
2207 {{"target",
2208 "/redfish/v1/Systems/system/LogServices/Dump/Actions/Oem/"
2209 "OemLogService.CollectDiagnosticData"}}}}}};
2210 }
2211};
2212
2213class SystemDumpEntryCollection : public Node
2214{
2215 public:
2216 template <typename CrowApp>
2217 SystemDumpEntryCollection(CrowApp& app) :
2218 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
2219 {
2220 entityPrivileges = {
2221 {boost::beast::http::verb::get, {{"Login"}}},
2222 {boost::beast::http::verb::head, {{"Login"}}},
2223 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2224 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2225 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2226 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2227 }
2228
2229 private:
2230 /**
2231 * Functions triggers appropriate requests on DBus
2232 */
2233 void doGet(crow::Response& res, const crow::Request& req,
2234 const std::vector<std::string>& params) override
2235 {
2236 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2237
2238 asyncResp->res.jsonValue["@odata.type"] =
2239 "#LogEntryCollection.LogEntryCollection";
2240 asyncResp->res.jsonValue["@odata.id"] =
2241 "/redfish/v1/Systems/system/LogServices/Dump/Entries";
2242 asyncResp->res.jsonValue["Name"] = "System Dump Entries";
2243 asyncResp->res.jsonValue["Description"] =
2244 "Collection of System Dump Entries";
2245
2246 getDumpEntryCollection(asyncResp, "System");
2247 }
2248};
2249
2250class SystemDumpEntry : public Node
2251{
2252 public:
2253 SystemDumpEntry(CrowApp& app) :
2254 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
2255 std::string())
2256 {
2257 entityPrivileges = {
2258 {boost::beast::http::verb::get, {{"Login"}}},
2259 {boost::beast::http::verb::head, {{"Login"}}},
2260 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2261 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2262 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2263 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2264 }
2265
2266 private:
2267 void doGet(crow::Response& res, const crow::Request& req,
2268 const std::vector<std::string>& params) override
2269 {
2270 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2271 if (params.size() != 1)
2272 {
2273 messages::internalError(asyncResp->res);
2274 return;
2275 }
2276 getDumpEntryById(asyncResp, params[0], "System");
2277 }
2278
2279 void doDelete(crow::Response& res, const crow::Request& req,
2280 const std::vector<std::string>& params) override
2281 {
2282 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2283 if (params.size() != 1)
2284 {
2285 messages::internalError(asyncResp->res);
2286 return;
2287 }
2288 deleteDumpEntry(asyncResp->res, params[0]);
raviteja-bc9bb6862020-02-03 11:53:32 -06002289 }
2290};
2291
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002292class SystemDumpCreate : public Node
2293{
2294 public:
2295 SystemDumpCreate(CrowApp& app) :
2296 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
2297 "Actions/Oem/"
2298 "OemLogService.CollectDiagnosticData/")
2299 {
2300 entityPrivileges = {
2301 {boost::beast::http::verb::get, {{"Login"}}},
2302 {boost::beast::http::verb::head, {{"Login"}}},
2303 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2304 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2305 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2306 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2307 }
2308
2309 private:
2310 void doPost(crow::Response& res, const crow::Request& req,
2311 const std::vector<std::string>& params) override
2312 {
2313 createDump(res, req, "System");
2314 }
2315};
2316
raviteja-b06578432020-02-03 12:50:42 -06002317class SystemDumpEntryDownload : public Node
2318{
2319 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002320 SystemDumpEntryDownload(CrowApp& app) :
raviteja-b06578432020-02-03 12:50:42 -06002321 Node(app,
2322 "/redfish/v1/Systems/system/LogServices/System/Entries/<str>/"
2323 "Actions/"
2324 "LogEntry.DownloadLog/",
2325 std::string())
2326 {
2327 entityPrivileges = {
2328 {boost::beast::http::verb::get, {{"Login"}}},
2329 {boost::beast::http::verb::head, {{"Login"}}},
2330 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2331 }
2332
2333 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002334 void doPost(crow::Response& res, const crow::Request& req,
2335 const std::vector<std::string>& params) override
raviteja-b06578432020-02-03 12:50:42 -06002336 {
2337 if (params.size() != 1)
2338 {
2339 messages::internalError(res);
2340 return;
2341 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002342 const std::string& entryID = params[0];
raviteja-b06578432020-02-03 12:50:42 -06002343 crow::obmc_dump::handleDumpOffloadUrl(req, res, entryID);
2344 }
2345};
2346
raviteja-b013487e2020-03-03 03:20:48 -06002347class SystemDumpClear : public Node
2348{
2349 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002350 SystemDumpClear(CrowApp& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002351 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
raviteja-b013487e2020-03-03 03:20:48 -06002352 "Actions/"
2353 "LogService.ClearLog/")
2354 {
2355 entityPrivileges = {
2356 {boost::beast::http::verb::get, {{"Login"}}},
2357 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002358 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2359 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2360 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b013487e2020-03-03 03:20:48 -06002361 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2362 }
2363
2364 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002365 void doPost(crow::Response& res, const crow::Request& req,
2366 const std::vector<std::string>& params) override
raviteja-b013487e2020-03-03 03:20:48 -06002367 {
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002368 clearDump(res, "xyz.openbmc_project.Dump.Entry.System");
raviteja-b013487e2020-03-03 03:20:48 -06002369 }
2370};
2371
Jason M. Bills424c4172019-03-21 13:50:33 -07002372class CrashdumpService : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002373{
2374 public:
2375 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002376 CrashdumpService(CrowApp& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002377 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002378 {
AppaRao Puli39460282020-04-07 17:03:04 +05302379 // Note: Deviated from redfish privilege registry for GET & HEAD
2380 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002381 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302382 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2383 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002384 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2385 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2386 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2387 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002388 }
2389
2390 private:
2391 /**
2392 * Functions triggers appropriate requests on DBus
2393 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002394 void doGet(crow::Response& res, const crow::Request& req,
2395 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002396 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002397 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002398 // Copy over the static data to include the entries added by SubRoute
Ed Tanous0f74e642018-11-12 15:17:05 -08002399 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002400 "/redfish/v1/Systems/system/LogServices/Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002401 asyncResp->res.jsonValue["@odata.type"] =
2402 "#LogService.v1_1_0.LogService";
Gunnar Mills4f50ae42020-02-06 15:29:57 -06002403 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2404 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2405 asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002406 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2407 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Jason M. Billscd50aa42019-02-12 17:09:02 -08002408 asyncResp->res.jsonValue["Entries"] = {
2409 {"@odata.id",
Jason M. Bills424c4172019-03-21 13:50:33 -07002410 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07002411 asyncResp->res.jsonValue["Actions"] = {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002412 {"#LogService.ClearLog",
2413 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2414 "Actions/LogService.ClearLog"}}},
Ed Tanous1da66f72018-07-27 16:13:37 -07002415 {"Oem",
Jason M. Bills424c4172019-03-21 13:50:33 -07002416 {{"#Crashdump.OnDemand",
2417 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002418 "Actions/Oem/Crashdump.OnDemand"}}},
2419 {"#Crashdump.Telemetry",
2420 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2421 "Actions/Oem/Crashdump.Telemetry"}}}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002422
2423#ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
Jason M. Billse1f26342018-07-18 12:12:00 -07002424 asyncResp->res.jsonValue["Actions"]["Oem"].push_back(
Jason M. Bills424c4172019-03-21 13:50:33 -07002425 {"#Crashdump.SendRawPeci",
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05002426 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2427 "Actions/Oem/Crashdump.SendRawPeci"}}});
Ed Tanous1da66f72018-07-27 16:13:37 -07002428#endif
Ed Tanous1da66f72018-07-27 16:13:37 -07002429 }
2430};
2431
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002432class CrashdumpClear : public Node
2433{
2434 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002435 CrashdumpClear(CrowApp& app) :
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002436 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2437 "LogService.ClearLog/")
2438 {
AppaRao Puli39460282020-04-07 17:03:04 +05302439 // Note: Deviated from redfish privilege registry for GET & HEAD
2440 // method for security reasons.
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002441 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302442 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2443 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002444 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2445 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2446 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2447 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2448 }
2449
2450 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002451 void doPost(crow::Response& res, const crow::Request& req,
2452 const std::vector<std::string>& params) override
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002453 {
2454 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2455
2456 crow::connections::systemBus->async_method_call(
2457 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002458 const std::string& resp) {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002459 if (ec)
2460 {
2461 messages::internalError(asyncResp->res);
2462 return;
2463 }
2464 messages::success(asyncResp->res);
2465 },
2466 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
2467 }
2468};
2469
Jason M. Billse855dd22019-10-08 11:37:48 -07002470static void logCrashdumpEntry(std::shared_ptr<AsyncResp> asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002471 const std::string& logID,
2472 nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002473{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002474 auto getStoredLogCallback =
2475 [asyncResp, logID, &logEntryJson](
2476 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002477 const std::vector<std::pair<std::string, VariantType>>& params) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002478 if (ec)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002479 {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002480 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
2481 if (ec.value() ==
2482 boost::system::linux_error::bad_request_descriptor)
2483 {
2484 messages::resourceNotFound(asyncResp->res, "LogEntry",
2485 logID);
2486 }
2487 else
2488 {
2489 messages::internalError(asyncResp->res);
2490 }
2491 return;
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002492 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002493
Johnathan Mantey043a0532020-03-10 17:15:28 -07002494 std::string timestamp{};
2495 std::string filename{};
2496 std::string logfile{};
2497 ParseCrashdumpParameters(params, filename, timestamp, logfile);
2498
2499 if (filename.empty() || timestamp.empty())
2500 {
2501 messages::resourceMissingAtURI(asyncResp->res, logID);
2502 return;
2503 }
2504
2505 std::string crashdumpURI =
2506 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2507 logID + "/" + filename;
2508 logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
2509 {"@odata.id", "/redfish/v1/Systems/system/"
2510 "LogServices/Crashdump/Entries/" +
2511 logID},
2512 {"Name", "CPU Crashdump"},
2513 {"Id", logID},
2514 {"EntryType", "Oem"},
2515 {"OemRecordFormat", "Crashdump URI"},
2516 {"Message", std::move(crashdumpURI)},
2517 {"Created", std::move(timestamp)}};
2518 };
Jason M. Billse855dd22019-10-08 11:37:48 -07002519 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002520 std::move(getStoredLogCallback), crashdumpObject,
2521 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002522 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Jason M. Billse855dd22019-10-08 11:37:48 -07002523}
2524
Jason M. Bills424c4172019-03-21 13:50:33 -07002525class CrashdumpEntryCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002526{
2527 public:
2528 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002529 CrashdumpEntryCollection(CrowApp& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002530 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002531 {
AppaRao Puli39460282020-04-07 17:03:04 +05302532 // Note: Deviated from redfish privilege registry for GET & HEAD
2533 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002534 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302535 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2536 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002537 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2538 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2539 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2540 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002541 }
2542
2543 private:
2544 /**
2545 * Functions triggers appropriate requests on DBus
2546 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002547 void doGet(crow::Response& res, const crow::Request& req,
2548 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002549 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002550 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002551 // Collections don't include the static data added by SubRoute because
2552 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07002553 auto getLogEntriesCallback = [asyncResp](
2554 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002555 const std::vector<std::string>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002556 if (ec)
2557 {
2558 if (ec.value() !=
2559 boost::system::errc::no_such_file_or_directory)
Ed Tanous1da66f72018-07-27 16:13:37 -07002560 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002561 BMCWEB_LOG_DEBUG << "failed to get entries ec: "
2562 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002563 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002564 return;
Ed Tanous1da66f72018-07-27 16:13:37 -07002565 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002566 }
2567 asyncResp->res.jsonValue["@odata.type"] =
2568 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08002569 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002570 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
Jason M. Bills424c4172019-03-21 13:50:33 -07002571 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002572 asyncResp->res.jsonValue["Description"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002573 "Collection of Crashdump Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002574 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07002575 logEntryArray = nlohmann::json::array();
Jason M. Billse855dd22019-10-08 11:37:48 -07002576 std::vector<std::string> logIDs;
2577 // Get the list of log entries and build up an empty array big
2578 // enough to hold them
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002579 for (const std::string& objpath : resp)
Jason M. Billse1f26342018-07-18 12:12:00 -07002580 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002581 // Get the log ID
Jason M. Billse1f26342018-07-18 12:12:00 -07002582 std::size_t lastPos = objpath.rfind("/");
Jason M. Billse855dd22019-10-08 11:37:48 -07002583 if (lastPos == std::string::npos)
Jason M. Billse1f26342018-07-18 12:12:00 -07002584 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002585 continue;
Jason M. Billse1f26342018-07-18 12:12:00 -07002586 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002587 logIDs.emplace_back(objpath.substr(lastPos + 1));
2588
2589 // Add a space for the log entry to the array
2590 logEntryArray.push_back({});
2591 }
2592 // Now go through and set up async calls to fill in the entries
2593 size_t index = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002594 for (const std::string& logID : logIDs)
Jason M. Billse855dd22019-10-08 11:37:48 -07002595 {
2596 // Add the log entry to the array
2597 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
Jason M. Billse1f26342018-07-18 12:12:00 -07002598 }
2599 asyncResp->res.jsonValue["Members@odata.count"] =
2600 logEntryArray.size();
2601 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002602 crow::connections::systemBus->async_method_call(
2603 std::move(getLogEntriesCallback),
2604 "xyz.openbmc_project.ObjectMapper",
2605 "/xyz/openbmc_project/object_mapper",
2606 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002607 std::array<const char*, 1>{crashdumpInterface});
Ed Tanous1da66f72018-07-27 16:13:37 -07002608 }
2609};
2610
Jason M. Bills424c4172019-03-21 13:50:33 -07002611class CrashdumpEntry : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002612{
2613 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002614 CrashdumpEntry(CrowApp& app) :
Jason M. Billsd53dd412019-02-12 17:16:22 -08002615 Node(app,
Jason M. Bills424c4172019-03-21 13:50:33 -07002616 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
Ed Tanous1da66f72018-07-27 16:13:37 -07002617 std::string())
2618 {
AppaRao Puli39460282020-04-07 17:03:04 +05302619 // Note: Deviated from redfish privilege registry for GET & HEAD
2620 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002621 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302622 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2623 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002624 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2625 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2626 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2627 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002628 }
2629
2630 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002631 void doGet(crow::Response& res, const crow::Request& req,
2632 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002633 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002634 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002635 if (params.size() != 1)
2636 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002637 messages::internalError(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002638 return;
2639 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002640 const std::string& logID = params[0];
Jason M. Billse855dd22019-10-08 11:37:48 -07002641 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2642 }
2643};
2644
2645class CrashdumpFile : public Node
2646{
2647 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002648 CrashdumpFile(CrowApp& app) :
Jason M. Billse855dd22019-10-08 11:37:48 -07002649 Node(app,
2650 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2651 "<str>/",
2652 std::string(), std::string())
2653 {
AppaRao Puli39460282020-04-07 17:03:04 +05302654 // Note: Deviated from redfish privilege registry for GET & HEAD
2655 // method for security reasons.
Jason M. Billse855dd22019-10-08 11:37:48 -07002656 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302657 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2658 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse855dd22019-10-08 11:37:48 -07002659 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2660 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2661 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2662 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2663 }
2664
2665 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002666 void doGet(crow::Response& res, const crow::Request& req,
2667 const std::vector<std::string>& params) override
Jason M. Billse855dd22019-10-08 11:37:48 -07002668 {
2669 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2670 if (params.size() != 2)
2671 {
2672 messages::internalError(asyncResp->res);
2673 return;
2674 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002675 const std::string& logID = params[0];
2676 const std::string& fileName = params[1];
Jason M. Billse855dd22019-10-08 11:37:48 -07002677
Johnathan Mantey043a0532020-03-10 17:15:28 -07002678 auto getStoredLogCallback =
2679 [asyncResp, logID, fileName](
2680 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002681 const std::vector<std::pair<std::string, VariantType>>& resp) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002682 if (ec)
2683 {
2684 BMCWEB_LOG_DEBUG << "failed to get log ec: "
2685 << ec.message();
2686 messages::internalError(asyncResp->res);
2687 return;
2688 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002689
Johnathan Mantey043a0532020-03-10 17:15:28 -07002690 std::string dbusFilename{};
2691 std::string dbusTimestamp{};
2692 std::string dbusFilepath{};
Jason M. Billse855dd22019-10-08 11:37:48 -07002693
Johnathan Mantey043a0532020-03-10 17:15:28 -07002694 ParseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
2695 dbusFilepath);
2696
2697 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2698 dbusFilepath.empty())
2699 {
2700 messages::resourceMissingAtURI(asyncResp->res, fileName);
2701 return;
2702 }
2703
2704 // Verify the file name parameter is correct
2705 if (fileName != dbusFilename)
2706 {
2707 messages::resourceMissingAtURI(asyncResp->res, fileName);
2708 return;
2709 }
2710
2711 if (!std::filesystem::exists(dbusFilepath))
2712 {
2713 messages::resourceMissingAtURI(asyncResp->res, fileName);
2714 return;
2715 }
2716 std::ifstream ifs(dbusFilepath, std::ios::in |
2717 std::ios::binary |
2718 std::ios::ate);
2719 std::ifstream::pos_type fileSize = ifs.tellg();
2720 if (fileSize < 0)
2721 {
2722 messages::generalError(asyncResp->res);
2723 return;
2724 }
2725 ifs.seekg(0, std::ios::beg);
2726
2727 auto crashData = std::make_unique<char[]>(
2728 static_cast<unsigned int>(fileSize));
2729
2730 ifs.read(crashData.get(), static_cast<int>(fileSize));
2731
2732 // The cast to std::string is intentional in order to use the
2733 // assign() that applies move mechanics
2734 asyncResp->res.body().assign(
2735 static_cast<std::string>(crashData.get()));
2736
2737 // Configure this to be a file download when accessed from
2738 // a browser
2739 asyncResp->res.addHeader("Content-Disposition", "attachment");
2740 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002741 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002742 std::move(getStoredLogCallback), crashdumpObject,
2743 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002744 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Ed Tanous1da66f72018-07-27 16:13:37 -07002745 }
2746};
2747
Jason M. Bills424c4172019-03-21 13:50:33 -07002748class OnDemandCrashdump : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002749{
2750 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002751 OnDemandCrashdump(CrowApp& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002752 Node(app,
2753 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2754 "Crashdump.OnDemand/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002755 {
AppaRao Puli39460282020-04-07 17:03:04 +05302756 // Note: Deviated from redfish privilege registry for GET & HEAD
2757 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002758 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302759 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2760 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2761 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2762 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2763 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2764 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002765 }
2766
2767 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002768 void doPost(crow::Response& res, const crow::Request& req,
2769 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002770 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002771 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002772
James Feistfe306722020-03-12 16:32:08 -07002773 auto generateonDemandLogCallback = [asyncResp,
2774 req](const boost::system::error_code
2775 ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002776 const std::string& resp) {
James Feist46229572020-02-19 15:11:58 -08002777 if (ec)
2778 {
2779 if (ec.value() == boost::system::errc::operation_not_supported)
Ed Tanous1da66f72018-07-27 16:13:37 -07002780 {
James Feist46229572020-02-19 15:11:58 -08002781 messages::resourceInStandby(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002782 }
James Feist46229572020-02-19 15:11:58 -08002783 else if (ec.value() ==
2784 boost::system::errc::device_or_resource_busy)
2785 {
2786 messages::serviceTemporarilyUnavailable(asyncResp->res,
2787 "60");
2788 }
2789 else
2790 {
2791 messages::internalError(asyncResp->res);
2792 }
2793 return;
2794 }
2795 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002796 [](boost::system::error_code err, sdbusplus::message::message&,
2797 const std::shared_ptr<task::TaskData>& taskData) {
James Feist66afe4f2020-02-24 13:09:58 -08002798 if (!err)
2799 {
James Feiste5d50062020-05-11 17:29:00 -07002800 taskData->messages.emplace_back(
2801 messages::taskCompletedOK(
2802 std::to_string(taskData->index)));
James Feist831d6b02020-03-12 16:31:30 -07002803 taskData->state = "Completed";
James Feist66afe4f2020-02-24 13:09:58 -08002804 }
James Feist32898ce2020-03-10 16:16:52 -07002805 return task::completed;
James Feist66afe4f2020-02-24 13:09:58 -08002806 },
James Feist46229572020-02-19 15:11:58 -08002807 "type='signal',interface='org.freedesktop.DBus.Properties',"
2808 "member='PropertiesChanged',arg0namespace='com.intel."
2809 "crashdump'");
2810 task->startTimer(std::chrono::minutes(5));
2811 task->populateResp(asyncResp->res);
James Feistfe306722020-03-12 16:32:08 -07002812 task->payload.emplace(req);
James Feist46229572020-02-19 15:11:58 -08002813 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002814 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002815 std::move(generateonDemandLogCallback), crashdumpObject,
2816 crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog");
Ed Tanous1da66f72018-07-27 16:13:37 -07002817 }
2818};
2819
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002820class TelemetryCrashdump : public Node
2821{
2822 public:
2823 TelemetryCrashdump(CrowApp& app) :
2824 Node(app,
2825 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2826 "Crashdump.Telemetry/")
2827 {
2828 // Note: Deviated from redfish privilege registry for GET & HEAD
2829 // method for security reasons.
2830 entityPrivileges = {
2831 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2832 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2833 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2834 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2835 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2836 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2837 }
2838
2839 private:
2840 void doPost(crow::Response& res, const crow::Request& req,
2841 const std::vector<std::string>& params) override
2842 {
2843 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2844
2845 auto generateTelemetryLogCallback = [asyncResp, req](
2846 const boost::system::error_code
2847 ec,
2848 const std::string& resp) {
2849 if (ec)
2850 {
2851 if (ec.value() == boost::system::errc::operation_not_supported)
2852 {
2853 messages::resourceInStandby(asyncResp->res);
2854 }
2855 else if (ec.value() ==
2856 boost::system::errc::device_or_resource_busy)
2857 {
2858 messages::serviceTemporarilyUnavailable(asyncResp->res,
2859 "60");
2860 }
2861 else
2862 {
2863 messages::internalError(asyncResp->res);
2864 }
2865 return;
2866 }
2867 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
2868 [](boost::system::error_code err, sdbusplus::message::message&,
2869 const std::shared_ptr<task::TaskData>& taskData) {
2870 if (!err)
2871 {
2872 taskData->messages.emplace_back(
2873 messages::taskCompletedOK(
2874 std::to_string(taskData->index)));
2875 taskData->state = "Completed";
2876 }
2877 return task::completed;
2878 },
2879 "type='signal',interface='org.freedesktop.DBus.Properties',"
2880 "member='PropertiesChanged',arg0namespace='com.intel."
2881 "crashdump'");
2882 task->startTimer(std::chrono::minutes(5));
2883 task->populateResp(asyncResp->res);
2884 task->payload.emplace(req);
2885 };
2886 crow::connections::systemBus->async_method_call(
2887 std::move(generateTelemetryLogCallback), crashdumpObject,
2888 crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog");
2889 }
2890};
2891
Jason M. Billse1f26342018-07-18 12:12:00 -07002892class SendRawPECI : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002893{
2894 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002895 SendRawPECI(CrowApp& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002896 Node(app,
2897 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2898 "Crashdump.SendRawPeci/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002899 {
AppaRao Puli39460282020-04-07 17:03:04 +05302900 // Note: Deviated from redfish privilege registry for GET & HEAD
2901 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002902 entityPrivileges = {
2903 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2904 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2905 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2906 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2907 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2908 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2909 }
2910
2911 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002912 void doPost(crow::Response& res, const crow::Request& req,
2913 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002914 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002915 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002916 std::vector<std::vector<uint8_t>> peciCommands;
Ed Tanousb1556422018-10-16 14:09:17 -07002917
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002918 nlohmann::json reqJson =
2919 nlohmann::json::parse(req.body, nullptr, false);
2920 if (reqJson.find("PECICommands") != reqJson.end())
2921 {
2922 if (!json_util::readJson(req, res, "PECICommands", peciCommands))
2923 {
2924 return;
2925 }
2926 uint32_t idx = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002927 for (auto const& cmd : peciCommands)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002928 {
2929 if (cmd.size() < 3)
2930 {
2931 std::string s("[");
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002932 for (auto const& val : cmd)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002933 {
2934 if (val != *cmd.begin())
2935 {
2936 s += ",";
2937 }
2938 s += std::to_string(val);
2939 }
2940 s += "]";
2941 messages::actionParameterValueFormatError(
2942 res, s, "PECICommands[" + std::to_string(idx) + "]",
2943 "SendRawPeci");
2944 return;
2945 }
2946 idx++;
2947 }
2948 }
2949 else
2950 {
2951 /* This interface is deprecated */
2952 uint8_t clientAddress = 0;
2953 uint8_t readLength = 0;
2954 std::vector<uint8_t> peciCommand;
2955 if (!json_util::readJson(req, res, "ClientAddress", clientAddress,
2956 "ReadLength", readLength, "PECICommand",
2957 peciCommand))
2958 {
2959 return;
2960 }
2961 peciCommands.push_back({clientAddress, 0, readLength});
2962 peciCommands[0].insert(peciCommands[0].end(), peciCommand.begin(),
2963 peciCommand.end());
2964 }
Ed Tanous1da66f72018-07-27 16:13:37 -07002965 // Callback to return the Raw PECI response
Jason M. Billse1f26342018-07-18 12:12:00 -07002966 auto sendRawPECICallback =
2967 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002968 const std::vector<std::vector<uint8_t>>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002969 if (ec)
2970 {
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002971 BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: "
Jason M. Billse1f26342018-07-18 12:12:00 -07002972 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002973 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002974 return;
2975 }
2976 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
2977 {"PECIResponse", resp}};
2978 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002979 // Call the SendRawPECI command with the provided data
2980 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002981 std::move(sendRawPECICallback), crashdumpObject, crashdumpPath,
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002982 crashdumpRawPECIInterface, "SendRawPeci", peciCommands);
Ed Tanous1da66f72018-07-27 16:13:37 -07002983 }
2984};
2985
Andrew Geisslercb92c032018-08-17 07:56:14 -07002986/**
2987 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
2988 */
2989class DBusLogServiceActionsClear : public Node
2990{
2991 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002992 DBusLogServiceActionsClear(CrowApp& app) :
Andrew Geisslercb92c032018-08-17 07:56:14 -07002993 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
Gunnar Mills7af91512020-04-14 22:16:57 -05002994 "LogService.ClearLog/")
Andrew Geisslercb92c032018-08-17 07:56:14 -07002995 {
2996 entityPrivileges = {
2997 {boost::beast::http::verb::get, {{"Login"}}},
2998 {boost::beast::http::verb::head, {{"Login"}}},
2999 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3000 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3001 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3002 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3003 }
3004
3005 private:
3006 /**
3007 * Function handles POST method request.
3008 * The Clear Log actions does not require any parameter.The action deletes
3009 * all entries found in the Entries collection for this Log Service.
3010 */
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003011 void doPost(crow::Response& res, const crow::Request& req,
3012 const std::vector<std::string>& params) override
Andrew Geisslercb92c032018-08-17 07:56:14 -07003013 {
3014 BMCWEB_LOG_DEBUG << "Do delete all entries.";
3015
3016 auto asyncResp = std::make_shared<AsyncResp>(res);
3017 // Process response from Logging service.
3018 auto resp_handler = [asyncResp](const boost::system::error_code ec) {
3019 BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
3020 if (ec)
3021 {
3022 // TODO Handle for specific error code
3023 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
3024 asyncResp->res.result(
3025 boost::beast::http::status::internal_server_error);
3026 return;
3027 }
3028
3029 asyncResp->res.result(boost::beast::http::status::no_content);
3030 };
3031
3032 // Make call to Logging service to request Clear Log
3033 crow::connections::systemBus->async_method_call(
3034 resp_handler, "xyz.openbmc_project.Logging",
3035 "/xyz/openbmc_project/logging",
3036 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3037 }
3038};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003039
3040/****************************************************
3041 * Redfish PostCode interfaces
3042 * using DBUS interface: getPostCodesTS
3043 ******************************************************/
3044class PostCodesLogService : public Node
3045{
3046 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003047 PostCodesLogService(CrowApp& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003048 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
3049 {
3050 entityPrivileges = {
3051 {boost::beast::http::verb::get, {{"Login"}}},
3052 {boost::beast::http::verb::head, {{"Login"}}},
3053 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3054 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3055 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3056 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3057 }
3058
3059 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003060 void doGet(crow::Response& res, const crow::Request& req,
3061 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003062 {
3063 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3064
3065 asyncResp->res.jsonValue = {
3066 {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
3067 {"@odata.type", "#LogService.v1_1_0.LogService"},
3068 {"@odata.context", "/redfish/v1/$metadata#LogService.LogService"},
3069 {"Name", "POST Code Log Service"},
3070 {"Description", "POST Code Log Service"},
3071 {"Id", "BIOS POST Code Log"},
3072 {"OverWritePolicy", "WrapsWhenFull"},
3073 {"Entries",
3074 {{"@odata.id",
3075 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
3076 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
3077 {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
3078 "Actions/LogService.ClearLog"}};
3079 }
3080};
3081
3082class PostCodesClear : public Node
3083{
3084 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003085 PostCodesClear(CrowApp& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003086 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3087 "LogService.ClearLog/")
3088 {
3089 entityPrivileges = {
3090 {boost::beast::http::verb::get, {{"Login"}}},
3091 {boost::beast::http::verb::head, {{"Login"}}},
AppaRao Puli39460282020-04-07 17:03:04 +05303092 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
3093 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
3094 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
3095 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003096 }
3097
3098 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003099 void doPost(crow::Response& res, const crow::Request& req,
3100 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003101 {
3102 BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3103
3104 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3105 // Make call to post-code service to request clear all
3106 crow::connections::systemBus->async_method_call(
3107 [asyncResp](const boost::system::error_code ec) {
3108 if (ec)
3109 {
3110 // TODO Handle for specific error code
3111 BMCWEB_LOG_ERROR
3112 << "doClearPostCodes resp_handler got error " << ec;
3113 asyncResp->res.result(
3114 boost::beast::http::status::internal_server_error);
3115 messages::internalError(asyncResp->res);
3116 return;
3117 }
3118 },
3119 "xyz.openbmc_project.State.Boot.PostCode",
3120 "/xyz/openbmc_project/State/Boot/PostCode",
3121 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3122 }
3123};
3124
3125static void fillPostCodeEntry(
3126 std::shared_ptr<AsyncResp> aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003127 const boost::container::flat_map<uint64_t, uint64_t>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003128 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3129 const uint64_t skip = 0, const uint64_t top = 0)
3130{
3131 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003132 const message_registries::Message* message =
ZhikuiRena3316fc2020-01-29 14:58:08 -08003133 message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003134
3135 uint64_t currentCodeIndex = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003136 nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003137
3138 uint64_t firstCodeTimeUs = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003139 for (const std::pair<uint64_t, uint64_t>& code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003140 {
3141 currentCodeIndex++;
3142 std::string postcodeEntryID =
3143 "B" + std::to_string(bootIndex) + "-" +
3144 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3145
3146 uint64_t usecSinceEpoch = code.first;
3147 uint64_t usTimeOffset = 0;
3148
3149 if (1 == currentCodeIndex)
3150 { // already incremented
3151 firstCodeTimeUs = code.first;
3152 }
3153 else
3154 {
3155 usTimeOffset = code.first - firstCodeTimeUs;
3156 }
3157
3158 // skip if no specific codeIndex is specified and currentCodeIndex does
3159 // not fall between top and skip
3160 if ((codeIndex == 0) &&
3161 (currentCodeIndex <= skip || currentCodeIndex > top))
3162 {
3163 continue;
3164 }
3165
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003166 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003167 // currentIndex
3168 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3169 {
3170 // This is done for simplicity. 1st entry is needed to calculate
3171 // time offset. To improve efficiency, one can get to the entry
3172 // directly (possibly with flatmap's nth method)
3173 continue;
3174 }
3175
3176 // currentCodeIndex is within top and skip or equal to specified code
3177 // index
3178
3179 // Get the Created time from the timestamp
3180 std::string entryTimeStr;
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003181 entryTimeStr = crow::utility::getDateTime(
3182 static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003183
3184 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3185 std::ostringstream hexCode;
3186 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
3187 << code.second;
3188 std::ostringstream timeOffsetStr;
3189 // Set Fixed -Point Notation
3190 timeOffsetStr << std::fixed;
3191 // Set precision to 4 digits
3192 timeOffsetStr << std::setprecision(4);
3193 // Add double to stream
3194 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3195 std::vector<std::string> messageArgs = {
3196 std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3197
3198 // Get MessageArgs template from message registry
3199 std::string msg;
3200 if (message != nullptr)
3201 {
3202 msg = message->message;
3203
3204 // fill in this post code value
3205 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003206 for (const std::string& messageArg : messageArgs)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003207 {
3208 std::string argStr = "%" + std::to_string(++i);
3209 size_t argPos = msg.find(argStr);
3210 if (argPos != std::string::npos)
3211 {
3212 msg.replace(argPos, argStr.length(), messageArg);
3213 }
3214 }
3215 }
3216
Tim Leed4342a92020-04-27 11:47:58 +08003217 // Get Severity template from message registry
3218 std::string severity;
3219 if (message != nullptr)
3220 {
3221 severity = message->severity;
3222 }
3223
ZhikuiRena3316fc2020-01-29 14:58:08 -08003224 // add to AsyncResp
3225 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003226 nlohmann::json& bmcLogEntry = logEntryArray.back();
ZhikuiRena3316fc2020-01-29 14:58:08 -08003227 bmcLogEntry = {
3228 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3229 {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"},
3230 {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3231 "PostCodes/Entries/" +
3232 postcodeEntryID},
3233 {"Name", "POST Code Log Entry"},
3234 {"Id", postcodeEntryID},
3235 {"Message", std::move(msg)},
3236 {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"},
3237 {"MessageArgs", std::move(messageArgs)},
3238 {"EntryType", "Event"},
3239 {"Severity", std::move(severity)},
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003240 {"Created", entryTimeStr}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003241 }
3242}
3243
3244static void getPostCodeForEntry(std::shared_ptr<AsyncResp> aResp,
3245 const uint16_t bootIndex,
3246 const uint64_t codeIndex)
3247{
3248 crow::connections::systemBus->async_method_call(
3249 [aResp, bootIndex, codeIndex](
3250 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003251 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003252 if (ec)
3253 {
3254 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3255 messages::internalError(aResp->res);
3256 return;
3257 }
3258
3259 // skip the empty postcode boots
3260 if (postcode.empty())
3261 {
3262 return;
3263 }
3264
3265 fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3266
3267 aResp->res.jsonValue["Members@odata.count"] =
3268 aResp->res.jsonValue["Members"].size();
3269 },
3270 "xyz.openbmc_project.State.Boot.PostCode",
3271 "/xyz/openbmc_project/State/Boot/PostCode",
3272 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3273 bootIndex);
3274}
3275
3276static void getPostCodeForBoot(std::shared_ptr<AsyncResp> aResp,
3277 const uint16_t bootIndex,
3278 const uint16_t bootCount,
3279 const uint64_t entryCount, const uint64_t skip,
3280 const uint64_t top)
3281{
3282 crow::connections::systemBus->async_method_call(
3283 [aResp, bootIndex, bootCount, entryCount, skip,
3284 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003285 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003286 if (ec)
3287 {
3288 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3289 messages::internalError(aResp->res);
3290 return;
3291 }
3292
3293 uint64_t endCount = entryCount;
3294 if (!postcode.empty())
3295 {
3296 endCount = entryCount + postcode.size();
3297
3298 if ((skip < endCount) && ((top + skip) > entryCount))
3299 {
3300 uint64_t thisBootSkip =
3301 std::max(skip, entryCount) - entryCount;
3302 uint64_t thisBootTop =
3303 std::min(top + skip, endCount) - entryCount;
3304
3305 fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3306 thisBootSkip, thisBootTop);
3307 }
3308 aResp->res.jsonValue["Members@odata.count"] = endCount;
3309 }
3310
3311 // continue to previous bootIndex
3312 if (bootIndex < bootCount)
3313 {
3314 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3315 bootCount, endCount, skip, top);
3316 }
3317 else
3318 {
3319 aResp->res.jsonValue["Members@odata.nextLink"] =
3320 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3321 "Entries?$skip=" +
3322 std::to_string(skip + top);
3323 }
3324 },
3325 "xyz.openbmc_project.State.Boot.PostCode",
3326 "/xyz/openbmc_project/State/Boot/PostCode",
3327 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3328 bootIndex);
3329}
3330
3331static void getCurrentBootNumber(std::shared_ptr<AsyncResp> aResp,
3332 const uint64_t skip, const uint64_t top)
3333{
3334 uint64_t entryCount = 0;
3335 crow::connections::systemBus->async_method_call(
3336 [aResp, entryCount, skip,
3337 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003338 const std::variant<uint16_t>& bootCount) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003339 if (ec)
3340 {
3341 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3342 messages::internalError(aResp->res);
3343 return;
3344 }
3345 auto pVal = std::get_if<uint16_t>(&bootCount);
3346 if (pVal)
3347 {
3348 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3349 }
3350 else
3351 {
3352 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3353 }
3354 },
3355 "xyz.openbmc_project.State.Boot.PostCode",
3356 "/xyz/openbmc_project/State/Boot/PostCode",
3357 "org.freedesktop.DBus.Properties", "Get",
3358 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3359}
3360
3361class PostCodesEntryCollection : public Node
3362{
3363 public:
3364 template <typename CrowApp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003365 PostCodesEntryCollection(CrowApp& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003366 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3367 {
3368 entityPrivileges = {
3369 {boost::beast::http::verb::get, {{"Login"}}},
3370 {boost::beast::http::verb::head, {{"Login"}}},
3371 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3372 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3373 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3374 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3375 }
3376
3377 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003378 void doGet(crow::Response& res, const crow::Request& req,
3379 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003380 {
3381 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3382
3383 asyncResp->res.jsonValue["@odata.type"] =
3384 "#LogEntryCollection.LogEntryCollection";
3385 asyncResp->res.jsonValue["@odata.context"] =
3386 "/redfish/v1/"
3387 "$metadata#LogEntryCollection.LogEntryCollection";
3388 asyncResp->res.jsonValue["@odata.id"] =
3389 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3390 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3391 asyncResp->res.jsonValue["Description"] =
3392 "Collection of POST Code Log Entries";
3393 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3394 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3395
3396 uint64_t skip = 0;
3397 uint64_t top = maxEntriesPerPage; // Show max entries by default
3398 if (!getSkipParam(asyncResp->res, req, skip))
3399 {
3400 return;
3401 }
3402 if (!getTopParam(asyncResp->res, req, top))
3403 {
3404 return;
3405 }
3406 getCurrentBootNumber(asyncResp, skip, top);
3407 }
3408};
3409
3410class PostCodesEntry : public Node
3411{
3412 public:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003413 PostCodesEntry(CrowApp& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003414 Node(app,
3415 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3416 std::string())
3417 {
3418 entityPrivileges = {
3419 {boost::beast::http::verb::get, {{"Login"}}},
3420 {boost::beast::http::verb::head, {{"Login"}}},
3421 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3422 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3423 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3424 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3425 }
3426
3427 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003428 void doGet(crow::Response& res, const crow::Request& req,
3429 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003430 {
3431 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3432 if (params.size() != 1)
3433 {
3434 messages::internalError(asyncResp->res);
3435 return;
3436 }
3437
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003438 const std::string& targetID = params[0];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003439
3440 size_t bootPos = targetID.find('B');
3441 if (bootPos == std::string::npos)
3442 {
3443 // Requested ID was not found
3444 messages::resourceMissingAtURI(asyncResp->res, targetID);
3445 return;
3446 }
3447 std::string_view bootIndexStr(targetID);
3448 bootIndexStr.remove_prefix(bootPos + 1);
3449 uint16_t bootIndex = 0;
3450 uint64_t codeIndex = 0;
3451 size_t dashPos = bootIndexStr.find('-');
3452
3453 if (dashPos == std::string::npos)
3454 {
3455 return;
3456 }
3457 std::string_view codeIndexStr(bootIndexStr);
3458 bootIndexStr.remove_suffix(dashPos);
3459 codeIndexStr.remove_prefix(dashPos + 1);
3460
3461 bootIndex = static_cast<uint16_t>(
3462 strtoul(std::string(bootIndexStr).c_str(), NULL, 0));
3463 codeIndex = strtoul(std::string(codeIndexStr).c_str(), NULL, 0);
3464 if (bootIndex == 0 || codeIndex == 0)
3465 {
3466 BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3467 << params[0];
3468 }
3469
3470 asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
3471 asyncResp->res.jsonValue["@odata.context"] =
3472 "/redfish/v1/$metadata#LogEntry.LogEntry";
3473 asyncResp->res.jsonValue["@odata.id"] =
3474 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3475 "Entries";
3476 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3477 asyncResp->res.jsonValue["Description"] =
3478 "Collection of POST Code Log Entries";
3479 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3480 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3481
3482 getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3483 }
3484};
3485
Ed Tanous1da66f72018-07-27 16:13:37 -07003486} // namespace redfish