blob: 3d38686a4e2196ee7ca74bf137687790c98f288f [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
Patrick Venture3d6d3182018-08-31 09:33:09 -070020#include <phosphor-logging/log.hpp>
21
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
35using namespace phosphor::logging;
36using EndpointList = std::vector<std::string>;
37using EndpointsProperty = sdbusplus::message::variant<EndpointList>;
38
Ratan Guptaa45e0862018-02-21 19:03:13 +053039void ResolveCallout::operator()(Context ctx)
Matt Spinler56fd8332017-10-31 14:00:18 -050040{
Brad Bishopd1eac882018-03-29 10:34:05 -040041 // Resolve all errors for this callout:
Matt Spinler4eaa77b2017-10-31 14:25:27 -050042 // 1) Read the 'endpoints' property for the callout/fault object
43 //
44 // 2) Follow each endpoint to its log entry
45 //
46 // 3) Set the Resolved property to true on the entry
47
48 try
49 {
50 auto path = callout + "/fault";
51 auto busName = SDBusPlus::getBusName(path, ASSOCIATION_IFACE);
52
53 if (busName.empty())
54 {
Brad Bishopd1eac882018-03-29 10:34:05 -040055 // Just means there are no error logs with this callout
Matt Spinler4eaa77b2017-10-31 14:25:27 -050056 return;
57 }
58
59 auto endpoints = SDBusPlus::callMethodAndRead<EndpointsProperty>(
Brad Bishopd1eac882018-03-29 10:34:05 -040060 busName, path, PROPERTY_IFACE, "Get", ASSOCIATION_IFACE,
61 ENDPOINTS_PROPERTY);
Matt Spinler4eaa77b2017-10-31 14:25:27 -050062
William A. Kennington IIIefcd6532018-11-12 15:54:32 -080063 const auto& logEntries =
64 sdbusplus::message::variant_ns::get<EndpointList>(endpoints);
Matt Spinler4eaa77b2017-10-31 14:25:27 -050065
Brad Bishopd1eac882018-03-29 10:34:05 -040066 // Resolve each log entry
Matt Spinler4eaa77b2017-10-31 14:25:27 -050067 for (const auto& logEntry : logEntries)
68 {
69 resolve(logEntry);
70 }
71 }
72 catch (const std::exception& e)
73 {
Brad Bishopd1eac882018-03-29 10:34:05 -040074 log<level::ERR>("Failed getting callout fault associations",
75 entry("CALLOUT=%s", callout.c_str()),
Matt Spinler63830492018-09-18 15:27:04 -050076 entry("ERROR=%s", e.what()));
Matt Spinler4eaa77b2017-10-31 14:25:27 -050077 }
Matt Spinler56fd8332017-10-31 14:00:18 -050078}
79
80void ResolveCallout::resolve(const std::string& logEntry)
81{
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050082 try
83 {
84 static std::string busName;
85 if (busName.empty())
86 {
87 busName = SDBusPlus::getBusName(logEntry, LOGGING_IFACE);
88 if (busName.empty())
89 {
90 return;
91 }
92 }
93
94 sdbusplus::message::variant<bool> resolved = true;
95
Brad Bishopd1eac882018-03-29 10:34:05 -040096 auto response =
97 SDBusPlus::callMethod(busName, logEntry, PROPERTY_IFACE, "Set",
98 LOGGING_IFACE, RESOLVED_PROPERTY, resolved);
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050099
100 if (response.is_method_error())
101 {
102 log<level::ERR>(
Brad Bishopd1eac882018-03-29 10:34:05 -0400103 "Failed to set Resolved property on an error log entry",
104 entry("ENTRY=%s", logEntry.c_str()));
Matt Spinlerf55c1ee2017-11-01 10:40:57 -0500105 }
106 }
107 catch (const std::exception& e)
108 {
Brad Bishopd1eac882018-03-29 10:34:05 -0400109 log<level::ERR>("Unable to resolve error log entry",
110 entry("ENTRY=%s", logEntry.c_str()),
Matt Spinler63830492018-09-18 15:27:04 -0500111 entry("ERROR=%s", e.what()));
Matt Spinlerf55c1ee2017-11-01 10:40:57 -0500112 }
Matt Spinler56fd8332017-10-31 14:00:18 -0500113}
114
115} // namespace monitoring
116} // namespace dbus
117} // namespace phosphor