xref: /openbmc/phosphor-dbus-monitor/src/resolve_errors.cpp (revision 4eaa77b3f688658d1f1d6a6e95a60a69e8aa83e4)
1 /**
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 <phosphor-logging/log.hpp>
17 #include "resolve_errors.hpp"
18 #include "sdbusplus.hpp"
19 
20 namespace phosphor
21 {
22 namespace dbus
23 {
24 namespace monitoring
25 {
26 
27 constexpr auto PROPERTY_IFACE = "org.freedesktop.DBus.Properties";
28 constexpr auto ASSOCIATION_IFACE = "org.openbmc.Association";
29 constexpr auto ENDPOINTS_PROPERTY = "endpoints";
30 
31 using namespace phosphor::logging;
32 using EndpointList = std::vector<std::string>;
33 using EndpointsProperty = sdbusplus::message::variant<EndpointList>;
34 
35 void ResolveCallout::operator()()
36 {
37     //Resolve all errors for this callout:
38     // 1) Read the 'endpoints' property for the callout/fault object
39     //
40     // 2) Follow each endpoint to its log entry
41     //
42     // 3) Set the Resolved property to true on the entry
43 
44     try
45     {
46         auto path = callout + "/fault";
47         auto busName = SDBusPlus::getBusName(path, ASSOCIATION_IFACE);
48 
49         if (busName.empty())
50         {
51             //Just means there are no error logs with this callout
52             return;
53         }
54 
55         auto endpoints = SDBusPlus::callMethodAndRead<EndpointsProperty>(
56                 busName,
57                 path,
58                 PROPERTY_IFACE,
59                 "Get",
60                 ASSOCIATION_IFACE,
61                 ENDPOINTS_PROPERTY);
62 
63         const auto& logEntries = endpoints.get<EndpointList>();
64 
65         //Resolve each log entry
66         for (const auto& logEntry : logEntries)
67         {
68             resolve(logEntry);
69         }
70     }
71     catch (const std::exception& e)
72     {
73         log<level::ERR>(
74                 "Failed getting callout fault associations",
75                 entry("CALLOUT=%s", callout.c_str()),
76                 entry("MESSAGE=%s", e.what()));
77     }
78 }
79 
80 void ResolveCallout::resolve(const std::string& logEntry)
81 {
82     //TODO: fill in
83 }
84 
85 } // namespace monitoring
86 } // namespace dbus
87 } // namespace phosphor
88