blob: fd5be3408411a90219fbf310229f632bacdfa1be [file] [log] [blame]
Matt Spinler56fd8332017-10-31 14:00:18 -05001/**
2 * Copyright © 2017 IBM 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#include "resolve_errors.hpp"
Patrick Venture3d6d3182018-08-31 09:33:09 -070017
Matt Spinler4eaa77b2017-10-31 14:25:27 -050018#include "sdbusplus.hpp"
Matt Spinler56fd8332017-10-31 14:00:18 -050019
George Liu13e3df62022-06-22 15:03:06 +080020#include <phosphor-logging/lg2.hpp>
Patrick Venture3d6d3182018-08-31 09:33:09 -070021
Matt Spinler56fd8332017-10-31 14:00:18 -050022namespace phosphor
23{
24namespace dbus
25{
26namespace monitoring
27{
28
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050029constexpr auto LOGGING_IFACE = "xyz.openbmc_project.Logging.Entry";
Matt Spinler4eaa77b2017-10-31 14:25:27 -050030constexpr auto PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
Matt Spinlerecf89102018-09-18 15:29:01 -050031constexpr auto ASSOCIATION_IFACE = "xyz.openbmc_project.Association";
Matt Spinler4eaa77b2017-10-31 14:25:27 -050032constexpr auto ENDPOINTS_PROPERTY = "endpoints";
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050033constexpr auto RESOLVED_PROPERTY = "Resolved";
Matt Spinler4eaa77b2017-10-31 14:25:27 -050034
Matt Spinler4eaa77b2017-10-31 14:25:27 -050035using EndpointList = std::vector<std::string>;
Patrick Williams35b4f332020-05-13 17:53:09 -050036using EndpointsProperty = std::variant<EndpointList>;
Matt Spinler4eaa77b2017-10-31 14:25:27 -050037
George Liu5e6b51d2022-06-21 16:59:39 +080038void ResolveCallout::operator()(Context /* ctx */)
Matt Spinler56fd8332017-10-31 14:00:18 -050039{
Brad Bishopd1eac882018-03-29 10:34:05 -040040 // Resolve all errors for this callout:
Matt Spinler4eaa77b2017-10-31 14:25:27 -050041 // 1) Read the 'endpoints' property for the callout/fault object
42 //
43 // 2) Follow each endpoint to its log entry
44 //
45 // 3) Set the Resolved property to true on the entry
46
47 try
48 {
49 auto path = callout + "/fault";
50 auto busName = SDBusPlus::getBusName(path, ASSOCIATION_IFACE);
51
52 if (busName.empty())
53 {
Brad Bishopd1eac882018-03-29 10:34:05 -040054 // Just means there are no error logs with this callout
Matt Spinler4eaa77b2017-10-31 14:25:27 -050055 return;
56 }
57
58 auto endpoints = SDBusPlus::callMethodAndRead<EndpointsProperty>(
Brad Bishopd1eac882018-03-29 10:34:05 -040059 busName, path, PROPERTY_IFACE, "Get", ASSOCIATION_IFACE,
60 ENDPOINTS_PROPERTY);
Matt Spinler4eaa77b2017-10-31 14:25:27 -050061
Patrick Williams34ef1e52020-05-13 11:07:43 -050062 const auto& logEntries = std::get<EndpointList>(endpoints);
Matt Spinler4eaa77b2017-10-31 14:25:27 -050063
Brad Bishopd1eac882018-03-29 10:34:05 -040064 // Resolve each log entry
Matt Spinler4eaa77b2017-10-31 14:25:27 -050065 for (const auto& logEntry : logEntries)
66 {
67 resolve(logEntry);
68 }
69 }
70 catch (const std::exception& e)
71 {
George Liu13e3df62022-06-22 15:03:06 +080072 lg2::error("Failed getting callout fault associations: {ERROR}, {PATH}",
73 "ERROR", e, "PATH", callout);
Matt Spinler4eaa77b2017-10-31 14:25:27 -050074 }
Matt Spinler56fd8332017-10-31 14:00:18 -050075}
76
77void ResolveCallout::resolve(const std::string& logEntry)
78{
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050079 try
80 {
81 static std::string busName;
82 if (busName.empty())
83 {
84 busName = SDBusPlus::getBusName(logEntry, LOGGING_IFACE);
85 if (busName.empty())
86 {
87 return;
88 }
89 }
90
Patrick Williams35b4f332020-05-13 17:53:09 -050091 std::variant<bool> resolved = true;
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050092
Brad Bishopd1eac882018-03-29 10:34:05 -040093 auto response =
94 SDBusPlus::callMethod(busName, logEntry, PROPERTY_IFACE, "Set",
95 LOGGING_IFACE, RESOLVED_PROPERTY, resolved);
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050096
97 if (response.is_method_error())
98 {
George Liu13e3df62022-06-22 15:03:06 +080099 lg2::error(
100 "Failed to set Resolved property on an error log entry: {ENTRY}",
101 "ENTRY", logEntry);
Matt Spinlerf55c1ee2017-11-01 10:40:57 -0500102 }
103 }
104 catch (const std::exception& e)
105 {
George Liu13e3df62022-06-22 15:03:06 +0800106 lg2::error("Unable to resolve error log entry {ENTRY}: {ERROR}",
107 "ENTRY", logEntry, "ERROR", e);
Matt Spinlerf55c1ee2017-11-01 10:40:57 -0500108 }
Matt Spinler56fd8332017-10-31 14:00:18 -0500109}
110
111} // namespace monitoring
112} // namespace dbus
113} // namespace phosphor