blob: 47277ebae65762f083a90d1ae1d37f03cf50ba65 [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 */
Matt Spinler4eaa77b2017-10-31 14:25:27 -050016#include <phosphor-logging/log.hpp>
Matt Spinler56fd8332017-10-31 14:00:18 -050017#include "resolve_errors.hpp"
Matt Spinler4eaa77b2017-10-31 14:25:27 -050018#include "sdbusplus.hpp"
Matt Spinler56fd8332017-10-31 14:00:18 -050019
20namespace phosphor
21{
22namespace dbus
23{
24namespace monitoring
25{
26
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050027constexpr auto LOGGING_IFACE = "xyz.openbmc_project.Logging.Entry";
Matt Spinler4eaa77b2017-10-31 14:25:27 -050028constexpr auto PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
29constexpr auto ASSOCIATION_IFACE = "org.openbmc.Association";
30constexpr auto ENDPOINTS_PROPERTY = "endpoints";
Matt Spinlerf55c1ee2017-11-01 10:40:57 -050031constexpr auto RESOLVED_PROPERTY = "Resolved";
Matt Spinler4eaa77b2017-10-31 14:25:27 -050032
33using namespace phosphor::logging;
34using EndpointList = std::vector<std::string>;
35using EndpointsProperty = sdbusplus::message::variant<EndpointList>;
36
Ratan Guptaa45e0862018-02-21 19:03:13 +053037void ResolveCallout::operator()(Context ctx)
Matt Spinler56fd8332017-10-31 14:00:18 -050038{
Brad Bishopd1eac882018-03-29 10:34:05 -040039 // Resolve all errors for this callout:
Matt Spinler4eaa77b2017-10-31 14:25:27 -050040 // 1) Read the 'endpoints' property for the callout/fault object
41 //
42 // 2) Follow each endpoint to its log entry
43 //
44 // 3) Set the Resolved property to true on the entry
45
46 try
47 {
48 auto path = callout + "/fault";
49 auto busName = SDBusPlus::getBusName(path, ASSOCIATION_IFACE);
50
51 if (busName.empty())
52 {
Brad Bishopd1eac882018-03-29 10:34:05 -040053 // Just means there are no error logs with this callout
Matt Spinler4eaa77b2017-10-31 14:25:27 -050054 return;
55 }
56
57 auto endpoints = SDBusPlus::callMethodAndRead<EndpointsProperty>(
Brad Bishopd1eac882018-03-29 10:34:05 -040058 busName, path, PROPERTY_IFACE, "Get", ASSOCIATION_IFACE,
59 ENDPOINTS_PROPERTY);
Matt Spinler4eaa77b2017-10-31 14:25:27 -050060
61 const auto& logEntries = endpoints.get<EndpointList>();
62
Brad Bishopd1eac882018-03-29 10:34:05 -040063 // Resolve each log entry
Matt Spinler4eaa77b2017-10-31 14:25:27 -050064 for (const auto& logEntry : logEntries)
65 {
66 resolve(logEntry);
67 }
68 }
69 catch (const std::exception& e)
70 {
Brad Bishopd1eac882018-03-29 10:34:05 -040071 log<level::ERR>("Failed getting callout fault associations",
72 entry("CALLOUT=%s", callout.c_str()),
73 entry("MESSAGE=%s", e.what()));
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
91 sdbusplus::message::variant<bool> resolved = true;
92
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 {
99 log<level::ERR>(
Brad Bishopd1eac882018-03-29 10:34:05 -0400100 "Failed to set Resolved property on an error log entry",
101 entry("ENTRY=%s", logEntry.c_str()));
Matt Spinlerf55c1ee2017-11-01 10:40:57 -0500102 }
103 }
104 catch (const std::exception& e)
105 {
Brad Bishopd1eac882018-03-29 10:34:05 -0400106 log<level::ERR>("Unable to resolve error log entry",
107 entry("ENTRY=%s", logEntry.c_str()),
108 entry("MESSAGE=%s", e.what()));
Matt Spinlerf55c1ee2017-11-01 10:40:57 -0500109 }
Matt Spinler56fd8332017-10-31 14:00:18 -0500110}
111
112} // namespace monitoring
113} // namespace dbus
114} // namespace phosphor