diff options
| author | Jason M. Bills <jason.m.bills@linux.intel.com> | 2019-10-08 11:43:32 -0700 |
|---|---|---|
| committer | Jason Bills <jason.m.bills@linux.intel.com> | 2019-10-29 18:42:47 +0000 |
| commit | 3cf8ea3c737098239c9392d991f6ef742ba67061 (patch) | |
| tree | 59c92ca9181b0d21053fa9b9d9d4ed4a89d0a714 | |
| parent | 53d9a6668f7d20c46aea33d5163a143ccf35e643 (diff) | |
| download | bmcweb-3cf8ea3c737098239c9392d991f6ef742ba67061.tar.gz bmcweb-3cf8ea3c737098239c9392d991f6ef742ba67061.zip | |
Simplify the OnDemand Crashdump return data
Tested:
Ran an on-demand crashdump and confirmed that the output is
correct.
Change-Id: I993a36d3a6966433cbc6ede9e2d0702b319e3fd0
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
| -rw-r--r-- | redfish-core/lib/log_services.hpp | 85 |
1 files changed, 39 insertions, 46 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index d08d6d0..f1bfda6 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -1747,58 +1747,51 @@ class OnDemandCrashdump : public Node messages::internalError(asyncResp->res); }); - auto onDemandLogMatcherCallback = [asyncResp]( - sdbusplus::message::message &m) { - BMCWEB_LOG_DEBUG << "OnDemand log available match fired"; - timeout.cancel(); - - sdbusplus::message::object_path objPath; - boost::container::flat_map< - std::string, boost::container::flat_map< - std::string, std::variant<std::string>>> - interfacesAdded; - m.read(objPath, interfacesAdded); - const std::string *log = std::get_if<std::string>( - &interfacesAdded[CrashdumpInterface]["Log"]); - if (log == nullptr) - { - messages::internalError(asyncResp->res); - // Careful with onDemandLogMatcher. It is a unique_ptr to the - // match object inside which this lambda is executing. Once it - // is set to nullptr, the match object will be destroyed and the - // lambda will lose its context, including res, so it needs to - // be the last thing done. - onDemandLogMatcher = nullptr; - return; - } - nlohmann::json j = nlohmann::json::parse(*log, nullptr, false); - if (j.is_discarded()) - { - messages::internalError(asyncResp->res); + auto onDemandLogMatcherCallback = + [asyncResp](sdbusplus::message::message &m) { + BMCWEB_LOG_DEBUG << "OnDemand log available match fired"; + timeout.cancel(); + + sdbusplus::message::object_path objPath; + boost::container::flat_map< + std::string, boost::container::flat_map< + std::string, std::variant<std::string>>> + interfacesAdded; + m.read(objPath, interfacesAdded); + const std::string *log = std::get_if<std::string>( + &interfacesAdded[CrashdumpInterface]["Log"]); + if (log == nullptr) + { + messages::internalError(asyncResp->res); + // Careful with onDemandLogMatcher. It is a unique_ptr to + // the match object inside which this lambda is executing. + // Once it is set to nullptr, the match object will be + // destroyed and the lambda will lose its context, including + // res, so it needs to be the last thing done. + onDemandLogMatcher = nullptr; + return; + } + nlohmann::json crashdumpJson = + nlohmann::json::parse(*log, nullptr, false); + if (crashdumpJson.is_discarded()) + { + messages::internalError(asyncResp->res); + // Careful with onDemandLogMatcher. It is a unique_ptr to + // the match object inside which this lambda is executing. + // Once it is set to nullptr, the match object will be + // destroyed and the lambda will lose its context, including + // res, so it needs to be the last thing done. + onDemandLogMatcher = nullptr; + return; + } + asyncResp->res.jsonValue = crashdumpJson; // Careful with onDemandLogMatcher. It is a unique_ptr to the // match object inside which this lambda is executing. Once it // is set to nullptr, the match object will be destroyed and the // lambda will lose its context, including res, so it needs to // be the last thing done. onDemandLogMatcher = nullptr; - return; - } - std::string t = getLogCreatedTime(j); - asyncResp->res.jsonValue = { - {"@odata.type", "#LogEntry.v1_4_0.LogEntry"}, - {"@odata.context", "/redfish/v1/$metadata#LogEntry.LogEntry"}, - {"Name", "CPU Crashdump"}, - {"EntryType", "Oem"}, - {"OemRecordFormat", "Intel Crashdump"}, - {"Oem", {{"Intel", std::move(j)}}}, - {"Created", std::move(t)}}; - // Careful with onDemandLogMatcher. It is a unique_ptr to the - // match object inside which this lambda is executing. Once it is - // set to nullptr, the match object will be destroyed and the lambda - // will lose its context, including res, so it needs to be the last - // thing done. - onDemandLogMatcher = nullptr; - }; + }; onDemandLogMatcher = std::make_unique<sdbusplus::bus::match::match>( *crow::connections::systemBus, sdbusplus::bus::match::rules::interfacesAdded() + |

