Matt Spinler | 56fd833 | 2017-10-31 14:00:18 -0500 | [diff] [blame] | 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 "resolve_errors.hpp" |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 17 | |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 18 | #include "sdbusplus.hpp" |
Matt Spinler | 56fd833 | 2017-10-31 14:00:18 -0500 | [diff] [blame] | 19 | |
George Liu | 13e3df6 | 2022-06-22 15:03:06 +0800 | [diff] [blame] | 20 | #include <phosphor-logging/lg2.hpp> |
Patrick Venture | 3d6d318 | 2018-08-31 09:33:09 -0700 | [diff] [blame] | 21 | |
Matt Spinler | 56fd833 | 2017-10-31 14:00:18 -0500 | [diff] [blame] | 22 | namespace phosphor |
| 23 | { |
| 24 | namespace dbus |
| 25 | { |
| 26 | namespace monitoring |
| 27 | { |
| 28 | |
Matt Spinler | f55c1ee | 2017-11-01 10:40:57 -0500 | [diff] [blame] | 29 | constexpr auto LOGGING_IFACE = "xyz.openbmc_project.Logging.Entry"; |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 30 | constexpr auto PROPERTY_IFACE = "org.freedesktop.DBus.Properties"; |
Matt Spinler | ecf8910 | 2018-09-18 15:29:01 -0500 | [diff] [blame] | 31 | constexpr auto ASSOCIATION_IFACE = "xyz.openbmc_project.Association"; |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 32 | constexpr auto ENDPOINTS_PROPERTY = "endpoints"; |
Matt Spinler | f55c1ee | 2017-11-01 10:40:57 -0500 | [diff] [blame] | 33 | constexpr auto RESOLVED_PROPERTY = "Resolved"; |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 34 | |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 35 | using EndpointList = std::vector<std::string>; |
Patrick Williams | 35b4f33 | 2020-05-13 17:53:09 -0500 | [diff] [blame] | 36 | using EndpointsProperty = std::variant<EndpointList>; |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 37 | |
George Liu | 5e6b51d | 2022-06-21 16:59:39 +0800 | [diff] [blame] | 38 | void ResolveCallout::operator()(Context /* ctx */) |
Matt Spinler | 56fd833 | 2017-10-31 14:00:18 -0500 | [diff] [blame] | 39 | { |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 40 | // Resolve all errors for this callout: |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 41 | // 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 Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 54 | // Just means there are no error logs with this callout |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 55 | return; |
| 56 | } |
| 57 | |
| 58 | auto endpoints = SDBusPlus::callMethodAndRead<EndpointsProperty>( |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 59 | busName, path, PROPERTY_IFACE, "Get", ASSOCIATION_IFACE, |
| 60 | ENDPOINTS_PROPERTY); |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 61 | |
Patrick Williams | 34ef1e5 | 2020-05-13 11:07:43 -0500 | [diff] [blame] | 62 | const auto& logEntries = std::get<EndpointList>(endpoints); |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 63 | |
Brad Bishop | d1eac88 | 2018-03-29 10:34:05 -0400 | [diff] [blame] | 64 | // Resolve each log entry |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 65 | for (const auto& logEntry : logEntries) |
| 66 | { |
| 67 | resolve(logEntry); |
| 68 | } |
| 69 | } |
| 70 | catch (const std::exception& e) |
| 71 | { |
George Liu | 13e3df6 | 2022-06-22 15:03:06 +0800 | [diff] [blame] | 72 | lg2::error("Failed getting callout fault associations: {ERROR}, {PATH}", |
| 73 | "ERROR", e, "PATH", callout); |
Matt Spinler | 4eaa77b | 2017-10-31 14:25:27 -0500 | [diff] [blame] | 74 | } |
Matt Spinler | 56fd833 | 2017-10-31 14:00:18 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void ResolveCallout::resolve(const std::string& logEntry) |
| 78 | { |
Matt Spinler | f55c1ee | 2017-11-01 10:40:57 -0500 | [diff] [blame] | 79 | 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 Williams | 35b4f33 | 2020-05-13 17:53:09 -0500 | [diff] [blame] | 91 | std::variant<bool> resolved = true; |
Matt Spinler | f55c1ee | 2017-11-01 10:40:57 -0500 | [diff] [blame] | 92 | |
George Liu | 6f04b22 | 2022-06-22 14:23:19 +0800 | [diff] [blame] | 93 | SDBusPlus::callMethod(busName, logEntry, PROPERTY_IFACE, "Set", |
| 94 | LOGGING_IFACE, RESOLVED_PROPERTY, resolved); |
Matt Spinler | f55c1ee | 2017-11-01 10:40:57 -0500 | [diff] [blame] | 95 | } |
| 96 | catch (const std::exception& e) |
| 97 | { |
George Liu | 13e3df6 | 2022-06-22 15:03:06 +0800 | [diff] [blame] | 98 | lg2::error("Unable to resolve error log entry {ENTRY}: {ERROR}", |
| 99 | "ENTRY", logEntry, "ERROR", e); |
Matt Spinler | f55c1ee | 2017-11-01 10:40:57 -0500 | [diff] [blame] | 100 | } |
Matt Spinler | 56fd833 | 2017-10-31 14:00:18 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | } // namespace monitoring |
| 104 | } // namespace dbus |
| 105 | } // namespace phosphor |