blob: 4975a37928b0e22f020d388163b25395fbd0f537 [file] [log] [blame]
Ed Tanous1da66f72018-07-27 16:13:37 -07001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
18#include "node.hpp"
Jason M. Bills4851d452019-03-28 11:27:48 -070019#include "registries.hpp"
20#include "registries/base_message_registry.hpp"
21#include "registries/openbmc_message_registry.hpp"
James Feist46229572020-02-19 15:11:58 -080022#include "task.hpp"
Ed Tanous1da66f72018-07-27 16:13:37 -070023
Jason M. Billse1f26342018-07-18 12:12:00 -070024#include <systemd/sd-journal.h>
25
Jason M. Bills4851d452019-03-28 11:27:48 -070026#include <boost/algorithm/string/split.hpp>
27#include <boost/beast/core/span.hpp>
Ed Tanous1da66f72018-07-27 16:13:37 -070028#include <boost/container/flat_map.hpp>
Jason M. Bills1ddcf012019-11-26 14:59:21 -080029#include <boost/system/linux_error.hpp>
Andrew Geisslercb92c032018-08-17 07:56:14 -070030#include <error_messages.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050031
James Feist4418c7f2019-04-15 11:09:15 -070032#include <filesystem>
Jason M. Billscd225da2019-05-08 15:31:57 -070033#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080034#include <variant>
Ed Tanous1da66f72018-07-27 16:13:37 -070035
36namespace redfish
37{
38
Gunnar Mills1214b7e2020-06-04 10:11:30 -050039constexpr char const* crashdumpObject = "com.intel.crashdump";
40constexpr char const* crashdumpPath = "/com/intel/crashdump";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050041constexpr char const* crashdumpInterface = "com.intel.crashdump";
42constexpr char const* deleteAllInterface =
Jason M. Bills5b61b5e2019-10-16 10:59:02 -070043 "xyz.openbmc_project.Collection.DeleteAll";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050044constexpr char const* crashdumpOnDemandInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070045 "com.intel.crashdump.OnDemand";
Gunnar Mills1214b7e2020-06-04 10:11:30 -050046constexpr char const* crashdumpRawPECIInterface =
Jason M. Bills424c4172019-03-21 13:50:33 -070047 "com.intel.crashdump.SendRawPeci";
Kenny L. Ku6eda7682020-06-19 09:48:36 -070048constexpr char const* crashdumpTelemetryInterface =
49 "com.intel.crashdump.Telemetry";
Ed Tanous1da66f72018-07-27 16:13:37 -070050
Jason M. Bills4851d452019-03-28 11:27:48 -070051namespace message_registries
52{
Gunnar Mills1214b7e2020-06-04 10:11:30 -050053static const Message* getMessageFromRegistry(
54 const std::string& messageKey,
Jason M. Bills4851d452019-03-28 11:27:48 -070055 const boost::beast::span<const MessageEntry> registry)
56{
57 boost::beast::span<const MessageEntry>::const_iterator messageIt =
58 std::find_if(registry.cbegin(), registry.cend(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -050059 [&messageKey](const MessageEntry& messageEntry) {
Jason M. Bills4851d452019-03-28 11:27:48 -070060 return !std::strcmp(messageEntry.first,
61 messageKey.c_str());
62 });
63 if (messageIt != registry.cend())
64 {
65 return &messageIt->second;
66 }
67
68 return nullptr;
69}
70
Gunnar Mills1214b7e2020-06-04 10:11:30 -050071static const Message* getMessage(const std::string_view& messageID)
Jason M. Bills4851d452019-03-28 11:27:48 -070072{
73 // Redfish MessageIds are in the form
74 // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
75 // the right Message
76 std::vector<std::string> fields;
77 fields.reserve(4);
78 boost::split(fields, messageID, boost::is_any_of("."));
Gunnar Mills1214b7e2020-06-04 10:11:30 -050079 std::string& registryName = fields[0];
80 std::string& messageKey = fields[3];
Jason M. Bills4851d452019-03-28 11:27:48 -070081
82 // Find the right registry and check it for the MessageKey
83 if (std::string(base::header.registryPrefix) == registryName)
84 {
85 return getMessageFromRegistry(
86 messageKey, boost::beast::span<const MessageEntry>(base::registry));
87 }
88 if (std::string(openbmc::header.registryPrefix) == registryName)
89 {
90 return getMessageFromRegistry(
91 messageKey,
92 boost::beast::span<const MessageEntry>(openbmc::registry));
93 }
94 return nullptr;
95}
96} // namespace message_registries
97
James Feistf6150402019-01-08 10:36:20 -080098namespace fs = std::filesystem;
Ed Tanous1da66f72018-07-27 16:13:37 -070099
Andrew Geisslercb92c032018-08-17 07:56:14 -0700100using GetManagedPropertyType = boost::container::flat_map<
Patrick Williams19bd78d2020-05-13 17:38:24 -0500101 std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t,
102 int32_t, uint32_t, int64_t, uint64_t, double>>;
Andrew Geisslercb92c032018-08-17 07:56:14 -0700103
104using GetManagedObjectsType = boost::container::flat_map<
105 sdbusplus::message::object_path,
106 boost::container::flat_map<std::string, GetManagedPropertyType>>;
107
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500108inline std::string translateSeverityDbusToRedfish(const std::string& s)
Andrew Geisslercb92c032018-08-17 07:56:14 -0700109{
Ed Tanousd4d25792020-09-29 15:15:03 -0700110 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Alert") ||
111 (s == "xyz.openbmc_project.Logging.Entry.Level.Critical") ||
112 (s == "xyz.openbmc_project.Logging.Entry.Level.Emergency") ||
113 (s == "xyz.openbmc_project.Logging.Entry.Level.Error"))
Andrew Geisslercb92c032018-08-17 07:56:14 -0700114 {
115 return "Critical";
116 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700117 if ((s == "xyz.openbmc_project.Logging.Entry.Level.Debug") ||
118 (s == "xyz.openbmc_project.Logging.Entry.Level.Informational") ||
119 (s == "xyz.openbmc_project.Logging.Entry.Level.Notice"))
Andrew Geisslercb92c032018-08-17 07:56:14 -0700120 {
121 return "OK";
122 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700123 if (s == "xyz.openbmc_project.Logging.Entry.Level.Warning")
Andrew Geisslercb92c032018-08-17 07:56:14 -0700124 {
125 return "Warning";
126 }
127 return "";
128}
129
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500130static int getJournalMetadata(sd_journal* journal,
131 const std::string_view& field,
132 std::string_view& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700133{
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500134 const char* data = nullptr;
Jason M. Bills16428a12018-11-02 12:42:29 -0700135 size_t length = 0;
136 int ret = 0;
137 // Get the metadata from the requested field of the journal entry
Ed Tanous271584a2019-07-09 16:24:22 -0700138 ret = sd_journal_get_data(journal, field.data(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500139 reinterpret_cast<const void**>(&data), &length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700140 if (ret < 0)
141 {
142 return ret;
143 }
Ed Tanous39e77502019-03-04 17:35:53 -0800144 contents = std::string_view(data, length);
Jason M. Bills16428a12018-11-02 12:42:29 -0700145 // Only use the content after the "=" character.
Ed Tanous81ce6092020-12-17 16:54:55 +0000146 contents.remove_prefix(std::min(contents.find('=') + 1, contents.size()));
Jason M. Bills16428a12018-11-02 12:42:29 -0700147 return ret;
148}
149
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500150static int getJournalMetadata(sd_journal* journal,
151 const std::string_view& field, const int& base,
152 long int& contents)
Jason M. Bills16428a12018-11-02 12:42:29 -0700153{
154 int ret = 0;
Ed Tanous39e77502019-03-04 17:35:53 -0800155 std::string_view metadata;
Jason M. Bills16428a12018-11-02 12:42:29 -0700156 // Get the metadata from the requested field of the journal entry
157 ret = getJournalMetadata(journal, field, metadata);
158 if (ret < 0)
159 {
160 return ret;
161 }
Ed Tanousb01bf292019-03-25 19:25:26 +0000162 contents = strtol(metadata.data(), nullptr, base);
Jason M. Bills16428a12018-11-02 12:42:29 -0700163 return ret;
164}
165
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500166static bool getEntryTimestamp(sd_journal* journal, std::string& entryTimestamp)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800167{
168 int ret = 0;
169 uint64_t timestamp = 0;
170 ret = sd_journal_get_realtime_usec(journal, &timestamp);
171 if (ret < 0)
172 {
173 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
174 << strerror(-ret);
175 return false;
176 }
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -0500177 entryTimestamp = crow::utility::getDateTime(
178 static_cast<std::time_t>(timestamp / 1000 / 1000));
179 return true;
ZhikuiRena3316fc2020-01-29 14:58:08 -0800180}
181
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500182static bool getSkipParam(crow::Response& res, const crow::Request& req,
183 uint64_t& skip)
Jason M. Bills16428a12018-11-02 12:42:29 -0700184{
James Feist5a7e8772020-07-22 09:08:38 -0700185 boost::urls::url_view::params_type::iterator it =
186 req.urlParams.find("$skip");
187 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700188 {
James Feist5a7e8772020-07-22 09:08:38 -0700189 std::string skipParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500190 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700191 skip = std::strtoul(skipParam.c_str(), &ptr, 10);
192 if (skipParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700193 {
194
195 messages::queryParameterValueTypeError(res, std::string(skipParam),
196 "$skip");
197 return false;
198 }
Jason M. Bills16428a12018-11-02 12:42:29 -0700199 }
200 return true;
201}
202
Ed Tanous271584a2019-07-09 16:24:22 -0700203static constexpr const uint64_t maxEntriesPerPage = 1000;
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500204static bool getTopParam(crow::Response& res, const crow::Request& req,
205 uint64_t& top)
Jason M. Bills16428a12018-11-02 12:42:29 -0700206{
James Feist5a7e8772020-07-22 09:08:38 -0700207 boost::urls::url_view::params_type::iterator it =
208 req.urlParams.find("$top");
209 if (it != req.urlParams.end())
Jason M. Bills16428a12018-11-02 12:42:29 -0700210 {
James Feist5a7e8772020-07-22 09:08:38 -0700211 std::string topParam = it->value();
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500212 char* ptr = nullptr;
James Feist5a7e8772020-07-22 09:08:38 -0700213 top = std::strtoul(topParam.c_str(), &ptr, 10);
214 if (topParam.empty() || *ptr != '\0')
Jason M. Bills16428a12018-11-02 12:42:29 -0700215 {
216 messages::queryParameterValueTypeError(res, std::string(topParam),
217 "$top");
218 return false;
219 }
Ed Tanous271584a2019-07-09 16:24:22 -0700220 if (top < 1U || top > maxEntriesPerPage)
Jason M. Bills16428a12018-11-02 12:42:29 -0700221 {
222
223 messages::queryParameterOutOfRange(
224 res, std::to_string(top), "$top",
225 "1-" + std::to_string(maxEntriesPerPage));
226 return false;
227 }
228 }
229 return true;
230}
231
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500232static bool getUniqueEntryID(sd_journal* journal, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700233 const bool firstEntry = true)
Jason M. Bills16428a12018-11-02 12:42:29 -0700234{
235 int ret = 0;
236 static uint64_t prevTs = 0;
237 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700238 if (firstEntry)
239 {
240 prevTs = 0;
241 }
242
Jason M. Bills16428a12018-11-02 12:42:29 -0700243 // Get the entry timestamp
244 uint64_t curTs = 0;
245 ret = sd_journal_get_realtime_usec(journal, &curTs);
246 if (ret < 0)
247 {
248 BMCWEB_LOG_ERROR << "Failed to read entry timestamp: "
249 << strerror(-ret);
250 return false;
251 }
252 // If the timestamp isn't unique, increment the index
253 if (curTs == prevTs)
254 {
255 index++;
256 }
257 else
258 {
259 // Otherwise, reset it
260 index = 0;
261 }
262 // Save the timestamp
263 prevTs = curTs;
264
265 entryID = std::to_string(curTs);
266 if (index > 0)
267 {
268 entryID += "_" + std::to_string(index);
269 }
270 return true;
271}
272
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500273static bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
Jason M. Billse85d6b12019-07-29 17:01:15 -0700274 const bool firstEntry = true)
Jason M. Bills95820182019-04-22 16:25:34 -0700275{
Ed Tanous271584a2019-07-09 16:24:22 -0700276 static time_t prevTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700277 static int index = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -0700278 if (firstEntry)
279 {
280 prevTs = 0;
281 }
282
Jason M. Bills95820182019-04-22 16:25:34 -0700283 // Get the entry timestamp
Ed Tanous271584a2019-07-09 16:24:22 -0700284 std::time_t curTs = 0;
Jason M. Bills95820182019-04-22 16:25:34 -0700285 std::tm timeStruct = {};
286 std::istringstream entryStream(logEntry);
287 if (entryStream >> std::get_time(&timeStruct, "%Y-%m-%dT%H:%M:%S"))
288 {
289 curTs = std::mktime(&timeStruct);
290 }
291 // If the timestamp isn't unique, increment the index
292 if (curTs == prevTs)
293 {
294 index++;
295 }
296 else
297 {
298 // Otherwise, reset it
299 index = 0;
300 }
301 // Save the timestamp
302 prevTs = curTs;
303
304 entryID = std::to_string(curTs);
305 if (index > 0)
306 {
307 entryID += "_" + std::to_string(index);
308 }
309 return true;
310}
311
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500312static bool getTimestampFromID(crow::Response& res, const std::string& entryID,
313 uint64_t& timestamp, uint64_t& index)
Jason M. Bills16428a12018-11-02 12:42:29 -0700314{
315 if (entryID.empty())
316 {
317 return false;
318 }
319 // Convert the unique ID back to a timestamp to find the entry
Ed Tanous39e77502019-03-04 17:35:53 -0800320 std::string_view tsStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700321
Ed Tanous81ce6092020-12-17 16:54:55 +0000322 auto underscorePos = tsStr.find('_');
Jason M. Bills16428a12018-11-02 12:42:29 -0700323 if (underscorePos != tsStr.npos)
324 {
325 // Timestamp has an index
326 tsStr.remove_suffix(tsStr.size() - underscorePos);
Ed Tanous39e77502019-03-04 17:35:53 -0800327 std::string_view indexStr(entryID);
Jason M. Bills16428a12018-11-02 12:42:29 -0700328 indexStr.remove_prefix(underscorePos + 1);
329 std::size_t pos;
330 try
331 {
Ed Tanous39e77502019-03-04 17:35:53 -0800332 index = std::stoul(std::string(indexStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700333 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500334 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700335 {
336 messages::resourceMissingAtURI(res, entryID);
337 return false;
338 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500339 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700340 {
341 messages::resourceMissingAtURI(res, entryID);
342 return false;
343 }
344 if (pos != indexStr.size())
345 {
346 messages::resourceMissingAtURI(res, entryID);
347 return false;
348 }
349 }
350 // Timestamp has no index
351 std::size_t pos;
352 try
353 {
Ed Tanous39e77502019-03-04 17:35:53 -0800354 timestamp = std::stoull(std::string(tsStr), &pos);
Jason M. Bills16428a12018-11-02 12:42:29 -0700355 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500356 catch (std::invalid_argument&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700357 {
358 messages::resourceMissingAtURI(res, entryID);
359 return false;
360 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500361 catch (std::out_of_range&)
Jason M. Bills16428a12018-11-02 12:42:29 -0700362 {
363 messages::resourceMissingAtURI(res, entryID);
364 return false;
365 }
366 if (pos != tsStr.size())
367 {
368 messages::resourceMissingAtURI(res, entryID);
369 return false;
370 }
371 return true;
372}
373
Jason M. Bills95820182019-04-22 16:25:34 -0700374static bool
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500375 getRedfishLogFiles(std::vector<std::filesystem::path>& redfishLogFiles)
Jason M. Bills95820182019-04-22 16:25:34 -0700376{
377 static const std::filesystem::path redfishLogDir = "/var/log";
378 static const std::string redfishLogFilename = "redfish";
379
380 // Loop through the directory looking for redfish log files
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500381 for (const std::filesystem::directory_entry& dirEnt :
Jason M. Bills95820182019-04-22 16:25:34 -0700382 std::filesystem::directory_iterator(redfishLogDir))
383 {
384 // If we find a redfish log file, save the path
385 std::string filename = dirEnt.path().filename();
386 if (boost::starts_with(filename, redfishLogFilename))
387 {
388 redfishLogFiles.emplace_back(redfishLogDir / filename);
389 }
390 }
391 // As the log files rotate, they are appended with a ".#" that is higher for
392 // the older logs. Since we don't expect more than 10 log files, we
393 // can just sort the list to get them in order from newest to oldest
394 std::sort(redfishLogFiles.begin(), redfishLogFiles.end());
395
396 return !redfishLogFiles.empty();
397}
398
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500399inline void getDumpEntryCollection(std::shared_ptr<AsyncResp>& asyncResp,
400 const std::string& dumpType)
401{
402 std::string dumpPath;
403 if (dumpType == "BMC")
404 {
405 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
406 }
407 else if (dumpType == "System")
408 {
409 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
410 }
411 else
412 {
413 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
414 messages::internalError(asyncResp->res);
415 return;
416 }
417
418 crow::connections::systemBus->async_method_call(
419 [asyncResp, dumpPath, dumpType](const boost::system::error_code ec,
420 GetManagedObjectsType& resp) {
421 if (ec)
422 {
423 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
424 messages::internalError(asyncResp->res);
425 return;
426 }
427
428 nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
429 entriesArray = nlohmann::json::array();
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500430 std::string dumpEntryPath =
431 "/xyz/openbmc_project/dump/" +
432 std::string(boost::algorithm::to_lower_copy(dumpType)) +
433 "/entry/";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500434
435 for (auto& object : resp)
436 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500437 if (object.first.str.find(dumpEntryPath) == std::string::npos)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500438 {
439 continue;
440 }
441 std::time_t timestamp;
442 uint64_t size = 0;
443 entriesArray.push_back({});
444 nlohmann::json& thisEntry = entriesArray.back();
445 const std::string& path =
446 static_cast<const std::string&>(object.first);
Ed Tanousf23b7292020-10-15 09:41:17 -0700447 std::size_t lastPos = path.rfind('/');
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500448 if (lastPos == std::string::npos)
449 {
450 continue;
451 }
452 std::string entryID = path.substr(lastPos + 1);
453
454 for (auto& interfaceMap : object.second)
455 {
456 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
457 {
458
459 for (auto& propertyMap : interfaceMap.second)
460 {
461 if (propertyMap.first == "Size")
462 {
463 auto sizePtr =
464 std::get_if<uint64_t>(&propertyMap.second);
465 if (sizePtr == nullptr)
466 {
467 messages::internalError(asyncResp->res);
468 break;
469 }
470 size = *sizePtr;
471 break;
472 }
473 }
474 }
475 else if (interfaceMap.first ==
476 "xyz.openbmc_project.Time.EpochTime")
477 {
478
479 for (auto& propertyMap : interfaceMap.second)
480 {
481 if (propertyMap.first == "Elapsed")
482 {
483 const uint64_t* usecsTimeStamp =
484 std::get_if<uint64_t>(&propertyMap.second);
485 if (usecsTimeStamp == nullptr)
486 {
487 messages::internalError(asyncResp->res);
488 break;
489 }
490 timestamp =
491 static_cast<std::time_t>(*usecsTimeStamp);
492 break;
493 }
494 }
495 }
496 }
497
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500498 thisEntry["@odata.type"] = "#LogEntry.v1_7_0.LogEntry";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500499 thisEntry["@odata.id"] = dumpPath + entryID;
500 thisEntry["Id"] = entryID;
501 thisEntry["EntryType"] = "Event";
502 thisEntry["Created"] = crow::utility::getDateTime(timestamp);
503 thisEntry["Name"] = dumpType + " Dump Entry";
504
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500505 thisEntry["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500506
507 if (dumpType == "BMC")
508 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500509 thisEntry["DiagnosticDataType"] = "Manager";
510 thisEntry["AdditionalDataURI"] =
511 "/redfish/v1/Managers/bmc/LogServices/Dump/"
512 "attachment/" +
513 entryID;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500514 }
515 else if (dumpType == "System")
516 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500517 thisEntry["DiagnosticDataType"] = "OEM";
518 thisEntry["OEMDiagnosticDataType"] = "System";
519 thisEntry["AdditionalDataURI"] =
520 "/redfish/v1/Systems/system/LogServices/Dump/"
521 "attachment/" +
522 entryID;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500523 }
524 }
525 asyncResp->res.jsonValue["Members@odata.count"] =
526 entriesArray.size();
527 },
528 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
529 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
530}
531
532inline void getDumpEntryById(std::shared_ptr<AsyncResp>& asyncResp,
533 const std::string& entryID,
534 const std::string& dumpType)
535{
536 std::string dumpPath;
537 if (dumpType == "BMC")
538 {
539 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
540 }
541 else if (dumpType == "System")
542 {
543 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
544 }
545 else
546 {
547 BMCWEB_LOG_ERROR << "Invalid dump type" << dumpType;
548 messages::internalError(asyncResp->res);
549 return;
550 }
551
552 crow::connections::systemBus->async_method_call(
553 [asyncResp, entryID, dumpPath, dumpType](
554 const boost::system::error_code ec, GetManagedObjectsType& resp) {
555 if (ec)
556 {
557 BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
558 messages::internalError(asyncResp->res);
559 return;
560 }
561
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500562 bool foundDumpEntry = false;
563 std::string dumpEntryPath =
564 "/xyz/openbmc_project/dump/" +
565 std::string(boost::algorithm::to_lower_copy(dumpType)) +
566 "/entry/";
567
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500568 for (auto& objectPath : resp)
569 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500570 if (objectPath.first.str != dumpEntryPath + entryID)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500571 {
572 continue;
573 }
574
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500575 foundDumpEntry = true;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500576 std::time_t timestamp;
577 uint64_t size = 0;
578
579 for (auto& interfaceMap : objectPath.second)
580 {
581 if (interfaceMap.first == "xyz.openbmc_project.Dump.Entry")
582 {
583 for (auto& propertyMap : interfaceMap.second)
584 {
585 if (propertyMap.first == "Size")
586 {
587 auto sizePtr =
588 std::get_if<uint64_t>(&propertyMap.second);
589 if (sizePtr == nullptr)
590 {
591 messages::internalError(asyncResp->res);
592 break;
593 }
594 size = *sizePtr;
595 break;
596 }
597 }
598 }
599 else if (interfaceMap.first ==
600 "xyz.openbmc_project.Time.EpochTime")
601 {
602 for (auto& propertyMap : interfaceMap.second)
603 {
604 if (propertyMap.first == "Elapsed")
605 {
606 const uint64_t* usecsTimeStamp =
607 std::get_if<uint64_t>(&propertyMap.second);
608 if (usecsTimeStamp == nullptr)
609 {
610 messages::internalError(asyncResp->res);
611 break;
612 }
613 timestamp =
614 static_cast<std::time_t>(*usecsTimeStamp);
615 break;
616 }
617 }
618 }
619 }
620
621 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500622 "#LogEntry.v1_7_0.LogEntry";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500623 asyncResp->res.jsonValue["@odata.id"] = dumpPath + entryID;
624 asyncResp->res.jsonValue["Id"] = entryID;
625 asyncResp->res.jsonValue["EntryType"] = "Event";
626 asyncResp->res.jsonValue["Created"] =
627 crow::utility::getDateTime(timestamp);
628 asyncResp->res.jsonValue["Name"] = dumpType + " Dump Entry";
629
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500630 asyncResp->res.jsonValue["AdditionalDataSizeBytes"] = size;
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500631
632 if (dumpType == "BMC")
633 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500634 asyncResp->res.jsonValue["DiagnosticDataType"] = "Manager";
635 asyncResp->res.jsonValue["AdditionalDataURI"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500636 "/redfish/v1/Managers/bmc/LogServices/Dump/"
637 "attachment/" +
638 entryID;
639 }
640 else if (dumpType == "System")
641 {
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500642 asyncResp->res.jsonValue["DiagnosticDataType"] = "OEM";
643 asyncResp->res.jsonValue["OEMDiagnosticDataType"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500644 "System";
Asmitha Karunanithid337bb72020-09-21 10:34:02 -0500645 asyncResp->res.jsonValue["AdditionalDataURI"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500646 "/redfish/v1/Systems/system/LogServices/Dump/"
647 "attachment/" +
648 entryID;
649 }
650 }
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500651 if (foundDumpEntry == false)
652 {
653 BMCWEB_LOG_ERROR << "Can't find Dump Entry";
654 messages::internalError(asyncResp->res);
655 return;
656 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500657 },
658 "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
659 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
660}
661
Stanley Chu98782562020-11-04 16:10:24 +0800662inline void deleteDumpEntry(const std::shared_ptr<AsyncResp>& asyncResp,
663 const std::string& entryID,
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500664 const std::string& dumpType)
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500665{
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500666 auto respHandler = [asyncResp](const boost::system::error_code ec) {
667 BMCWEB_LOG_DEBUG << "Dump Entry doDelete callback: Done";
668 if (ec)
669 {
670 BMCWEB_LOG_ERROR << "Dump (DBus) doDelete respHandler got error "
671 << ec;
672 messages::internalError(asyncResp->res);
673 return;
674 }
675 };
676 crow::connections::systemBus->async_method_call(
677 respHandler, "xyz.openbmc_project.Dump.Manager",
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500678 "/xyz/openbmc_project/dump/" +
679 std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" +
680 entryID,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500681 "xyz.openbmc_project.Object.Delete", "Delete");
682}
683
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500684inline void createDumpTaskCallback(const crow::Request& req,
Ed Tanousb5a76932020-09-29 16:16:58 -0700685 const std::shared_ptr<AsyncResp>& asyncResp,
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500686 const uint32_t& dumpId,
687 const std::string& dumpPath,
688 const std::string& dumpType)
689{
690 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500691 [dumpId, dumpPath, dumpType](
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500692 boost::system::error_code err, sdbusplus::message::message& m,
693 const std::shared_ptr<task::TaskData>& taskData) {
Ed Tanouscb13a392020-07-25 19:02:03 +0000694 if (err)
695 {
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500696 BMCWEB_LOG_ERROR << "Error in creating a dump";
697 taskData->state = "Cancelled";
698 return task::completed;
Ed Tanouscb13a392020-07-25 19:02:03 +0000699 }
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500700 std::vector<std::pair<
701 std::string,
702 std::vector<std::pair<std::string, std::variant<std::string>>>>>
703 interfacesList;
704
705 sdbusplus::message::object_path objPath;
706
707 m.read(objPath, interfacesList);
708
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500709 if (objPath.str ==
710 "/xyz/openbmc_project/dump/" +
711 std::string(boost::algorithm::to_lower_copy(dumpType)) +
712 "/entry/" + std::to_string(dumpId))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500713 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500714 nlohmann::json retMessage = messages::success();
715 taskData->messages.emplace_back(retMessage);
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500716
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500717 std::string headerLoc =
718 "Location: " + dumpPath + std::to_string(dumpId);
719 taskData->payload->httpHeaders.emplace_back(
720 std::move(headerLoc));
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500721
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500722 taskData->state = "Completed";
723 return task::completed;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500724 }
Asmitha Karunanithi6145ed62020-09-17 23:40:03 -0500725 return task::completed;
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500726 },
727 "type='signal',interface='org.freedesktop.DBus."
728 "ObjectManager',"
729 "member='InterfacesAdded', "
730 "path='/xyz/openbmc_project/dump'");
731
732 task->startTimer(std::chrono::minutes(3));
733 task->populateResp(asyncResp->res);
734 task->payload.emplace(req);
735}
736
737inline void createDump(crow::Response& res, const crow::Request& req,
738 const std::string& dumpType)
739{
740 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
741
742 std::string dumpPath;
743 if (dumpType == "BMC")
744 {
745 dumpPath = "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/";
746 }
747 else if (dumpType == "System")
748 {
749 dumpPath = "/redfish/v1/Systems/system/LogServices/Dump/Entries/";
750 }
751 else
752 {
753 BMCWEB_LOG_ERROR << "Invalid dump type: " << dumpType;
754 messages::internalError(asyncResp->res);
755 return;
756 }
757
758 std::optional<std::string> diagnosticDataType;
759 std::optional<std::string> oemDiagnosticDataType;
760
761 if (!redfish::json_util::readJson(
762 req, asyncResp->res, "DiagnosticDataType", diagnosticDataType,
763 "OEMDiagnosticDataType", oemDiagnosticDataType))
764 {
765 return;
766 }
767
768 if (dumpType == "System")
769 {
770 if (!oemDiagnosticDataType || !diagnosticDataType)
771 {
772 BMCWEB_LOG_ERROR << "CreateDump action parameter "
773 "'DiagnosticDataType'/"
774 "'OEMDiagnosticDataType' value not found!";
775 messages::actionParameterMissing(
776 asyncResp->res, "CollectDiagnosticData",
777 "DiagnosticDataType & OEMDiagnosticDataType");
778 return;
779 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700780 if ((*oemDiagnosticDataType != "System") ||
781 (*diagnosticDataType != "OEM"))
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500782 {
783 BMCWEB_LOG_ERROR << "Wrong parameter values passed";
784 messages::invalidObject(asyncResp->res,
785 "System Dump creation parameters");
786 return;
787 }
788 }
789 else if (dumpType == "BMC")
790 {
791 if (!diagnosticDataType)
792 {
793 BMCWEB_LOG_ERROR << "CreateDump action parameter "
794 "'DiagnosticDataType' not found!";
795 messages::actionParameterMissing(
796 asyncResp->res, "CollectDiagnosticData", "DiagnosticDataType");
797 return;
798 }
Ed Tanous3174e4d2020-10-07 11:41:22 -0700799 if (*diagnosticDataType != "Manager")
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500800 {
801 BMCWEB_LOG_ERROR
802 << "Wrong parameter value passed for 'DiagnosticDataType'";
803 messages::invalidObject(asyncResp->res,
804 "BMC Dump creation parameters");
805 return;
806 }
807 }
808
809 crow::connections::systemBus->async_method_call(
810 [asyncResp, req, dumpPath, dumpType](const boost::system::error_code ec,
811 const uint32_t& dumpId) {
812 if (ec)
813 {
814 BMCWEB_LOG_ERROR << "CreateDump resp_handler got error " << ec;
815 messages::internalError(asyncResp->res);
816 return;
817 }
818 BMCWEB_LOG_DEBUG << "Dump Created. Id: " << dumpId;
819
820 createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
821 },
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500822 "xyz.openbmc_project.Dump.Manager",
823 "/xyz/openbmc_project/dump/" +
824 std::string(boost::algorithm::to_lower_copy(dumpType)),
Asmitha Karunanithia43be802020-05-07 05:05:36 -0500825 "xyz.openbmc_project.Dump.Create", "CreateDump");
826}
827
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500828inline void clearDump(crow::Response& res, const std::string& dumpType)
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500829{
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500830 std::string dumpTypeLowerCopy =
831 std::string(boost::algorithm::to_lower_copy(dumpType));
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500832 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
833 crow::connections::systemBus->async_method_call(
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500834 [asyncResp, dumpType](const boost::system::error_code ec,
835 const std::vector<std::string>& subTreePaths) {
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500836 if (ec)
837 {
838 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
839 messages::internalError(asyncResp->res);
840 return;
841 }
842
843 for (const std::string& path : subTreePaths)
844 {
Ed Tanousf23b7292020-10-15 09:41:17 -0700845 std::size_t pos = path.rfind('/');
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500846 if (pos != std::string::npos)
847 {
848 std::string logID = path.substr(pos + 1);
Stanley Chu98782562020-11-04 16:10:24 +0800849 deleteDumpEntry(asyncResp, logID, dumpType);
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500850 }
851 }
852 },
853 "xyz.openbmc_project.ObjectMapper",
854 "/xyz/openbmc_project/object_mapper",
855 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
Asmitha Karunanithib47452b2020-09-25 02:02:19 -0500856 "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0,
857 std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." +
858 dumpType});
Asmitha Karunanithi80319af2020-05-07 05:30:21 -0500859}
860
Ed Tanous2c70f802020-09-28 14:29:23 -0700861static void parseCrashdumpParameters(
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500862 const std::vector<std::pair<std::string, VariantType>>& params,
863 std::string& filename, std::string& timestamp, std::string& logfile)
Johnathan Mantey043a0532020-03-10 17:15:28 -0700864{
865 for (auto property : params)
866 {
867 if (property.first == "Timestamp")
868 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500869 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500870 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700871 if (value != nullptr)
872 {
873 timestamp = *value;
874 }
875 }
876 else if (property.first == "Filename")
877 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500878 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500879 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700880 if (value != nullptr)
881 {
882 filename = *value;
883 }
884 }
885 else if (property.first == "Log")
886 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500887 const std::string* value =
Patrick Williams8d78b7a2020-05-13 11:24:20 -0500888 std::get_if<std::string>(&property.second);
Johnathan Mantey043a0532020-03-10 17:15:28 -0700889 if (value != nullptr)
890 {
891 logfile = *value;
892 }
893 }
894 }
895}
896
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500897constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800898class SystemLogServiceCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -0700899{
900 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700901 SystemLogServiceCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800902 Node(app, "/redfish/v1/Systems/system/LogServices/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800903 {
904 entityPrivileges = {
905 {boost::beast::http::verb::get, {{"Login"}}},
906 {boost::beast::http::verb::head, {{"Login"}}},
907 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
908 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
909 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
910 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
911 }
912
913 private:
914 /**
915 * Functions triggers appropriate requests on DBus
916 */
Ed Tanouscb13a392020-07-25 19:02:03 +0000917 void doGet(crow::Response& res, const crow::Request&,
918 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800919 {
920 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800921 // Collections don't include the static data added by SubRoute because
922 // it has a duplicate entry for members
923 asyncResp->res.jsonValue["@odata.type"] =
924 "#LogServiceCollection.LogServiceCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800925 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -0800926 "/redfish/v1/Systems/system/LogServices";
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800927 asyncResp->res.jsonValue["Name"] = "System Log Services Collection";
928 asyncResp->res.jsonValue["Description"] =
929 "Collection of LogServices for this Computer System";
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500930 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800931 logServiceArray = nlohmann::json::array();
Ed Tanous029573d2019-02-01 10:57:49 -0800932 logServiceArray.push_back(
933 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/EventLog"}});
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500934#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
raviteja-bc9bb6862020-02-03 11:53:32 -0600935 logServiceArray.push_back(
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -0500936 {{"@odata.id", "/redfish/v1/Systems/system/LogServices/Dump"}});
raviteja-bc9bb6862020-02-03 11:53:32 -0600937#endif
938
Jason M. Billsd53dd412019-02-12 17:16:22 -0800939#ifdef BMCWEB_ENABLE_REDFISH_CPU_LOG
940 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -0500941 {{"@odata.id",
942 "/redfish/v1/Systems/system/LogServices/Crashdump"}});
Jason M. Billsd53dd412019-02-12 17:16:22 -0800943#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800944 asyncResp->res.jsonValue["Members@odata.count"] =
945 logServiceArray.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800946
947 crow::connections::systemBus->async_method_call(
948 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500949 const std::vector<std::string>& subtreePath) {
ZhikuiRena3316fc2020-01-29 14:58:08 -0800950 if (ec)
951 {
952 BMCWEB_LOG_ERROR << ec;
953 return;
954 }
955
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500956 for (auto& pathStr : subtreePath)
ZhikuiRena3316fc2020-01-29 14:58:08 -0800957 {
958 if (pathStr.find("PostCode") != std::string::npos)
959 {
Ed Tanous23a21a12020-07-25 04:45:05 +0000960 nlohmann::json& logServiceArrayLocal =
ZhikuiRena3316fc2020-01-29 14:58:08 -0800961 asyncResp->res.jsonValue["Members"];
Ed Tanous23a21a12020-07-25 04:45:05 +0000962 logServiceArrayLocal.push_back(
ZhikuiRena3316fc2020-01-29 14:58:08 -0800963 {{"@odata.id", "/redfish/v1/Systems/system/"
964 "LogServices/PostCodes"}});
965 asyncResp->res.jsonValue["Members@odata.count"] =
Ed Tanous23a21a12020-07-25 04:45:05 +0000966 logServiceArrayLocal.size();
ZhikuiRena3316fc2020-01-29 14:58:08 -0800967 return;
968 }
969 }
970 },
971 "xyz.openbmc_project.ObjectMapper",
972 "/xyz/openbmc_project/object_mapper",
973 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500974 std::array<const char*, 1>{postCodeIface});
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800975 }
976};
977
978class EventLogService : public Node
979{
980 public:
Ed Tanous52cc1122020-07-18 13:51:21 -0700981 EventLogService(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -0800982 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800983 {
984 entityPrivileges = {
985 {boost::beast::http::verb::get, {{"Login"}}},
986 {boost::beast::http::verb::head, {{"Login"}}},
987 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
988 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
989 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
990 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
991 }
992
993 private:
Ed Tanouscb13a392020-07-25 19:02:03 +0000994 void doGet(crow::Response& res, const crow::Request&,
995 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800996 {
997 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
998
Jason M. Billsc4bf6372018-11-05 13:48:27 -0800999 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001000 "/redfish/v1/Systems/system/LogServices/EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001001 asyncResp->res.jsonValue["@odata.type"] =
1002 "#LogService.v1_1_0.LogService";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001003 asyncResp->res.jsonValue["Name"] = "Event Log Service";
1004 asyncResp->res.jsonValue["Description"] = "System Event Log Service";
Gunnar Mills73ec8302020-04-14 16:02:42 -05001005 asyncResp->res.jsonValue["Id"] = "EventLog";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001006 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
1007 asyncResp->res.jsonValue["Entries"] = {
1008 {"@odata.id",
Ed Tanous029573d2019-02-01 10:57:49 -08001009 "/redfish/v1/Systems/system/LogServices/EventLog/Entries"}};
Gunnar Millse7d6c8b2019-07-03 11:30:01 -05001010 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
1011
1012 {"target", "/redfish/v1/Systems/system/LogServices/EventLog/"
1013 "Actions/LogService.ClearLog"}};
Jason M. Bills489640c2019-05-17 09:56:36 -07001014 }
1015};
1016
Tim Lee1f56a3a2019-10-09 10:17:57 +08001017class JournalEventLogClear : public Node
Jason M. Bills489640c2019-05-17 09:56:36 -07001018{
1019 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001020 JournalEventLogClear(App& app) :
Jason M. Bills489640c2019-05-17 09:56:36 -07001021 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
1022 "LogService.ClearLog/")
1023 {
1024 entityPrivileges = {
1025 {boost::beast::http::verb::get, {{"Login"}}},
1026 {boost::beast::http::verb::head, {{"Login"}}},
1027 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
1028 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
1029 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
1030 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
1031 }
1032
1033 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001034 void doPost(crow::Response& res, const crow::Request&,
1035 const std::vector<std::string>&) override
Jason M. Bills489640c2019-05-17 09:56:36 -07001036 {
1037 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1038
1039 // Clear the EventLog by deleting the log files
1040 std::vector<std::filesystem::path> redfishLogFiles;
1041 if (getRedfishLogFiles(redfishLogFiles))
1042 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001043 for (const std::filesystem::path& file : redfishLogFiles)
Jason M. Bills489640c2019-05-17 09:56:36 -07001044 {
1045 std::error_code ec;
1046 std::filesystem::remove(file, ec);
1047 }
1048 }
1049
1050 // Reload rsyslog so it knows to start new log files
1051 crow::connections::systemBus->async_method_call(
1052 [asyncResp](const boost::system::error_code ec) {
1053 if (ec)
1054 {
1055 BMCWEB_LOG_ERROR << "Failed to reload rsyslog: " << ec;
1056 messages::internalError(asyncResp->res);
1057 return;
1058 }
1059
1060 messages::success(asyncResp->res);
1061 },
1062 "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
1063 "org.freedesktop.systemd1.Manager", "ReloadUnit", "rsyslog.service",
1064 "replace");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001065 }
1066};
1067
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001068static int fillEventLogEntryJson(const std::string& logEntryID,
Ed Tanousb5a76932020-09-29 16:16:58 -07001069 const std::string& logEntry,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001070 nlohmann::json& logEntryJson)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001071{
Jason M. Bills95820182019-04-22 16:25:34 -07001072 // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
Jason M. Billscd225da2019-05-08 15:31:57 -07001073 // First get the Timestamp
Ed Tanousf23b7292020-10-15 09:41:17 -07001074 size_t space = logEntry.find_first_of(' ');
Jason M. Billscd225da2019-05-08 15:31:57 -07001075 if (space == std::string::npos)
Jason M. Bills95820182019-04-22 16:25:34 -07001076 {
1077 return 1;
1078 }
Jason M. Billscd225da2019-05-08 15:31:57 -07001079 std::string timestamp = logEntry.substr(0, space);
1080 // Then get the log contents
Ed Tanousf23b7292020-10-15 09:41:17 -07001081 size_t entryStart = logEntry.find_first_not_of(' ', space);
Jason M. Billscd225da2019-05-08 15:31:57 -07001082 if (entryStart == std::string::npos)
1083 {
1084 return 1;
1085 }
1086 std::string_view entry(logEntry);
1087 entry.remove_prefix(entryStart);
1088 // Use split to separate the entry into its fields
1089 std::vector<std::string> logEntryFields;
1090 boost::split(logEntryFields, entry, boost::is_any_of(","),
1091 boost::token_compress_on);
1092 // We need at least a MessageId to be valid
1093 if (logEntryFields.size() < 1)
1094 {
1095 return 1;
1096 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001097 std::string& messageID = logEntryFields[0];
Jason M. Bills95820182019-04-22 16:25:34 -07001098
Jason M. Bills4851d452019-03-28 11:27:48 -07001099 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001100 const message_registries::Message* message =
Jason M. Bills4851d452019-03-28 11:27:48 -07001101 message_registries::getMessage(messageID);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001102
Jason M. Bills4851d452019-03-28 11:27:48 -07001103 std::string msg;
1104 std::string severity;
1105 if (message != nullptr)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001106 {
Jason M. Bills4851d452019-03-28 11:27:48 -07001107 msg = message->message;
1108 severity = message->severity;
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001109 }
1110
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001111 // Get the MessageArgs from the log if there are any
1112 boost::beast::span<std::string> messageArgs;
1113 if (logEntryFields.size() > 1)
Jason M. Bills4851d452019-03-28 11:27:48 -07001114 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001115 std::string& messageArgsStart = logEntryFields[1];
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001116 // If the first string is empty, assume there are no MessageArgs
1117 std::size_t messageArgsSize = 0;
1118 if (!messageArgsStart.empty())
Jason M. Bills4851d452019-03-28 11:27:48 -07001119 {
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001120 messageArgsSize = logEntryFields.size() - 1;
1121 }
1122
Ed Tanous23a21a12020-07-25 04:45:05 +00001123 messageArgs = {&messageArgsStart, messageArgsSize};
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001124
1125 // Fill the MessageArgs into the Message
1126 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001127 for (const std::string& messageArg : messageArgs)
Jason M. Bills15a86ff2019-06-18 13:49:54 -07001128 {
1129 std::string argStr = "%" + std::to_string(++i);
1130 size_t argPos = msg.find(argStr);
1131 if (argPos != std::string::npos)
1132 {
1133 msg.replace(argPos, argStr.length(), messageArg);
1134 }
Jason M. Bills4851d452019-03-28 11:27:48 -07001135 }
1136 }
1137
Jason M. Bills95820182019-04-22 16:25:34 -07001138 // Get the Created time from the timestamp. The log timestamp is in RFC3339
1139 // format which matches the Redfish format except for the fractional seconds
1140 // between the '.' and the '+', so just remove them.
Ed Tanousf23b7292020-10-15 09:41:17 -07001141 std::size_t dot = timestamp.find_first_of('.');
1142 std::size_t plus = timestamp.find_first_of('+');
Jason M. Bills95820182019-04-22 16:25:34 -07001143 if (dot != std::string::npos && plus != std::string::npos)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001144 {
Jason M. Bills95820182019-04-22 16:25:34 -07001145 timestamp.erase(dot, plus - dot);
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001146 }
1147
1148 // Fill in the log entry with the gathered data
Jason M. Bills95820182019-04-22 16:25:34 -07001149 logEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001150 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Ed Tanous029573d2019-02-01 10:57:49 -08001151 {"@odata.id",
Jason M. Bills897967d2019-07-29 17:05:30 -07001152 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/" +
Jason M. Bills95820182019-04-22 16:25:34 -07001153 logEntryID},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001154 {"Name", "System Event Log Entry"},
Jason M. Bills95820182019-04-22 16:25:34 -07001155 {"Id", logEntryID},
1156 {"Message", std::move(msg)},
1157 {"MessageId", std::move(messageID)},
Ed Tanousf23b7292020-10-15 09:41:17 -07001158 {"MessageArgs", messageArgs},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001159 {"EntryType", "Event"},
Jason M. Bills95820182019-04-22 16:25:34 -07001160 {"Severity", std::move(severity)},
1161 {"Created", std::move(timestamp)}};
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001162 return 0;
1163}
1164
Anthony Wilson27062602019-04-22 02:10:09 -05001165class JournalEventLogEntryCollection : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001166{
1167 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001168 JournalEventLogEntryCollection(App& app) :
Ed Tanous029573d2019-02-01 10:57:49 -08001169 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001170 {
1171 entityPrivileges = {
1172 {boost::beast::http::verb::get, {{"Login"}}},
1173 {boost::beast::http::verb::head, {{"Login"}}},
1174 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1175 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1176 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1177 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1178 }
1179
1180 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001181 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001182 const std::vector<std::string>&) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001183 {
1184 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous271584a2019-07-09 16:24:22 -07001185 uint64_t skip = 0;
1186 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001187 if (!getSkipParam(asyncResp->res, req, skip))
1188 {
1189 return;
1190 }
1191 if (!getTopParam(asyncResp->res, req, top))
1192 {
1193 return;
1194 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001195 // Collections don't include the static data added by SubRoute because
1196 // it has a duplicate entry for members
1197 asyncResp->res.jsonValue["@odata.type"] =
1198 "#LogEntryCollection.LogEntryCollection";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001199 asyncResp->res.jsonValue["@odata.id"] =
Ed Tanous029573d2019-02-01 10:57:49 -08001200 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001201 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1202 asyncResp->res.jsonValue["Description"] =
1203 "Collection of System Event Log Entries";
Andrew Geisslercb92c032018-08-17 07:56:14 -07001204
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001205 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001206 logEntryArray = nlohmann::json::array();
Jason M. Bills95820182019-04-22 16:25:34 -07001207 // Go through the log files and create a unique ID for each entry
1208 std::vector<std::filesystem::path> redfishLogFiles;
1209 getRedfishLogFiles(redfishLogFiles);
Ed Tanousb01bf292019-03-25 19:25:26 +00001210 uint64_t entryCount = 0;
Jason M. Billscd225da2019-05-08 15:31:57 -07001211 std::string logEntry;
Jason M. Bills95820182019-04-22 16:25:34 -07001212
1213 // Oldest logs are in the last file, so start there and loop backwards
Jason M. Billscd225da2019-05-08 15:31:57 -07001214 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1215 it++)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001216 {
Jason M. Billscd225da2019-05-08 15:31:57 -07001217 std::ifstream logStream(*it);
Jason M. Bills95820182019-04-22 16:25:34 -07001218 if (!logStream.is_open())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001219 {
1220 continue;
1221 }
1222
Jason M. Billse85d6b12019-07-29 17:01:15 -07001223 // Reset the unique ID on the first entry
1224 bool firstEntry = true;
Jason M. Bills95820182019-04-22 16:25:34 -07001225 while (std::getline(logStream, logEntry))
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001226 {
Jason M. Bills95820182019-04-22 16:25:34 -07001227 entryCount++;
1228 // Handle paging using skip (number of entries to skip from the
1229 // start) and top (number of entries to display)
1230 if (entryCount <= skip || entryCount > skip + top)
1231 {
1232 continue;
1233 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001234
Jason M. Bills95820182019-04-22 16:25:34 -07001235 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001236 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
Jason M. Bills95820182019-04-22 16:25:34 -07001237 {
1238 continue;
1239 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001240
Jason M. Billse85d6b12019-07-29 17:01:15 -07001241 if (firstEntry)
1242 {
1243 firstEntry = false;
1244 }
1245
Jason M. Bills95820182019-04-22 16:25:34 -07001246 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001247 nlohmann::json& bmcLogEntry = logEntryArray.back();
Jason M. Bills95820182019-04-22 16:25:34 -07001248 if (fillEventLogEntryJson(idStr, logEntry, bmcLogEntry) != 0)
1249 {
1250 messages::internalError(asyncResp->res);
1251 return;
1252 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001253 }
1254 }
1255 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1256 if (skip + top < entryCount)
1257 {
1258 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Bills95820182019-04-22 16:25:34 -07001259 "/redfish/v1/Systems/system/LogServices/EventLog/"
1260 "Entries?$skip=" +
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001261 std::to_string(skip + top);
1262 }
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001263 }
1264};
1265
Jason M. Bills897967d2019-07-29 17:05:30 -07001266class JournalEventLogEntry : public Node
1267{
1268 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001269 JournalEventLogEntry(App& app) :
Jason M. Bills897967d2019-07-29 17:05:30 -07001270 Node(app,
1271 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1272 std::string())
1273 {
1274 entityPrivileges = {
1275 {boost::beast::http::verb::get, {{"Login"}}},
1276 {boost::beast::http::verb::head, {{"Login"}}},
1277 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1278 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1279 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1280 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1281 }
1282
1283 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001284 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001285 const std::vector<std::string>& params) override
Jason M. Bills897967d2019-07-29 17:05:30 -07001286 {
1287 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1288 if (params.size() != 1)
1289 {
1290 messages::internalError(asyncResp->res);
1291 return;
1292 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001293 const std::string& targetID = params[0];
Jason M. Bills897967d2019-07-29 17:05:30 -07001294
1295 // Go through the log files and check the unique ID for each entry to
1296 // find the target entry
1297 std::vector<std::filesystem::path> redfishLogFiles;
1298 getRedfishLogFiles(redfishLogFiles);
1299 std::string logEntry;
1300
1301 // Oldest logs are in the last file, so start there and loop backwards
1302 for (auto it = redfishLogFiles.rbegin(); it < redfishLogFiles.rend();
1303 it++)
1304 {
1305 std::ifstream logStream(*it);
1306 if (!logStream.is_open())
1307 {
1308 continue;
1309 }
1310
1311 // Reset the unique ID on the first entry
1312 bool firstEntry = true;
1313 while (std::getline(logStream, logEntry))
1314 {
1315 std::string idStr;
1316 if (!getUniqueEntryID(logEntry, idStr, firstEntry))
1317 {
1318 continue;
1319 }
1320
1321 if (firstEntry)
1322 {
1323 firstEntry = false;
1324 }
1325
1326 if (idStr == targetID)
1327 {
1328 if (fillEventLogEntryJson(idStr, logEntry,
1329 asyncResp->res.jsonValue) != 0)
1330 {
1331 messages::internalError(asyncResp->res);
1332 return;
1333 }
1334 return;
1335 }
1336 }
1337 }
1338 // Requested ID was not found
1339 messages::resourceMissingAtURI(asyncResp->res, targetID);
1340 }
1341};
1342
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001343class DBusEventLogEntryCollection : public Node
1344{
1345 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001346 DBusEventLogEntryCollection(App& app) :
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001347 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Entries/")
1348 {
1349 entityPrivileges = {
1350 {boost::beast::http::verb::get, {{"Login"}}},
1351 {boost::beast::http::verb::head, {{"Login"}}},
1352 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1353 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1354 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1355 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1356 }
1357
1358 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001359 void doGet(crow::Response& res, const crow::Request&,
1360 const std::vector<std::string>&) override
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001361 {
1362 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1363
1364 // Collections don't include the static data added by SubRoute because
1365 // it has a duplicate entry for members
1366 asyncResp->res.jsonValue["@odata.type"] =
1367 "#LogEntryCollection.LogEntryCollection";
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001368 asyncResp->res.jsonValue["@odata.id"] =
1369 "/redfish/v1/Systems/system/LogServices/EventLog/Entries";
1370 asyncResp->res.jsonValue["Name"] = "System Event Log Entries";
1371 asyncResp->res.jsonValue["Description"] =
1372 "Collection of System Event Log Entries";
1373
Andrew Geisslercb92c032018-08-17 07:56:14 -07001374 // DBus implementation of EventLog/Entries
1375 // Make call to Logging Service to find all log entry objects
1376 crow::connections::systemBus->async_method_call(
1377 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001378 GetManagedObjectsType& resp) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001379 if (ec)
1380 {
1381 // TODO Handle for specific error code
1382 BMCWEB_LOG_ERROR
1383 << "getLogEntriesIfaceData resp_handler got error "
1384 << ec;
1385 messages::internalError(asyncResp->res);
1386 return;
1387 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001388 nlohmann::json& entriesArray =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001389 asyncResp->res.jsonValue["Members"];
1390 entriesArray = nlohmann::json::array();
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001391 for (auto& objectPath : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001392 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001393 for (auto& interfaceMap : objectPath.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001394 {
1395 if (interfaceMap.first !=
1396 "xyz.openbmc_project.Logging.Entry")
1397 {
1398 BMCWEB_LOG_DEBUG << "Bailing early on "
1399 << interfaceMap.first;
1400 continue;
1401 }
1402 entriesArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001403 nlohmann::json& thisEntry = entriesArray.back();
1404 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001405 std::time_t timestamp{};
George Liud139c232020-08-18 18:48:57 +08001406 std::time_t updateTimestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001407 std::string* severity = nullptr;
1408 std::string* message = nullptr;
George Liud139c232020-08-18 18:48:57 +08001409
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001410 for (auto& propertyMap : interfaceMap.second)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001411 {
1412 if (propertyMap.first == "Id")
1413 {
Patrick Williams8d78b7a2020-05-13 11:24:20 -05001414 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001415 }
1416 else if (propertyMap.first == "Timestamp")
1417 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001418 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001419 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001420 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001421 {
1422 timestamp = crow::utility::getTimestamp(
1423 *millisTimeStamp);
1424 }
George Liud139c232020-08-18 18:48:57 +08001425 }
1426 else if (propertyMap.first == "UpdateTimestamp")
1427 {
1428 const uint64_t* millisTimeStamp =
1429 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001430 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001431 {
1432 updateTimestamp =
1433 crow::utility::getTimestamp(
1434 *millisTimeStamp);
1435 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001436 }
1437 else if (propertyMap.first == "Severity")
1438 {
1439 severity = std::get_if<std::string>(
1440 &propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001441 }
1442 else if (propertyMap.first == "Message")
1443 {
1444 message = std::get_if<std::string>(
1445 &propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001446 }
1447 }
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001448 if (id == nullptr || message == nullptr ||
1449 severity == nullptr)
1450 {
1451 messages::internalError(asyncResp->res);
1452 return;
1453 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001454 thisEntry = {
George Liud139c232020-08-18 18:48:57 +08001455 {"@odata.type", "#LogEntry.v1_6_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001456 {"@odata.id",
1457 "/redfish/v1/Systems/system/LogServices/EventLog/"
1458 "Entries/" +
1459 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001460 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001461 {"Id", std::to_string(*id)},
1462 {"Message", *message},
1463 {"EntryType", "Event"},
1464 {"Severity",
1465 translateSeverityDbusToRedfish(*severity)},
George Liud139c232020-08-18 18:48:57 +08001466 {"Created", crow::utility::getDateTime(timestamp)},
1467 {"Modified",
1468 crow::utility::getDateTime(updateTimestamp)}};
Andrew Geisslercb92c032018-08-17 07:56:14 -07001469 }
1470 }
1471 std::sort(entriesArray.begin(), entriesArray.end(),
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001472 [](const nlohmann::json& left,
1473 const nlohmann::json& right) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001474 return (left["Id"] <= right["Id"]);
1475 });
1476 asyncResp->res.jsonValue["Members@odata.count"] =
1477 entriesArray.size();
1478 },
1479 "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
1480 "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001481 }
1482};
1483
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001484class DBusEventLogEntry : public Node
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001485{
1486 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001487 DBusEventLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001488 Node(app,
Ed Tanous029573d2019-02-01 10:57:49 -08001489 "/redfish/v1/Systems/system/LogServices/EventLog/Entries/<str>/",
1490 std::string())
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001491 {
1492 entityPrivileges = {
1493 {boost::beast::http::verb::get, {{"Login"}}},
1494 {boost::beast::http::verb::head, {{"Login"}}},
1495 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1496 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1497 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1498 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1499 }
1500
1501 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001502 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001503 const std::vector<std::string>& params) override
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001504 {
1505 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous029573d2019-02-01 10:57:49 -08001506 if (params.size() != 1)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001507 {
1508 messages::internalError(asyncResp->res);
1509 return;
1510 }
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001511 std::string entryID = params[0];
1512 dbus::utility::escapePathForDbus(entryID);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001513
Andrew Geisslercb92c032018-08-17 07:56:14 -07001514 // DBus implementation of EventLog/Entries
1515 // Make call to Logging Service to find all log entry objects
1516 crow::connections::systemBus->async_method_call(
1517 [asyncResp, entryID](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001518 GetManagedPropertyType& resp) {
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001519 if (ec.value() == EBADR)
1520 {
1521 messages::resourceNotFound(asyncResp->res, "EventLogEntry",
1522 entryID);
1523 return;
1524 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001525 if (ec)
1526 {
1527 BMCWEB_LOG_ERROR
1528 << "EventLogEntry (DBus) resp_handler got error " << ec;
1529 messages::internalError(asyncResp->res);
1530 return;
1531 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001532 uint32_t* id = nullptr;
Ed Tanous66664f22019-10-11 13:05:49 -07001533 std::time_t timestamp{};
George Liud139c232020-08-18 18:48:57 +08001534 std::time_t updateTimestamp{};
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001535 std::string* severity = nullptr;
1536 std::string* message = nullptr;
George Liud139c232020-08-18 18:48:57 +08001537
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001538 for (auto& propertyMap : resp)
Andrew Geisslercb92c032018-08-17 07:56:14 -07001539 {
1540 if (propertyMap.first == "Id")
1541 {
1542 id = std::get_if<uint32_t>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001543 }
1544 else if (propertyMap.first == "Timestamp")
1545 {
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001546 const uint64_t* millisTimeStamp =
Andrew Geisslercb92c032018-08-17 07:56:14 -07001547 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001548 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001549 {
1550 timestamp =
1551 crow::utility::getTimestamp(*millisTimeStamp);
1552 }
George Liud139c232020-08-18 18:48:57 +08001553 }
1554 else if (propertyMap.first == "UpdateTimestamp")
1555 {
1556 const uint64_t* millisTimeStamp =
1557 std::get_if<uint64_t>(&propertyMap.second);
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001558 if (millisTimeStamp != nullptr)
George Liuebd45902020-08-26 14:21:10 +08001559 {
1560 updateTimestamp =
1561 crow::utility::getTimestamp(*millisTimeStamp);
1562 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001563 }
1564 else if (propertyMap.first == "Severity")
1565 {
1566 severity =
1567 std::get_if<std::string>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001568 }
1569 else if (propertyMap.first == "Message")
1570 {
1571 message = std::get_if<std::string>(&propertyMap.second);
Andrew Geisslercb92c032018-08-17 07:56:14 -07001572 }
1573 }
Ed Tanous271584a2019-07-09 16:24:22 -07001574 if (id == nullptr || message == nullptr || severity == nullptr)
1575 {
Adriana Kobylakae34c8e2021-02-11 09:33:10 -06001576 messages::internalError(asyncResp->res);
Ed Tanous271584a2019-07-09 16:24:22 -07001577 return;
1578 }
Andrew Geisslercb92c032018-08-17 07:56:14 -07001579 asyncResp->res.jsonValue = {
George Liud139c232020-08-18 18:48:57 +08001580 {"@odata.type", "#LogEntry.v1_6_0.LogEntry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001581 {"@odata.id",
1582 "/redfish/v1/Systems/system/LogServices/EventLog/"
1583 "Entries/" +
1584 std::to_string(*id)},
Anthony Wilson27062602019-04-22 02:10:09 -05001585 {"Name", "System Event Log Entry"},
Andrew Geisslercb92c032018-08-17 07:56:14 -07001586 {"Id", std::to_string(*id)},
1587 {"Message", *message},
1588 {"EntryType", "Event"},
1589 {"Severity", translateSeverityDbusToRedfish(*severity)},
George Liud139c232020-08-18 18:48:57 +08001590 {"Created", crow::utility::getDateTime(timestamp)},
1591 {"Modified", crow::utility::getDateTime(updateTimestamp)}};
Andrew Geisslercb92c032018-08-17 07:56:14 -07001592 },
1593 "xyz.openbmc_project.Logging",
1594 "/xyz/openbmc_project/logging/entry/" + entryID,
1595 "org.freedesktop.DBus.Properties", "GetAll",
1596 "xyz.openbmc_project.Logging.Entry");
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001597 }
Chicago Duan336e96c2019-07-15 14:22:08 +08001598
Ed Tanouscb13a392020-07-25 19:02:03 +00001599 void doDelete(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001600 const std::vector<std::string>& params) override
Chicago Duan336e96c2019-07-15 14:22:08 +08001601 {
1602
1603 BMCWEB_LOG_DEBUG << "Do delete single event entries.";
1604
1605 auto asyncResp = std::make_shared<AsyncResp>(res);
1606
1607 if (params.size() != 1)
1608 {
1609 messages::internalError(asyncResp->res);
1610 return;
1611 }
1612 std::string entryID = params[0];
1613
1614 dbus::utility::escapePathForDbus(entryID);
1615
1616 // Process response from Logging service.
1617 auto respHandler = [asyncResp](const boost::system::error_code ec) {
1618 BMCWEB_LOG_DEBUG << "EventLogEntry (DBus) doDelete callback: Done";
1619 if (ec)
1620 {
1621 // TODO Handle for specific error code
1622 BMCWEB_LOG_ERROR
1623 << "EventLogEntry (DBus) doDelete respHandler got error "
1624 << ec;
1625 asyncResp->res.result(
1626 boost::beast::http::status::internal_server_error);
1627 return;
1628 }
1629
1630 asyncResp->res.result(boost::beast::http::status::ok);
1631 };
1632
1633 // Make call to Logging service to request Delete Log
1634 crow::connections::systemBus->async_method_call(
1635 respHandler, "xyz.openbmc_project.Logging",
1636 "/xyz/openbmc_project/logging/entry/" + entryID,
1637 "xyz.openbmc_project.Object.Delete", "Delete");
1638 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001639};
1640
1641class BMCLogServiceCollection : public Node
1642{
1643 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001644 BMCLogServiceCollection(App& app) :
Ed Tanous4ed77cd2018-10-15 08:08:07 -07001645 Node(app, "/redfish/v1/Managers/bmc/LogServices/")
Ed Tanous1da66f72018-07-27 16:13:37 -07001646 {
Ed Tanous1da66f72018-07-27 16:13:37 -07001647 entityPrivileges = {
Jason M. Billse1f26342018-07-18 12:12:00 -07001648 {boost::beast::http::verb::get, {{"Login"}}},
1649 {boost::beast::http::verb::head, {{"Login"}}},
1650 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1651 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1652 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1653 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07001654 }
1655
1656 private:
1657 /**
1658 * Functions triggers appropriate requests on DBus
1659 */
Ed Tanouscb13a392020-07-25 19:02:03 +00001660 void doGet(crow::Response& res, const crow::Request&,
1661 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07001662 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001663 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07001664 // Collections don't include the static data added by SubRoute because
1665 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07001666 asyncResp->res.jsonValue["@odata.type"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001667 "#LogServiceCollection.LogServiceCollection";
Jason M. Billse1f26342018-07-18 12:12:00 -07001668 asyncResp->res.jsonValue["@odata.id"] =
1669 "/redfish/v1/Managers/bmc/LogServices";
1670 asyncResp->res.jsonValue["Name"] = "Open BMC Log Services Collection";
1671 asyncResp->res.jsonValue["Description"] =
Ed Tanous1da66f72018-07-27 16:13:37 -07001672 "Collection of LogServices for this Manager";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001673 nlohmann::json& logServiceArray = asyncResp->res.jsonValue["Members"];
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001674 logServiceArray = nlohmann::json::array();
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001675#ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
1676 logServiceArray.push_back(
1677 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump"}});
1678#endif
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001679#ifdef BMCWEB_ENABLE_REDFISH_BMC_JOURNAL
1680 logServiceArray.push_back(
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05001681 {{"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal"}});
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001682#endif
Jason M. Billse1f26342018-07-18 12:12:00 -07001683 asyncResp->res.jsonValue["Members@odata.count"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001684 logServiceArray.size();
Ed Tanous1da66f72018-07-27 16:13:37 -07001685 }
1686};
1687
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001688class BMCJournalLogService : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07001689{
1690 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001691 BMCJournalLogService(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001692 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001693 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001694 entityPrivileges = {
1695 {boost::beast::http::verb::get, {{"Login"}}},
1696 {boost::beast::http::verb::head, {{"Login"}}},
1697 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1698 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1699 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1700 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1701 }
1702
1703 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001704 void doGet(crow::Response& res, const crow::Request&,
1705 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001706 {
1707 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001708 asyncResp->res.jsonValue["@odata.type"] =
1709 "#LogService.v1_1_0.LogService";
Ed Tanous0f74e642018-11-12 15:17:05 -08001710 asyncResp->res.jsonValue["@odata.id"] =
1711 "/redfish/v1/Managers/bmc/LogServices/Journal";
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001712 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Log Service";
1713 asyncResp->res.jsonValue["Description"] = "BMC Journal Log Service";
1714 asyncResp->res.jsonValue["Id"] = "BMC Journal";
Jason M. Billse1f26342018-07-18 12:12:00 -07001715 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
Jason M. Billscd50aa42019-02-12 17:09:02 -08001716 asyncResp->res.jsonValue["Entries"] = {
1717 {"@odata.id",
Ed Tanous086be232019-05-23 11:47:09 -07001718 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07001719 }
1720};
1721
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001722static int fillBMCJournalLogEntryJson(const std::string& bmcJournalLogEntryID,
1723 sd_journal* journal,
1724 nlohmann::json& bmcJournalLogEntryJson)
Jason M. Billse1f26342018-07-18 12:12:00 -07001725{
1726 // Get the Log Entry contents
1727 int ret = 0;
Jason M. Billse1f26342018-07-18 12:12:00 -07001728
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001729 std::string message;
1730 std::string_view syslogID;
1731 ret = getJournalMetadata(journal, "SYSLOG_IDENTIFIER", syslogID);
1732 if (ret < 0)
1733 {
1734 BMCWEB_LOG_ERROR << "Failed to read SYSLOG_IDENTIFIER field: "
1735 << strerror(-ret);
1736 }
1737 if (!syslogID.empty())
1738 {
1739 message += std::string(syslogID) + ": ";
1740 }
1741
Ed Tanous39e77502019-03-04 17:35:53 -08001742 std::string_view msg;
Jason M. Bills16428a12018-11-02 12:42:29 -07001743 ret = getJournalMetadata(journal, "MESSAGE", msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001744 if (ret < 0)
1745 {
1746 BMCWEB_LOG_ERROR << "Failed to read MESSAGE field: " << strerror(-ret);
1747 return 1;
1748 }
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001749 message += std::string(msg);
Jason M. Billse1f26342018-07-18 12:12:00 -07001750
1751 // Get the severity from the PRIORITY field
Ed Tanous271584a2019-07-09 16:24:22 -07001752 long int severity = 8; // Default to an invalid priority
Jason M. Bills16428a12018-11-02 12:42:29 -07001753 ret = getJournalMetadata(journal, "PRIORITY", 10, severity);
Jason M. Billse1f26342018-07-18 12:12:00 -07001754 if (ret < 0)
1755 {
1756 BMCWEB_LOG_ERROR << "Failed to read PRIORITY field: " << strerror(-ret);
Jason M. Billse1f26342018-07-18 12:12:00 -07001757 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001758
1759 // Get the Created time from the timestamp
Jason M. Bills16428a12018-11-02 12:42:29 -07001760 std::string entryTimeStr;
1761 if (!getEntryTimestamp(journal, entryTimeStr))
Jason M. Billse1f26342018-07-18 12:12:00 -07001762 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001763 return 1;
Jason M. Billse1f26342018-07-18 12:12:00 -07001764 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001765
1766 // Fill in the log entry with the gathered data
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001767 bmcJournalLogEntryJson = {
Andrew Geisslercb92c032018-08-17 07:56:14 -07001768 {"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001769 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/" +
1770 bmcJournalLogEntryID},
Jason M. Billse1f26342018-07-18 12:12:00 -07001771 {"Name", "BMC Journal Entry"},
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001772 {"Id", bmcJournalLogEntryID},
Jason M. Billsa8fe54f2020-11-20 15:57:55 -08001773 {"Message", std::move(message)},
Jason M. Billse1f26342018-07-18 12:12:00 -07001774 {"EntryType", "Oem"},
1775 {"Severity",
Jason M. Billsb6a61a52019-08-01 14:26:15 -07001776 severity <= 2 ? "Critical" : severity <= 4 ? "Warning" : "OK"},
Ed Tanous086be232019-05-23 11:47:09 -07001777 {"OemRecordFormat", "BMC Journal Entry"},
Jason M. Billse1f26342018-07-18 12:12:00 -07001778 {"Created", std::move(entryTimeStr)}};
1779 return 0;
1780}
1781
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001782class BMCJournalLogEntryCollection : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001783{
1784 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001785 BMCJournalLogEntryCollection(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001786 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/")
Jason M. Billse1f26342018-07-18 12:12:00 -07001787 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001788 entityPrivileges = {
1789 {boost::beast::http::verb::get, {{"Login"}}},
1790 {boost::beast::http::verb::head, {{"Login"}}},
1791 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1792 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1793 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1794 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1795 }
1796
1797 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001798 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00001799 const std::vector<std::string>&) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001800 {
1801 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001802 static constexpr const long maxEntriesPerPage = 1000;
Ed Tanous271584a2019-07-09 16:24:22 -07001803 uint64_t skip = 0;
1804 uint64_t top = maxEntriesPerPage; // Show max entries by default
Jason M. Bills16428a12018-11-02 12:42:29 -07001805 if (!getSkipParam(asyncResp->res, req, skip))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001806 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001807 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001808 }
Jason M. Bills16428a12018-11-02 12:42:29 -07001809 if (!getTopParam(asyncResp->res, req, top))
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001810 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001811 return;
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001812 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001813 // Collections don't include the static data added by SubRoute because
1814 // it has a duplicate entry for members
1815 asyncResp->res.jsonValue["@odata.type"] =
1816 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08001817 asyncResp->res.jsonValue["@odata.id"] =
1818 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001819 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001820 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07001821 asyncResp->res.jsonValue["Name"] = "Open BMC Journal Entries";
1822 asyncResp->res.jsonValue["Description"] =
1823 "Collection of BMC Journal Entries";
Ed Tanous0f74e642018-11-12 15:17:05 -08001824 asyncResp->res.jsonValue["@odata.id"] =
1825 "/redfish/v1/Managers/bmc/LogServices/BmcLog/Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001826 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07001827 logEntryArray = nlohmann::json::array();
1828
1829 // Go through the journal and use the timestamp to create a unique ID
1830 // for each entry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001831 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001832 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1833 if (ret < 0)
1834 {
1835 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001836 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001837 return;
1838 }
1839 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1840 journalTmp, sd_journal_close);
1841 journalTmp = nullptr;
Ed Tanousb01bf292019-03-25 19:25:26 +00001842 uint64_t entryCount = 0;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001843 // Reset the unique ID on the first entry
1844 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001845 SD_JOURNAL_FOREACH(journal.get())
1846 {
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001847 entryCount++;
1848 // Handle paging using skip (number of entries to skip from the
1849 // start) and top (number of entries to display)
1850 if (entryCount <= skip || entryCount > skip + top)
1851 {
1852 continue;
1853 }
1854
Jason M. Bills16428a12018-11-02 12:42:29 -07001855 std::string idStr;
Jason M. Billse85d6b12019-07-29 17:01:15 -07001856 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
Jason M. Billse1f26342018-07-18 12:12:00 -07001857 {
Jason M. Billse1f26342018-07-18 12:12:00 -07001858 continue;
1859 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001860
Jason M. Billse85d6b12019-07-29 17:01:15 -07001861 if (firstEntry)
1862 {
1863 firstEntry = false;
1864 }
1865
Jason M. Billse1f26342018-07-18 12:12:00 -07001866 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001867 nlohmann::json& bmcJournalLogEntry = logEntryArray.back();
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001868 if (fillBMCJournalLogEntryJson(idStr, journal.get(),
1869 bmcJournalLogEntry) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001870 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001871 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001872 return;
1873 }
1874 }
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001875 asyncResp->res.jsonValue["Members@odata.count"] = entryCount;
1876 if (skip + top < entryCount)
1877 {
1878 asyncResp->res.jsonValue["Members@odata.nextLink"] =
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001879 "/redfish/v1/Managers/bmc/LogServices/Journal/Entries?$skip=" +
Jason M. Bills193ad2f2018-09-26 15:08:52 -07001880 std::to_string(skip + top);
1881 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001882 }
1883};
1884
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001885class BMCJournalLogEntry : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07001886{
1887 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001888 BMCJournalLogEntry(App& app) :
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001889 Node(app, "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/",
Jason M. Billse1f26342018-07-18 12:12:00 -07001890 std::string())
1891 {
1892 entityPrivileges = {
1893 {boost::beast::http::verb::get, {{"Login"}}},
1894 {boost::beast::http::verb::head, {{"Login"}}},
1895 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1896 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1897 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1898 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1899 }
1900
1901 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001902 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001903 const std::vector<std::string>& params) override
Jason M. Billse1f26342018-07-18 12:12:00 -07001904 {
1905 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1906 if (params.size() != 1)
1907 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001908 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001909 return;
1910 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001911 const std::string& entryID = params[0];
Jason M. Billse1f26342018-07-18 12:12:00 -07001912 // Convert the unique ID back to a timestamp to find the entry
Jason M. Billse1f26342018-07-18 12:12:00 -07001913 uint64_t ts = 0;
Ed Tanous271584a2019-07-09 16:24:22 -07001914 uint64_t index = 0;
Jason M. Bills16428a12018-11-02 12:42:29 -07001915 if (!getTimestampFromID(asyncResp->res, entryID, ts, index))
Jason M. Billse1f26342018-07-18 12:12:00 -07001916 {
Jason M. Bills16428a12018-11-02 12:42:29 -07001917 return;
Jason M. Billse1f26342018-07-18 12:12:00 -07001918 }
1919
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001920 sd_journal* journalTmp = nullptr;
Jason M. Billse1f26342018-07-18 12:12:00 -07001921 int ret = sd_journal_open(&journalTmp, SD_JOURNAL_LOCAL_ONLY);
1922 if (ret < 0)
1923 {
1924 BMCWEB_LOG_ERROR << "failed to open journal: " << strerror(-ret);
Jason M. Billsf12894f2018-10-09 12:45:45 -07001925 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001926 return;
1927 }
1928 std::unique_ptr<sd_journal, decltype(&sd_journal_close)> journal(
1929 journalTmp, sd_journal_close);
1930 journalTmp = nullptr;
1931 // Go to the timestamp in the log and move to the entry at the index
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001932 // tracking the unique ID
1933 std::string idStr;
1934 bool firstEntry = true;
Jason M. Billse1f26342018-07-18 12:12:00 -07001935 ret = sd_journal_seek_realtime_usec(journal.get(), ts);
Manojkiran Eda2056b6d2020-05-28 08:57:36 +05301936 if (ret < 0)
1937 {
1938 BMCWEB_LOG_ERROR << "failed to seek to an entry in journal"
1939 << strerror(-ret);
1940 messages::internalError(asyncResp->res);
1941 return;
1942 }
Ed Tanous271584a2019-07-09 16:24:22 -07001943 for (uint64_t i = 0; i <= index; i++)
Jason M. Billse1f26342018-07-18 12:12:00 -07001944 {
1945 sd_journal_next(journal.get());
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001946 if (!getUniqueEntryID(journal.get(), idStr, firstEntry))
1947 {
1948 messages::internalError(asyncResp->res);
1949 return;
1950 }
1951 if (firstEntry)
1952 {
1953 firstEntry = false;
1954 }
Jason M. Billse1f26342018-07-18 12:12:00 -07001955 }
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001956 // Confirm that the entry ID matches what was requested
Jason M. Billsaf07e3f2019-08-01 14:41:39 -07001957 if (idStr != entryID)
Jason M. Billsc4bf6372018-11-05 13:48:27 -08001958 {
1959 messages::resourceMissingAtURI(asyncResp->res, entryID);
1960 return;
1961 }
1962
1963 if (fillBMCJournalLogEntryJson(entryID, journal.get(),
1964 asyncResp->res.jsonValue) != 0)
Jason M. Billse1f26342018-07-18 12:12:00 -07001965 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07001966 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07001967 return;
1968 }
1969 }
1970};
1971
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001972class BMCDumpService : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06001973{
1974 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07001975 BMCDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001976 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/")
raviteja-bc9bb6862020-02-03 11:53:32 -06001977 {
1978 entityPrivileges = {
1979 {boost::beast::http::verb::get, {{"Login"}}},
1980 {boost::beast::http::verb::head, {{"Login"}}},
1981 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
1982 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
1983 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
1984 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
1985 }
1986
1987 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00001988 void doGet(crow::Response& res, const crow::Request&,
1989 const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06001990 {
1991 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
1992
1993 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001994 "/redfish/v1/Managers/bmc/LogServices/Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06001995 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05001996 "#LogService.v1_2_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05001997 asyncResp->res.jsonValue["Name"] = "Dump LogService";
1998 asyncResp->res.jsonValue["Description"] = "BMC Dump LogService";
1999 asyncResp->res.jsonValue["Id"] = "Dump";
raviteja-bc9bb6862020-02-03 11:53:32 -06002000 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
raviteja-bc9bb6862020-02-03 11:53:32 -06002001 asyncResp->res.jsonValue["Entries"] = {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002002 {"@odata.id", "/redfish/v1/Managers/bmc/LogServices/Dump/Entries"}};
2003 asyncResp->res.jsonValue["Actions"] = {
2004 {"#LogService.ClearLog",
2005 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2006 "Actions/LogService.ClearLog"}}},
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002007 {"#LogService.CollectDiagnosticData",
2008 {{"target", "/redfish/v1/Managers/bmc/LogServices/Dump/"
2009 "Actions/LogService.CollectDiagnosticData"}}}};
raviteja-bc9bb6862020-02-03 11:53:32 -06002010 }
2011};
2012
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002013class BMCDumpEntryCollection : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002014{
2015 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002016 BMCDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002017 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/")
raviteja-bc9bb6862020-02-03 11:53:32 -06002018 {
2019 entityPrivileges = {
2020 {boost::beast::http::verb::get, {{"Login"}}},
2021 {boost::beast::http::verb::head, {{"Login"}}},
2022 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2023 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2024 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2025 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2026 }
2027
2028 private:
2029 /**
2030 * Functions triggers appropriate requests on DBus
2031 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002032 void doGet(crow::Response& res, const crow::Request&,
2033 const std::vector<std::string>&) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002034 {
2035 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2036
2037 asyncResp->res.jsonValue["@odata.type"] =
2038 "#LogEntryCollection.LogEntryCollection";
2039 asyncResp->res.jsonValue["@odata.id"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002040 "/redfish/v1/Managers/bmc/LogServices/Dump/Entries";
2041 asyncResp->res.jsonValue["Name"] = "BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002042 asyncResp->res.jsonValue["Description"] =
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002043 "Collection of BMC Dump Entries";
raviteja-bc9bb6862020-02-03 11:53:32 -06002044
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002045 getDumpEntryCollection(asyncResp, "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002046 }
2047};
2048
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002049class BMCDumpEntry : public Node
raviteja-bc9bb6862020-02-03 11:53:32 -06002050{
2051 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002052 BMCDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002053 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/Entries/<str>/",
raviteja-bc9bb6862020-02-03 11:53:32 -06002054 std::string())
2055 {
2056 entityPrivileges = {
2057 {boost::beast::http::verb::get, {{"Login"}}},
2058 {boost::beast::http::verb::head, {{"Login"}}},
2059 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2060 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2061 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2062 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2063 }
2064
2065 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002066 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002067 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002068 {
2069 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2070 if (params.size() != 1)
2071 {
2072 messages::internalError(asyncResp->res);
2073 return;
2074 }
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002075 getDumpEntryById(asyncResp, params[0], "BMC");
raviteja-bc9bb6862020-02-03 11:53:32 -06002076 }
2077
Ed Tanouscb13a392020-07-25 19:02:03 +00002078 void doDelete(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002079 const std::vector<std::string>& params) override
raviteja-bc9bb6862020-02-03 11:53:32 -06002080 {
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002081 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002082 if (params.size() != 1)
2083 {
2084 messages::internalError(asyncResp->res);
2085 return;
2086 }
Stanley Chu98782562020-11-04 16:10:24 +08002087 deleteDumpEntry(asyncResp, params[0], "bmc");
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002088 }
2089};
raviteja-bc9bb6862020-02-03 11:53:32 -06002090
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002091class BMCDumpCreate : public Node
2092{
2093 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002094 BMCDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002095 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002096 "Actions/"
2097 "LogService.CollectDiagnosticData/")
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002098 {
2099 entityPrivileges = {
2100 {boost::beast::http::verb::get, {{"Login"}}},
2101 {boost::beast::http::verb::head, {{"Login"}}},
2102 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2103 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2104 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2105 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2106 }
2107
2108 private:
2109 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002110 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002111 {
2112 createDump(res, req, "BMC");
2113 }
2114};
2115
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002116class BMCDumpClear : public Node
2117{
2118 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002119 BMCDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002120 Node(app, "/redfish/v1/Managers/bmc/LogServices/Dump/"
2121 "Actions/"
2122 "LogService.ClearLog/")
2123 {
2124 entityPrivileges = {
2125 {boost::beast::http::verb::get, {{"Login"}}},
2126 {boost::beast::http::verb::head, {{"Login"}}},
2127 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2128 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2129 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2130 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2131 }
2132
2133 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002134 void doPost(crow::Response& res, const crow::Request&,
2135 const std::vector<std::string>&) override
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002136 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -05002137 clearDump(res, "BMC");
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002138 }
2139};
2140
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002141class SystemDumpService : public Node
2142{
2143 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002144 SystemDumpService(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002145 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/")
2146 {
2147 entityPrivileges = {
2148 {boost::beast::http::verb::get, {{"Login"}}},
2149 {boost::beast::http::verb::head, {{"Login"}}},
2150 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2151 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2152 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2153 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2154 }
raviteja-bc9bb6862020-02-03 11:53:32 -06002155
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002156 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002157 void doGet(crow::Response& res, const crow::Request&,
2158 const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002159 {
2160 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
raviteja-bc9bb6862020-02-03 11:53:32 -06002161
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002162 asyncResp->res.jsonValue["@odata.id"] =
2163 "/redfish/v1/Systems/system/LogServices/Dump";
2164 asyncResp->res.jsonValue["@odata.type"] =
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002165 "#LogService.v1_2_0.LogService";
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002166 asyncResp->res.jsonValue["Name"] = "Dump LogService";
2167 asyncResp->res.jsonValue["Description"] = "System Dump LogService";
2168 asyncResp->res.jsonValue["Id"] = "Dump";
2169 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2170 asyncResp->res.jsonValue["Entries"] = {
2171 {"@odata.id",
2172 "/redfish/v1/Systems/system/LogServices/Dump/Entries"}};
2173 asyncResp->res.jsonValue["Actions"] = {
2174 {"#LogService.ClearLog",
2175 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2176 "LogService.ClearLog"}}},
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002177 {"#LogService.CollectDiagnosticData",
2178 {{"target", "/redfish/v1/Systems/system/LogServices/Dump/Actions/"
2179 "LogService.CollectDiagnosticData"}}}};
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002180 }
2181};
2182
2183class SystemDumpEntryCollection : public Node
2184{
2185 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002186 SystemDumpEntryCollection(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002187 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/")
2188 {
2189 entityPrivileges = {
2190 {boost::beast::http::verb::get, {{"Login"}}},
2191 {boost::beast::http::verb::head, {{"Login"}}},
2192 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2193 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2194 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2195 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2196 }
2197
2198 private:
2199 /**
2200 * Functions triggers appropriate requests on DBus
2201 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002202 void doGet(crow::Response& res, const crow::Request&,
2203 const std::vector<std::string>&) override
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002204 {
2205 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2206
2207 asyncResp->res.jsonValue["@odata.type"] =
2208 "#LogEntryCollection.LogEntryCollection";
2209 asyncResp->res.jsonValue["@odata.id"] =
2210 "/redfish/v1/Systems/system/LogServices/Dump/Entries";
2211 asyncResp->res.jsonValue["Name"] = "System Dump Entries";
2212 asyncResp->res.jsonValue["Description"] =
2213 "Collection of System Dump Entries";
2214
2215 getDumpEntryCollection(asyncResp, "System");
2216 }
2217};
2218
2219class SystemDumpEntry : public Node
2220{
2221 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002222 SystemDumpEntry(App& app) :
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002223 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/Entries/<str>/",
2224 std::string())
2225 {
2226 entityPrivileges = {
2227 {boost::beast::http::verb::get, {{"Login"}}},
2228 {boost::beast::http::verb::head, {{"Login"}}},
2229 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2230 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2231 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2232 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2233 }
2234
2235 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002236 void doGet(crow::Response& res, const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002237 const std::vector<std::string>& params) override
2238 {
2239 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2240 if (params.size() != 1)
2241 {
2242 messages::internalError(asyncResp->res);
2243 return;
2244 }
2245 getDumpEntryById(asyncResp, params[0], "System");
2246 }
2247
Ed Tanouscb13a392020-07-25 19:02:03 +00002248 void doDelete(crow::Response& res, const crow::Request&,
Asmitha Karunanithi5cb1dd22020-05-07 04:35:02 -05002249 const std::vector<std::string>& params) override
2250 {
2251 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2252 if (params.size() != 1)
2253 {
2254 messages::internalError(asyncResp->res);
2255 return;
2256 }
Stanley Chu98782562020-11-04 16:10:24 +08002257 deleteDumpEntry(asyncResp, params[0], "system");
raviteja-bc9bb6862020-02-03 11:53:32 -06002258 }
2259};
2260
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002261class SystemDumpCreate : public Node
2262{
2263 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002264 SystemDumpCreate(App& app) :
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002265 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
Asmitha Karunanithid337bb72020-09-21 10:34:02 -05002266 "Actions/"
2267 "LogService.CollectDiagnosticData/")
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002268 {
2269 entityPrivileges = {
2270 {boost::beast::http::verb::get, {{"Login"}}},
2271 {boost::beast::http::verb::head, {{"Login"}}},
2272 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2273 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2274 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2275 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2276 }
2277
2278 private:
2279 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002280 const std::vector<std::string>&) override
Asmitha Karunanithia43be802020-05-07 05:05:36 -05002281 {
2282 createDump(res, req, "System");
2283 }
2284};
2285
raviteja-b013487e2020-03-03 03:20:48 -06002286class SystemDumpClear : public Node
2287{
2288 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002289 SystemDumpClear(App& app) :
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002290 Node(app, "/redfish/v1/Systems/system/LogServices/Dump/"
raviteja-b013487e2020-03-03 03:20:48 -06002291 "Actions/"
2292 "LogService.ClearLog/")
2293 {
2294 entityPrivileges = {
2295 {boost::beast::http::verb::get, {{"Login"}}},
2296 {boost::beast::http::verb::head, {{"Login"}}},
Asmitha Karunanithi80319af2020-05-07 05:30:21 -05002297 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2298 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2299 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
raviteja-b013487e2020-03-03 03:20:48 -06002300 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2301 }
2302
2303 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002304 void doPost(crow::Response& res, const crow::Request&,
2305 const std::vector<std::string>&) override
raviteja-b013487e2020-03-03 03:20:48 -06002306 {
Asmitha Karunanithib47452b2020-09-25 02:02:19 -05002307 clearDump(res, "System");
raviteja-b013487e2020-03-03 03:20:48 -06002308 }
2309};
2310
Jason M. Bills424c4172019-03-21 13:50:33 -07002311class CrashdumpService : public Node
Jason M. Billse1f26342018-07-18 12:12:00 -07002312{
2313 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002314 CrashdumpService(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002315 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002316 {
AppaRao Puli39460282020-04-07 17:03:04 +05302317 // Note: Deviated from redfish privilege registry for GET & HEAD
2318 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002319 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302320 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2321 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002322 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2323 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2324 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2325 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002326 }
2327
2328 private:
2329 /**
2330 * Functions triggers appropriate requests on DBus
2331 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002332 void doGet(crow::Response& res, const crow::Request&,
2333 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002334 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002335 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002336 // Copy over the static data to include the entries added by SubRoute
Ed Tanous0f74e642018-11-12 15:17:05 -08002337 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002338 "/redfish/v1/Systems/system/LogServices/Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002339 asyncResp->res.jsonValue["@odata.type"] =
2340 "#LogService.v1_1_0.LogService";
Gunnar Mills4f50ae42020-02-06 15:29:57 -06002341 asyncResp->res.jsonValue["Name"] = "Open BMC Oem Crashdump Service";
2342 asyncResp->res.jsonValue["Description"] = "Oem Crashdump Service";
2343 asyncResp->res.jsonValue["Id"] = "Oem Crashdump";
Jason M. Billse1f26342018-07-18 12:12:00 -07002344 asyncResp->res.jsonValue["OverWritePolicy"] = "WrapsWhenFull";
2345 asyncResp->res.jsonValue["MaxNumberOfRecords"] = 3;
Jason M. Billscd50aa42019-02-12 17:09:02 -08002346 asyncResp->res.jsonValue["Entries"] = {
2347 {"@odata.id",
Jason M. Bills424c4172019-03-21 13:50:33 -07002348 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries"}};
Jason M. Billse1f26342018-07-18 12:12:00 -07002349 asyncResp->res.jsonValue["Actions"] = {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002350 {"#LogService.ClearLog",
2351 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2352 "Actions/LogService.ClearLog"}}},
Ed Tanous1da66f72018-07-27 16:13:37 -07002353 {"Oem",
Jason M. Bills424c4172019-03-21 13:50:33 -07002354 {{"#Crashdump.OnDemand",
2355 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002356 "Actions/Oem/Crashdump.OnDemand"}}},
2357 {"#Crashdump.Telemetry",
2358 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2359 "Actions/Oem/Crashdump.Telemetry"}}}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002360
2361#ifdef BMCWEB_ENABLE_REDFISH_RAW_PECI
Jason M. Billse1f26342018-07-18 12:12:00 -07002362 asyncResp->res.jsonValue["Actions"]["Oem"].push_back(
Jason M. Bills424c4172019-03-21 13:50:33 -07002363 {"#Crashdump.SendRawPeci",
Anthony Wilson08a4e4b2019-04-12 08:23:05 -05002364 {{"target", "/redfish/v1/Systems/system/LogServices/Crashdump/"
2365 "Actions/Oem/Crashdump.SendRawPeci"}}});
Ed Tanous1da66f72018-07-27 16:13:37 -07002366#endif
Ed Tanous1da66f72018-07-27 16:13:37 -07002367 }
2368};
2369
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002370class CrashdumpClear : public Node
2371{
2372 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002373 CrashdumpClear(App& app) :
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002374 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/"
2375 "LogService.ClearLog/")
2376 {
AppaRao Puli39460282020-04-07 17:03:04 +05302377 // Note: Deviated from redfish privilege registry for GET & HEAD
2378 // method for security reasons.
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002379 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302380 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2381 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002382 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2383 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2384 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2385 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2386 }
2387
2388 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002389 void doPost(crow::Response& res, const crow::Request&,
2390 const std::vector<std::string>&) override
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002391 {
2392 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2393
2394 crow::connections::systemBus->async_method_call(
2395 [asyncResp](const boost::system::error_code ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002396 const std::string&) {
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002397 if (ec)
2398 {
2399 messages::internalError(asyncResp->res);
2400 return;
2401 }
2402 messages::success(asyncResp->res);
2403 },
2404 crashdumpObject, crashdumpPath, deleteAllInterface, "DeleteAll");
2405 }
2406};
2407
Ed Tanousb5a76932020-09-29 16:16:58 -07002408static void logCrashdumpEntry(const std::shared_ptr<AsyncResp>& asyncResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002409 const std::string& logID,
2410 nlohmann::json& logEntryJson)
Jason M. Billse855dd22019-10-08 11:37:48 -07002411{
Johnathan Mantey043a0532020-03-10 17:15:28 -07002412 auto getStoredLogCallback =
2413 [asyncResp, logID, &logEntryJson](
2414 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002415 const std::vector<std::pair<std::string, VariantType>>& params) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002416 if (ec)
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002417 {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002418 BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message();
2419 if (ec.value() ==
2420 boost::system::linux_error::bad_request_descriptor)
2421 {
2422 messages::resourceNotFound(asyncResp->res, "LogEntry",
2423 logID);
2424 }
2425 else
2426 {
2427 messages::internalError(asyncResp->res);
2428 }
2429 return;
Jason M. Bills1ddcf012019-11-26 14:59:21 -08002430 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002431
Johnathan Mantey043a0532020-03-10 17:15:28 -07002432 std::string timestamp{};
2433 std::string filename{};
2434 std::string logfile{};
Ed Tanous2c70f802020-09-28 14:29:23 -07002435 parseCrashdumpParameters(params, filename, timestamp, logfile);
Johnathan Mantey043a0532020-03-10 17:15:28 -07002436
2437 if (filename.empty() || timestamp.empty())
2438 {
2439 messages::resourceMissingAtURI(asyncResp->res, logID);
2440 return;
2441 }
2442
2443 std::string crashdumpURI =
2444 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/" +
2445 logID + "/" + filename;
2446 logEntryJson = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
2447 {"@odata.id", "/redfish/v1/Systems/system/"
2448 "LogServices/Crashdump/Entries/" +
2449 logID},
2450 {"Name", "CPU Crashdump"},
2451 {"Id", logID},
2452 {"EntryType", "Oem"},
2453 {"OemRecordFormat", "Crashdump URI"},
2454 {"Message", std::move(crashdumpURI)},
2455 {"Created", std::move(timestamp)}};
2456 };
Jason M. Billse855dd22019-10-08 11:37:48 -07002457 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002458 std::move(getStoredLogCallback), crashdumpObject,
2459 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002460 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Jason M. Billse855dd22019-10-08 11:37:48 -07002461}
2462
Jason M. Bills424c4172019-03-21 13:50:33 -07002463class CrashdumpEntryCollection : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002464{
2465 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002466 CrashdumpEntryCollection(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002467 Node(app, "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002468 {
AppaRao Puli39460282020-04-07 17:03:04 +05302469 // Note: Deviated from redfish privilege registry for GET & HEAD
2470 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002471 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302472 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2473 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002474 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2475 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2476 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2477 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002478 }
2479
2480 private:
2481 /**
2482 * Functions triggers appropriate requests on DBus
2483 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002484 void doGet(crow::Response& res, const crow::Request&,
2485 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002486 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002487 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002488 // Collections don't include the static data added by SubRoute because
2489 // it has a duplicate entry for members
Jason M. Billse1f26342018-07-18 12:12:00 -07002490 auto getLogEntriesCallback = [asyncResp](
2491 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002492 const std::vector<std::string>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002493 if (ec)
2494 {
2495 if (ec.value() !=
2496 boost::system::errc::no_such_file_or_directory)
Ed Tanous1da66f72018-07-27 16:13:37 -07002497 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002498 BMCWEB_LOG_DEBUG << "failed to get entries ec: "
2499 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002500 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002501 return;
Ed Tanous1da66f72018-07-27 16:13:37 -07002502 }
Jason M. Billse1f26342018-07-18 12:12:00 -07002503 }
2504 asyncResp->res.jsonValue["@odata.type"] =
2505 "#LogEntryCollection.LogEntryCollection";
Ed Tanous0f74e642018-11-12 15:17:05 -08002506 asyncResp->res.jsonValue["@odata.id"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002507 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries";
Jason M. Bills424c4172019-03-21 13:50:33 -07002508 asyncResp->res.jsonValue["Name"] = "Open BMC Crashdump Entries";
Jason M. Billse1f26342018-07-18 12:12:00 -07002509 asyncResp->res.jsonValue["Description"] =
Jason M. Bills424c4172019-03-21 13:50:33 -07002510 "Collection of Crashdump Entries";
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002511 nlohmann::json& logEntryArray = asyncResp->res.jsonValue["Members"];
Jason M. Billse1f26342018-07-18 12:12:00 -07002512 logEntryArray = nlohmann::json::array();
Jason M. Billse855dd22019-10-08 11:37:48 -07002513 std::vector<std::string> logIDs;
2514 // Get the list of log entries and build up an empty array big
2515 // enough to hold them
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002516 for (const std::string& objpath : resp)
Jason M. Billse1f26342018-07-18 12:12:00 -07002517 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002518 // Get the log ID
Ed Tanousf23b7292020-10-15 09:41:17 -07002519 std::size_t lastPos = objpath.rfind('/');
Jason M. Billse855dd22019-10-08 11:37:48 -07002520 if (lastPos == std::string::npos)
Jason M. Billse1f26342018-07-18 12:12:00 -07002521 {
Jason M. Billse855dd22019-10-08 11:37:48 -07002522 continue;
Jason M. Billse1f26342018-07-18 12:12:00 -07002523 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002524 logIDs.emplace_back(objpath.substr(lastPos + 1));
2525
2526 // Add a space for the log entry to the array
2527 logEntryArray.push_back({});
2528 }
2529 // Now go through and set up async calls to fill in the entries
2530 size_t index = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002531 for (const std::string& logID : logIDs)
Jason M. Billse855dd22019-10-08 11:37:48 -07002532 {
2533 // Add the log entry to the array
2534 logCrashdumpEntry(asyncResp, logID, logEntryArray[index++]);
Jason M. Billse1f26342018-07-18 12:12:00 -07002535 }
2536 asyncResp->res.jsonValue["Members@odata.count"] =
2537 logEntryArray.size();
2538 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002539 crow::connections::systemBus->async_method_call(
2540 std::move(getLogEntriesCallback),
2541 "xyz.openbmc_project.ObjectMapper",
2542 "/xyz/openbmc_project/object_mapper",
2543 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002544 std::array<const char*, 1>{crashdumpInterface});
Ed Tanous1da66f72018-07-27 16:13:37 -07002545 }
2546};
2547
Jason M. Bills424c4172019-03-21 13:50:33 -07002548class CrashdumpEntry : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002549{
2550 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002551 CrashdumpEntry(App& app) :
Jason M. Billsd53dd412019-02-12 17:16:22 -08002552 Node(app,
Jason M. Bills424c4172019-03-21 13:50:33 -07002553 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/",
Ed Tanous1da66f72018-07-27 16:13:37 -07002554 std::string())
2555 {
AppaRao Puli39460282020-04-07 17:03:04 +05302556 // Note: Deviated from redfish privilege registry for GET & HEAD
2557 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002558 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302559 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2560 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse1f26342018-07-18 12:12:00 -07002561 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2562 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2563 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2564 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002565 }
2566
2567 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002568 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002569 const std::vector<std::string>& params) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002570 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002571 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002572 if (params.size() != 1)
2573 {
Jason M. Billsf12894f2018-10-09 12:45:45 -07002574 messages::internalError(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002575 return;
2576 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002577 const std::string& logID = params[0];
Jason M. Billse855dd22019-10-08 11:37:48 -07002578 logCrashdumpEntry(asyncResp, logID, asyncResp->res.jsonValue);
2579 }
2580};
2581
2582class CrashdumpFile : public Node
2583{
2584 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002585 CrashdumpFile(App& app) :
Jason M. Billse855dd22019-10-08 11:37:48 -07002586 Node(app,
2587 "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/"
2588 "<str>/",
2589 std::string(), std::string())
2590 {
AppaRao Puli39460282020-04-07 17:03:04 +05302591 // Note: Deviated from redfish privilege registry for GET & HEAD
2592 // method for security reasons.
Jason M. Billse855dd22019-10-08 11:37:48 -07002593 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302594 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2595 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
Jason M. Billse855dd22019-10-08 11:37:48 -07002596 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2597 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2598 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2599 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2600 }
2601
2602 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002603 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002604 const std::vector<std::string>& params) override
Jason M. Billse855dd22019-10-08 11:37:48 -07002605 {
2606 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2607 if (params.size() != 2)
2608 {
2609 messages::internalError(asyncResp->res);
2610 return;
2611 }
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002612 const std::string& logID = params[0];
2613 const std::string& fileName = params[1];
Jason M. Billse855dd22019-10-08 11:37:48 -07002614
Johnathan Mantey043a0532020-03-10 17:15:28 -07002615 auto getStoredLogCallback =
2616 [asyncResp, logID, fileName](
2617 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002618 const std::vector<std::pair<std::string, VariantType>>& resp) {
Johnathan Mantey043a0532020-03-10 17:15:28 -07002619 if (ec)
2620 {
2621 BMCWEB_LOG_DEBUG << "failed to get log ec: "
2622 << ec.message();
2623 messages::internalError(asyncResp->res);
2624 return;
2625 }
Jason M. Billse855dd22019-10-08 11:37:48 -07002626
Johnathan Mantey043a0532020-03-10 17:15:28 -07002627 std::string dbusFilename{};
2628 std::string dbusTimestamp{};
2629 std::string dbusFilepath{};
Jason M. Billse855dd22019-10-08 11:37:48 -07002630
Ed Tanous2c70f802020-09-28 14:29:23 -07002631 parseCrashdumpParameters(resp, dbusFilename, dbusTimestamp,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002632 dbusFilepath);
2633
2634 if (dbusFilename.empty() || dbusTimestamp.empty() ||
2635 dbusFilepath.empty())
2636 {
2637 messages::resourceMissingAtURI(asyncResp->res, fileName);
2638 return;
2639 }
2640
2641 // Verify the file name parameter is correct
2642 if (fileName != dbusFilename)
2643 {
2644 messages::resourceMissingAtURI(asyncResp->res, fileName);
2645 return;
2646 }
2647
2648 if (!std::filesystem::exists(dbusFilepath))
2649 {
2650 messages::resourceMissingAtURI(asyncResp->res, fileName);
2651 return;
2652 }
2653 std::ifstream ifs(dbusFilepath, std::ios::in |
2654 std::ios::binary |
2655 std::ios::ate);
2656 std::ifstream::pos_type fileSize = ifs.tellg();
2657 if (fileSize < 0)
2658 {
2659 messages::generalError(asyncResp->res);
2660 return;
2661 }
2662 ifs.seekg(0, std::ios::beg);
2663
2664 auto crashData = std::make_unique<char[]>(
2665 static_cast<unsigned int>(fileSize));
2666
2667 ifs.read(crashData.get(), static_cast<int>(fileSize));
2668
2669 // The cast to std::string is intentional in order to use the
2670 // assign() that applies move mechanics
2671 asyncResp->res.body().assign(
2672 static_cast<std::string>(crashData.get()));
2673
2674 // Configure this to be a file download when accessed from
2675 // a browser
2676 asyncResp->res.addHeader("Content-Disposition", "attachment");
2677 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002678 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002679 std::move(getStoredLogCallback), crashdumpObject,
2680 crashdumpPath + std::string("/") + logID,
Johnathan Mantey043a0532020-03-10 17:15:28 -07002681 "org.freedesktop.DBus.Properties", "GetAll", crashdumpInterface);
Ed Tanous1da66f72018-07-27 16:13:37 -07002682 }
2683};
2684
Jason M. Bills424c4172019-03-21 13:50:33 -07002685class OnDemandCrashdump : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002686{
2687 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002688 OnDemandCrashdump(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002689 Node(app,
2690 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2691 "Crashdump.OnDemand/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002692 {
AppaRao Puli39460282020-04-07 17:03:04 +05302693 // Note: Deviated from redfish privilege registry for GET & HEAD
2694 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002695 entityPrivileges = {
AppaRao Puli39460282020-04-07 17:03:04 +05302696 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2697 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2698 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2699 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2700 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2701 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
Ed Tanous1da66f72018-07-27 16:13:37 -07002702 }
2703
2704 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002705 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002706 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002707 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002708 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002709
James Feistfe306722020-03-12 16:32:08 -07002710 auto generateonDemandLogCallback = [asyncResp,
2711 req](const boost::system::error_code
2712 ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002713 const std::string&) {
James Feist46229572020-02-19 15:11:58 -08002714 if (ec)
2715 {
2716 if (ec.value() == boost::system::errc::operation_not_supported)
Ed Tanous1da66f72018-07-27 16:13:37 -07002717 {
James Feist46229572020-02-19 15:11:58 -08002718 messages::resourceInStandby(asyncResp->res);
Ed Tanous1da66f72018-07-27 16:13:37 -07002719 }
James Feist46229572020-02-19 15:11:58 -08002720 else if (ec.value() ==
2721 boost::system::errc::device_or_resource_busy)
2722 {
2723 messages::serviceTemporarilyUnavailable(asyncResp->res,
2724 "60");
2725 }
2726 else
2727 {
2728 messages::internalError(asyncResp->res);
2729 }
2730 return;
2731 }
2732 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002733 [](boost::system::error_code err, sdbusplus::message::message&,
2734 const std::shared_ptr<task::TaskData>& taskData) {
James Feist66afe4f2020-02-24 13:09:58 -08002735 if (!err)
2736 {
James Feiste5d50062020-05-11 17:29:00 -07002737 taskData->messages.emplace_back(
2738 messages::taskCompletedOK(
2739 std::to_string(taskData->index)));
James Feist831d6b02020-03-12 16:31:30 -07002740 taskData->state = "Completed";
James Feist66afe4f2020-02-24 13:09:58 -08002741 }
James Feist32898ce2020-03-10 16:16:52 -07002742 return task::completed;
James Feist66afe4f2020-02-24 13:09:58 -08002743 },
James Feist46229572020-02-19 15:11:58 -08002744 "type='signal',interface='org.freedesktop.DBus.Properties',"
2745 "member='PropertiesChanged',arg0namespace='com.intel."
2746 "crashdump'");
2747 task->startTimer(std::chrono::minutes(5));
2748 task->populateResp(asyncResp->res);
James Feistfe306722020-03-12 16:32:08 -07002749 task->payload.emplace(req);
James Feist46229572020-02-19 15:11:58 -08002750 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002751 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002752 std::move(generateonDemandLogCallback), crashdumpObject,
2753 crashdumpPath, crashdumpOnDemandInterface, "GenerateOnDemandLog");
Ed Tanous1da66f72018-07-27 16:13:37 -07002754 }
2755};
2756
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002757class TelemetryCrashdump : public Node
2758{
2759 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002760 TelemetryCrashdump(App& app) :
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002761 Node(app,
2762 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2763 "Crashdump.Telemetry/")
2764 {
2765 // Note: Deviated from redfish privilege registry for GET & HEAD
2766 // method for security reasons.
2767 entityPrivileges = {
2768 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2769 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2770 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2771 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2772 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2773 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2774 }
2775
2776 private:
2777 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002778 const std::vector<std::string>&) override
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002779 {
2780 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2781
2782 auto generateTelemetryLogCallback = [asyncResp, req](
2783 const boost::system::error_code
2784 ec,
Ed Tanouscb13a392020-07-25 19:02:03 +00002785 const std::string&) {
Kenny L. Ku6eda7682020-06-19 09:48:36 -07002786 if (ec)
2787 {
2788 if (ec.value() == boost::system::errc::operation_not_supported)
2789 {
2790 messages::resourceInStandby(asyncResp->res);
2791 }
2792 else if (ec.value() ==
2793 boost::system::errc::device_or_resource_busy)
2794 {
2795 messages::serviceTemporarilyUnavailable(asyncResp->res,
2796 "60");
2797 }
2798 else
2799 {
2800 messages::internalError(asyncResp->res);
2801 }
2802 return;
2803 }
2804 std::shared_ptr<task::TaskData> task = task::TaskData::createTask(
2805 [](boost::system::error_code err, sdbusplus::message::message&,
2806 const std::shared_ptr<task::TaskData>& taskData) {
2807 if (!err)
2808 {
2809 taskData->messages.emplace_back(
2810 messages::taskCompletedOK(
2811 std::to_string(taskData->index)));
2812 taskData->state = "Completed";
2813 }
2814 return task::completed;
2815 },
2816 "type='signal',interface='org.freedesktop.DBus.Properties',"
2817 "member='PropertiesChanged',arg0namespace='com.intel."
2818 "crashdump'");
2819 task->startTimer(std::chrono::minutes(5));
2820 task->populateResp(asyncResp->res);
2821 task->payload.emplace(req);
2822 };
2823 crow::connections::systemBus->async_method_call(
2824 std::move(generateTelemetryLogCallback), crashdumpObject,
2825 crashdumpPath, crashdumpTelemetryInterface, "GenerateTelemetryLog");
2826 }
2827};
2828
Jason M. Billse1f26342018-07-18 12:12:00 -07002829class SendRawPECI : public Node
Ed Tanous1da66f72018-07-27 16:13:37 -07002830{
2831 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002832 SendRawPECI(App& app) :
Jason M. Bills424c4172019-03-21 13:50:33 -07002833 Node(app,
2834 "/redfish/v1/Systems/system/LogServices/Crashdump/Actions/Oem/"
2835 "Crashdump.SendRawPeci/")
Ed Tanous1da66f72018-07-27 16:13:37 -07002836 {
AppaRao Puli39460282020-04-07 17:03:04 +05302837 // Note: Deviated from redfish privilege registry for GET & HEAD
2838 // method for security reasons.
Ed Tanous1da66f72018-07-27 16:13:37 -07002839 entityPrivileges = {
2840 {boost::beast::http::verb::get, {{"ConfigureComponents"}}},
2841 {boost::beast::http::verb::head, {{"ConfigureComponents"}}},
2842 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
2843 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
2844 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
2845 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
2846 }
2847
2848 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002849 void doPost(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00002850 const std::vector<std::string>&) override
Ed Tanous1da66f72018-07-27 16:13:37 -07002851 {
Jason M. Billse1f26342018-07-18 12:12:00 -07002852 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002853 std::vector<std::vector<uint8_t>> peciCommands;
Ed Tanousb1556422018-10-16 14:09:17 -07002854
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002855 if (!json_util::readJson(req, res, "PECICommands", peciCommands))
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002856 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002857 return;
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002858 }
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002859 uint32_t idx = 0;
2860 for (auto const& cmd : peciCommands)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002861 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002862 if (cmd.size() < 3)
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002863 {
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002864 std::string s("[");
2865 for (auto const& val : cmd)
2866 {
2867 if (val != *cmd.begin())
2868 {
2869 s += ",";
2870 }
2871 s += std::to_string(val);
2872 }
2873 s += "]";
2874 messages::actionParameterValueFormatError(
2875 res, s, "PECICommands[" + std::to_string(idx) + "]",
2876 "SendRawPeci");
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002877 return;
2878 }
Karthick Sundarrajanf0b6ae02020-01-17 13:32:58 -08002879 idx++;
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002880 }
Ed Tanous1da66f72018-07-27 16:13:37 -07002881 // Callback to return the Raw PECI response
Jason M. Billse1f26342018-07-18 12:12:00 -07002882 auto sendRawPECICallback =
2883 [asyncResp](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05002884 const std::vector<std::vector<uint8_t>>& resp) {
Jason M. Billse1f26342018-07-18 12:12:00 -07002885 if (ec)
2886 {
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002887 BMCWEB_LOG_DEBUG << "failed to process PECI commands ec: "
Jason M. Billse1f26342018-07-18 12:12:00 -07002888 << ec.message();
Jason M. Billsf12894f2018-10-09 12:45:45 -07002889 messages::internalError(asyncResp->res);
Jason M. Billse1f26342018-07-18 12:12:00 -07002890 return;
2891 }
2892 asyncResp->res.jsonValue = {{"Name", "PECI Command Response"},
2893 {"PECIResponse", resp}};
2894 };
Ed Tanous1da66f72018-07-27 16:13:37 -07002895 // Call the SendRawPECI command with the provided data
2896 crow::connections::systemBus->async_method_call(
Jason M. Bills5b61b5e2019-10-16 10:59:02 -07002897 std::move(sendRawPECICallback), crashdumpObject, crashdumpPath,
Karthick Sundarrajan8724c292020-01-06 09:04:48 -08002898 crashdumpRawPECIInterface, "SendRawPeci", peciCommands);
Ed Tanous1da66f72018-07-27 16:13:37 -07002899 }
2900};
2901
Andrew Geisslercb92c032018-08-17 07:56:14 -07002902/**
2903 * DBusLogServiceActionsClear class supports POST method for ClearLog action.
2904 */
2905class DBusLogServiceActionsClear : public Node
2906{
2907 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002908 DBusLogServiceActionsClear(App& app) :
Andrew Geisslercb92c032018-08-17 07:56:14 -07002909 Node(app, "/redfish/v1/Systems/system/LogServices/EventLog/Actions/"
Gunnar Mills7af91512020-04-14 22:16:57 -05002910 "LogService.ClearLog/")
Andrew Geisslercb92c032018-08-17 07:56:14 -07002911 {
2912 entityPrivileges = {
2913 {boost::beast::http::verb::get, {{"Login"}}},
2914 {boost::beast::http::verb::head, {{"Login"}}},
2915 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2916 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2917 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2918 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2919 }
2920
2921 private:
2922 /**
2923 * Function handles POST method request.
2924 * The Clear Log actions does not require any parameter.The action deletes
2925 * all entries found in the Entries collection for this Log Service.
2926 */
Ed Tanouscb13a392020-07-25 19:02:03 +00002927 void doPost(crow::Response& res, const crow::Request&,
2928 const std::vector<std::string>&) override
Andrew Geisslercb92c032018-08-17 07:56:14 -07002929 {
2930 BMCWEB_LOG_DEBUG << "Do delete all entries.";
2931
2932 auto asyncResp = std::make_shared<AsyncResp>(res);
2933 // Process response from Logging service.
Ed Tanous2c70f802020-09-28 14:29:23 -07002934 auto respHandler = [asyncResp](const boost::system::error_code ec) {
Andrew Geisslercb92c032018-08-17 07:56:14 -07002935 BMCWEB_LOG_DEBUG << "doClearLog resp_handler callback: Done";
2936 if (ec)
2937 {
2938 // TODO Handle for specific error code
2939 BMCWEB_LOG_ERROR << "doClearLog resp_handler got error " << ec;
2940 asyncResp->res.result(
2941 boost::beast::http::status::internal_server_error);
2942 return;
2943 }
2944
2945 asyncResp->res.result(boost::beast::http::status::no_content);
2946 };
2947
2948 // Make call to Logging service to request Clear Log
2949 crow::connections::systemBus->async_method_call(
Ed Tanous2c70f802020-09-28 14:29:23 -07002950 respHandler, "xyz.openbmc_project.Logging",
Andrew Geisslercb92c032018-08-17 07:56:14 -07002951 "/xyz/openbmc_project/logging",
2952 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
2953 }
2954};
ZhikuiRena3316fc2020-01-29 14:58:08 -08002955
2956/****************************************************
2957 * Redfish PostCode interfaces
2958 * using DBUS interface: getPostCodesTS
2959 ******************************************************/
2960class PostCodesLogService : public Node
2961{
2962 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07002963 PostCodesLogService(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08002964 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/")
2965 {
2966 entityPrivileges = {
2967 {boost::beast::http::verb::get, {{"Login"}}},
2968 {boost::beast::http::verb::head, {{"Login"}}},
2969 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
2970 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
2971 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
2972 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
2973 }
2974
2975 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00002976 void doGet(crow::Response& res, const crow::Request&,
2977 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08002978 {
2979 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
2980
2981 asyncResp->res.jsonValue = {
2982 {"@odata.id", "/redfish/v1/Systems/system/LogServices/PostCodes"},
2983 {"@odata.type", "#LogService.v1_1_0.LogService"},
ZhikuiRena3316fc2020-01-29 14:58:08 -08002984 {"Name", "POST Code Log Service"},
2985 {"Description", "POST Code Log Service"},
2986 {"Id", "BIOS POST Code Log"},
2987 {"OverWritePolicy", "WrapsWhenFull"},
2988 {"Entries",
2989 {{"@odata.id",
2990 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries"}}}};
2991 asyncResp->res.jsonValue["Actions"]["#LogService.ClearLog"] = {
2992 {"target", "/redfish/v1/Systems/system/LogServices/PostCodes/"
2993 "Actions/LogService.ClearLog"}};
2994 }
2995};
2996
2997class PostCodesClear : public Node
2998{
2999 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003000 PostCodesClear(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003001 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Actions/"
3002 "LogService.ClearLog/")
3003 {
3004 entityPrivileges = {
3005 {boost::beast::http::verb::get, {{"Login"}}},
3006 {boost::beast::http::verb::head, {{"Login"}}},
AppaRao Puli39460282020-04-07 17:03:04 +05303007 {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
3008 {boost::beast::http::verb::put, {{"ConfigureComponents"}}},
3009 {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}},
3010 {boost::beast::http::verb::post, {{"ConfigureComponents"}}}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003011 }
3012
3013 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003014 void doPost(crow::Response& res, const crow::Request&,
3015 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003016 {
3017 BMCWEB_LOG_DEBUG << "Do delete all postcodes entries.";
3018
3019 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3020 // Make call to post-code service to request clear all
3021 crow::connections::systemBus->async_method_call(
3022 [asyncResp](const boost::system::error_code ec) {
3023 if (ec)
3024 {
3025 // TODO Handle for specific error code
3026 BMCWEB_LOG_ERROR
3027 << "doClearPostCodes resp_handler got error " << ec;
3028 asyncResp->res.result(
3029 boost::beast::http::status::internal_server_error);
3030 messages::internalError(asyncResp->res);
3031 return;
3032 }
3033 },
3034 "xyz.openbmc_project.State.Boot.PostCode",
3035 "/xyz/openbmc_project/State/Boot/PostCode",
3036 "xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
3037 }
3038};
3039
3040static void fillPostCodeEntry(
Ed Tanousb5a76932020-09-29 16:16:58 -07003041 const std::shared_ptr<AsyncResp>& aResp,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003042 const boost::container::flat_map<uint64_t, uint64_t>& postcode,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003043 const uint16_t bootIndex, const uint64_t codeIndex = 0,
3044 const uint64_t skip = 0, const uint64_t top = 0)
3045{
3046 // Get the Message from the MessageRegistry
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003047 const message_registries::Message* message =
ZhikuiRena3316fc2020-01-29 14:58:08 -08003048 message_registries::getMessage("OpenBMC.0.1.BIOSPOSTCode");
ZhikuiRena3316fc2020-01-29 14:58:08 -08003049
3050 uint64_t currentCodeIndex = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003051 nlohmann::json& logEntryArray = aResp->res.jsonValue["Members"];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003052
3053 uint64_t firstCodeTimeUs = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003054 for (const std::pair<uint64_t, uint64_t>& code : postcode)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003055 {
3056 currentCodeIndex++;
3057 std::string postcodeEntryID =
3058 "B" + std::to_string(bootIndex) + "-" +
3059 std::to_string(currentCodeIndex); // 1 based index in EntryID string
3060
3061 uint64_t usecSinceEpoch = code.first;
3062 uint64_t usTimeOffset = 0;
3063
3064 if (1 == currentCodeIndex)
3065 { // already incremented
3066 firstCodeTimeUs = code.first;
3067 }
3068 else
3069 {
3070 usTimeOffset = code.first - firstCodeTimeUs;
3071 }
3072
3073 // skip if no specific codeIndex is specified and currentCodeIndex does
3074 // not fall between top and skip
3075 if ((codeIndex == 0) &&
3076 (currentCodeIndex <= skip || currentCodeIndex > top))
3077 {
3078 continue;
3079 }
3080
Gunnar Mills4e0453b2020-07-08 14:00:30 -05003081 // skip if a specific codeIndex is specified and does not match the
ZhikuiRena3316fc2020-01-29 14:58:08 -08003082 // currentIndex
3083 if ((codeIndex > 0) && (currentCodeIndex != codeIndex))
3084 {
3085 // This is done for simplicity. 1st entry is needed to calculate
3086 // time offset. To improve efficiency, one can get to the entry
3087 // directly (possibly with flatmap's nth method)
3088 continue;
3089 }
3090
3091 // currentCodeIndex is within top and skip or equal to specified code
3092 // index
3093
3094 // Get the Created time from the timestamp
3095 std::string entryTimeStr;
Asmitha Karunanithi9c620e22020-08-02 11:55:21 -05003096 entryTimeStr = crow::utility::getDateTime(
3097 static_cast<std::time_t>(usecSinceEpoch / 1000 / 1000));
ZhikuiRena3316fc2020-01-29 14:58:08 -08003098
3099 // assemble messageArgs: BootIndex, TimeOffset(100us), PostCode(hex)
3100 std::ostringstream hexCode;
3101 hexCode << "0x" << std::setfill('0') << std::setw(2) << std::hex
3102 << code.second;
3103 std::ostringstream timeOffsetStr;
3104 // Set Fixed -Point Notation
3105 timeOffsetStr << std::fixed;
3106 // Set precision to 4 digits
3107 timeOffsetStr << std::setprecision(4);
3108 // Add double to stream
3109 timeOffsetStr << static_cast<double>(usTimeOffset) / 1000 / 1000;
3110 std::vector<std::string> messageArgs = {
3111 std::to_string(bootIndex), timeOffsetStr.str(), hexCode.str()};
3112
3113 // Get MessageArgs template from message registry
3114 std::string msg;
3115 if (message != nullptr)
3116 {
3117 msg = message->message;
3118
3119 // fill in this post code value
3120 int i = 0;
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003121 for (const std::string& messageArg : messageArgs)
ZhikuiRena3316fc2020-01-29 14:58:08 -08003122 {
3123 std::string argStr = "%" + std::to_string(++i);
3124 size_t argPos = msg.find(argStr);
3125 if (argPos != std::string::npos)
3126 {
3127 msg.replace(argPos, argStr.length(), messageArg);
3128 }
3129 }
3130 }
3131
Tim Leed4342a92020-04-27 11:47:58 +08003132 // Get Severity template from message registry
3133 std::string severity;
3134 if (message != nullptr)
3135 {
3136 severity = message->severity;
3137 }
3138
ZhikuiRena3316fc2020-01-29 14:58:08 -08003139 // add to AsyncResp
3140 logEntryArray.push_back({});
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003141 nlohmann::json& bmcLogEntry = logEntryArray.back();
Gunnar Mills743e9a12020-10-26 12:44:53 -05003142 bmcLogEntry = {{"@odata.type", "#LogEntry.v1_4_0.LogEntry"},
3143 {"@odata.id", "/redfish/v1/Systems/system/LogServices/"
3144 "PostCodes/Entries/" +
3145 postcodeEntryID},
3146 {"Name", "POST Code Log Entry"},
3147 {"Id", postcodeEntryID},
3148 {"Message", std::move(msg)},
3149 {"MessageId", "OpenBMC.0.1.BIOSPOSTCode"},
3150 {"MessageArgs", std::move(messageArgs)},
3151 {"EntryType", "Event"},
3152 {"Severity", std::move(severity)},
3153 {"Created", entryTimeStr}};
ZhikuiRena3316fc2020-01-29 14:58:08 -08003154 }
3155}
3156
Ed Tanousb5a76932020-09-29 16:16:58 -07003157static void getPostCodeForEntry(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003158 const uint16_t bootIndex,
3159 const uint64_t codeIndex)
3160{
3161 crow::connections::systemBus->async_method_call(
3162 [aResp, bootIndex, codeIndex](
3163 const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003164 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003165 if (ec)
3166 {
3167 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3168 messages::internalError(aResp->res);
3169 return;
3170 }
3171
3172 // skip the empty postcode boots
3173 if (postcode.empty())
3174 {
3175 return;
3176 }
3177
3178 fillPostCodeEntry(aResp, postcode, bootIndex, codeIndex);
3179
3180 aResp->res.jsonValue["Members@odata.count"] =
3181 aResp->res.jsonValue["Members"].size();
3182 },
3183 "xyz.openbmc_project.State.Boot.PostCode",
3184 "/xyz/openbmc_project/State/Boot/PostCode",
3185 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3186 bootIndex);
3187}
3188
Ed Tanousb5a76932020-09-29 16:16:58 -07003189static void getPostCodeForBoot(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003190 const uint16_t bootIndex,
3191 const uint16_t bootCount,
3192 const uint64_t entryCount, const uint64_t skip,
3193 const uint64_t top)
3194{
3195 crow::connections::systemBus->async_method_call(
3196 [aResp, bootIndex, bootCount, entryCount, skip,
3197 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003198 const boost::container::flat_map<uint64_t, uint64_t>& postcode) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003199 if (ec)
3200 {
3201 BMCWEB_LOG_DEBUG << "DBUS POST CODE PostCode response error";
3202 messages::internalError(aResp->res);
3203 return;
3204 }
3205
3206 uint64_t endCount = entryCount;
3207 if (!postcode.empty())
3208 {
3209 endCount = entryCount + postcode.size();
3210
3211 if ((skip < endCount) && ((top + skip) > entryCount))
3212 {
3213 uint64_t thisBootSkip =
3214 std::max(skip, entryCount) - entryCount;
3215 uint64_t thisBootTop =
3216 std::min(top + skip, endCount) - entryCount;
3217
3218 fillPostCodeEntry(aResp, postcode, bootIndex, 0,
3219 thisBootSkip, thisBootTop);
3220 }
3221 aResp->res.jsonValue["Members@odata.count"] = endCount;
3222 }
3223
3224 // continue to previous bootIndex
3225 if (bootIndex < bootCount)
3226 {
3227 getPostCodeForBoot(aResp, static_cast<uint16_t>(bootIndex + 1),
3228 bootCount, endCount, skip, top);
3229 }
3230 else
3231 {
3232 aResp->res.jsonValue["Members@odata.nextLink"] =
3233 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3234 "Entries?$skip=" +
3235 std::to_string(skip + top);
3236 }
3237 },
3238 "xyz.openbmc_project.State.Boot.PostCode",
3239 "/xyz/openbmc_project/State/Boot/PostCode",
3240 "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodesWithTimeStamp",
3241 bootIndex);
3242}
3243
Ed Tanousb5a76932020-09-29 16:16:58 -07003244static void getCurrentBootNumber(const std::shared_ptr<AsyncResp>& aResp,
ZhikuiRena3316fc2020-01-29 14:58:08 -08003245 const uint64_t skip, const uint64_t top)
3246{
3247 uint64_t entryCount = 0;
3248 crow::connections::systemBus->async_method_call(
3249 [aResp, entryCount, skip,
3250 top](const boost::system::error_code ec,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003251 const std::variant<uint16_t>& bootCount) {
ZhikuiRena3316fc2020-01-29 14:58:08 -08003252 if (ec)
3253 {
3254 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
3255 messages::internalError(aResp->res);
3256 return;
3257 }
3258 auto pVal = std::get_if<uint16_t>(&bootCount);
3259 if (pVal)
3260 {
3261 getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
3262 }
3263 else
3264 {
3265 BMCWEB_LOG_DEBUG << "Post code boot index failed.";
3266 }
3267 },
3268 "xyz.openbmc_project.State.Boot.PostCode",
3269 "/xyz/openbmc_project/State/Boot/PostCode",
3270 "org.freedesktop.DBus.Properties", "Get",
3271 "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
3272}
3273
3274class PostCodesEntryCollection : public Node
3275{
3276 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003277 PostCodesEntryCollection(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003278 Node(app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/")
3279 {
3280 entityPrivileges = {
3281 {boost::beast::http::verb::get, {{"Login"}}},
3282 {boost::beast::http::verb::head, {{"Login"}}},
3283 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3284 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3285 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3286 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3287 }
3288
3289 private:
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003290 void doGet(crow::Response& res, const crow::Request& req,
Ed Tanouscb13a392020-07-25 19:02:03 +00003291 const std::vector<std::string>&) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003292 {
3293 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3294
3295 asyncResp->res.jsonValue["@odata.type"] =
3296 "#LogEntryCollection.LogEntryCollection";
ZhikuiRena3316fc2020-01-29 14:58:08 -08003297 asyncResp->res.jsonValue["@odata.id"] =
3298 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries";
3299 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3300 asyncResp->res.jsonValue["Description"] =
3301 "Collection of POST Code Log Entries";
3302 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3303 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3304
3305 uint64_t skip = 0;
3306 uint64_t top = maxEntriesPerPage; // Show max entries by default
3307 if (!getSkipParam(asyncResp->res, req, skip))
3308 {
3309 return;
3310 }
3311 if (!getTopParam(asyncResp->res, req, top))
3312 {
3313 return;
3314 }
3315 getCurrentBootNumber(asyncResp, skip, top);
3316 }
3317};
3318
3319class PostCodesEntry : public Node
3320{
3321 public:
Ed Tanous52cc1122020-07-18 13:51:21 -07003322 PostCodesEntry(App& app) :
ZhikuiRena3316fc2020-01-29 14:58:08 -08003323 Node(app,
3324 "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/",
3325 std::string())
3326 {
3327 entityPrivileges = {
3328 {boost::beast::http::verb::get, {{"Login"}}},
3329 {boost::beast::http::verb::head, {{"Login"}}},
3330 {boost::beast::http::verb::patch, {{"ConfigureManager"}}},
3331 {boost::beast::http::verb::put, {{"ConfigureManager"}}},
3332 {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
3333 {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3334 }
3335
3336 private:
Ed Tanouscb13a392020-07-25 19:02:03 +00003337 void doGet(crow::Response& res, const crow::Request&,
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003338 const std::vector<std::string>& params) override
ZhikuiRena3316fc2020-01-29 14:58:08 -08003339 {
3340 std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
3341 if (params.size() != 1)
3342 {
3343 messages::internalError(asyncResp->res);
3344 return;
3345 }
3346
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003347 const std::string& targetID = params[0];
ZhikuiRena3316fc2020-01-29 14:58:08 -08003348
3349 size_t bootPos = targetID.find('B');
3350 if (bootPos == std::string::npos)
3351 {
3352 // Requested ID was not found
3353 messages::resourceMissingAtURI(asyncResp->res, targetID);
3354 return;
3355 }
3356 std::string_view bootIndexStr(targetID);
3357 bootIndexStr.remove_prefix(bootPos + 1);
3358 uint16_t bootIndex = 0;
3359 uint64_t codeIndex = 0;
3360 size_t dashPos = bootIndexStr.find('-');
3361
3362 if (dashPos == std::string::npos)
3363 {
3364 return;
3365 }
3366 std::string_view codeIndexStr(bootIndexStr);
3367 bootIndexStr.remove_suffix(dashPos);
3368 codeIndexStr.remove_prefix(dashPos + 1);
3369
3370 bootIndex = static_cast<uint16_t>(
Ed Tanous23a21a12020-07-25 04:45:05 +00003371 strtoul(std::string(bootIndexStr).c_str(), nullptr, 0));
3372 codeIndex = strtoul(std::string(codeIndexStr).c_str(), nullptr, 0);
ZhikuiRena3316fc2020-01-29 14:58:08 -08003373 if (bootIndex == 0 || codeIndex == 0)
3374 {
3375 BMCWEB_LOG_DEBUG << "Get Post Code invalid entry string "
3376 << params[0];
3377 }
3378
3379 asyncResp->res.jsonValue["@odata.type"] = "#LogEntry.v1_4_0.LogEntry";
ZhikuiRena3316fc2020-01-29 14:58:08 -08003380 asyncResp->res.jsonValue["@odata.id"] =
3381 "/redfish/v1/Systems/system/LogServices/PostCodes/"
3382 "Entries";
3383 asyncResp->res.jsonValue["Name"] = "BIOS POST Code Log Entries";
3384 asyncResp->res.jsonValue["Description"] =
3385 "Collection of POST Code Log Entries";
3386 asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
3387 asyncResp->res.jsonValue["Members@odata.count"] = 0;
3388
3389 getPostCodeForEntry(asyncResp, bootIndex, codeIndex);
3390 }
3391};
3392
Ed Tanous1da66f72018-07-27 16:13:37 -07003393} // namespace redfish