Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2021 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 | #pragma once |
| 17 | |
Matt Spinler | 66e75a7 | 2021-05-14 10:32:47 -0500 | [diff] [blame] | 18 | #include "power_state.hpp" |
| 19 | |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 20 | #include <sdbusplus/bus.hpp> |
| 21 | #include <sdbusplus/bus/match.hpp> |
| 22 | #include <sdeventplus/event.hpp> |
| 23 | |
| 24 | namespace sensor::monitor |
| 25 | { |
| 26 | |
Matt Spinler | 50bf816 | 2021-02-01 16:24:01 -0600 | [diff] [blame] | 27 | using InterfaceName = std::string; |
| 28 | using PropertyName = std::string; |
| 29 | using ErrorName = std::string; |
| 30 | using ObjectPath = std::string; |
| 31 | using InterfaceKey = std::tuple<ObjectPath, InterfaceName>; |
| 32 | |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 33 | /** |
| 34 | * @class ThresholdAlarmLogger |
| 35 | * |
| 36 | * This class watches the threshold interfaces |
| 37 | * openbmc_project.Sensor.Threshold.Warning |
| 38 | * openbmc_project.Sensor.Threshold.Critical |
| 39 | * openbmc_project.Sensor.Threshold.PerformanceLoss |
| 40 | * |
| 41 | * and creates event logs when their high and low alarm |
| 42 | * properties set and clear. The error names of the |
| 43 | * event logs are based on the sensor type and look like: |
| 44 | * |
| 45 | * xyz.openbmc_project.Sensor.Threshold.Error.TemperatureWarningHigh |
| 46 | * xyz.openbmc_project.Sensor.Threshold.Error.TemperatureWarningHighClear |
Matt Spinler | 66e75a7 | 2021-05-14 10:32:47 -0500 | [diff] [blame] | 47 | * |
| 48 | * Event logs are only created when the power is on. |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 49 | */ |
| 50 | class ThresholdAlarmLogger |
| 51 | { |
| 52 | public: |
| 53 | ThresholdAlarmLogger() = delete; |
| 54 | ~ThresholdAlarmLogger() = default; |
| 55 | ThresholdAlarmLogger(const ThresholdAlarmLogger&) = default; |
| 56 | ThresholdAlarmLogger& operator=(const ThresholdAlarmLogger&) = default; |
| 57 | ThresholdAlarmLogger(ThresholdAlarmLogger&&) = default; |
| 58 | ThresholdAlarmLogger& operator=(ThresholdAlarmLogger&&) = default; |
| 59 | |
| 60 | /** |
| 61 | * @brief Constructor |
| 62 | * |
| 63 | * Looks for existing active threshold alarms. |
| 64 | * |
| 65 | * @param[in] bus - The sdbusplus bus object |
| 66 | * @param[in] event - The sdeventplus event object |
Matt Spinler | 7f6946b | 2021-05-14 12:43:50 -0500 | [diff] [blame] | 67 | * @param[in] powerState - The PowerState object |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 68 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 69 | ThresholdAlarmLogger(sdbusplus::bus_t& bus, sdeventplus::Event& event, |
Matt Spinler | 7f6946b | 2021-05-14 12:43:50 -0500 | [diff] [blame] | 70 | std::shared_ptr<phosphor::fan::PowerState> powerState); |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 71 | |
| 72 | private: |
| 73 | /** |
| 74 | * @brief The propertiesChanged handler for all of the thresholds |
| 75 | * interfaces. |
| 76 | * |
| 77 | * Creates event logs for high/low alarm sets and clears. |
| 78 | * |
| 79 | * @param[in] msg - The signal message payload. |
| 80 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 81 | void propertiesChanged(sdbusplus::message_t& msg); |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 82 | |
| 83 | /** |
Matt Spinler | 9c13602 | 2021-10-18 10:16:09 -0500 | [diff] [blame] | 84 | * @brief The interfacesRemoved removed handler for the threshold |
| 85 | * interfaces. |
| 86 | * |
| 87 | * Removes that threshold from the alarms map |
| 88 | * |
| 89 | * @param[in] msg - The signal message payload. |
| 90 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 91 | void interfacesRemoved(sdbusplus::message_t& msg); |
Matt Spinler | 9c13602 | 2021-10-18 10:16:09 -0500 | [diff] [blame] | 92 | |
| 93 | /** |
Matt Spinler | 8ce6507 | 2022-11-03 15:15:55 -0400 | [diff] [blame] | 94 | * @brief The interfacesAdded handler for the threshold |
| 95 | * interfaces. |
| 96 | * |
| 97 | * Checks the alarm when it shows up on D-Bus. |
| 98 | * |
| 99 | * @param[in] msg - The signal message payload. |
| 100 | */ |
| 101 | void interfacesAdded(sdbusplus::message_t& msg); |
| 102 | |
| 103 | /** |
| 104 | * @brief Checks for alarms in the D-Bus data passed in, |
| 105 | * and creates an event log if necessary. |
| 106 | * |
| 107 | * @param[in] sensorPath - D-Bus path of the sensor |
| 108 | * @param[in] interface - The threshold interface name |
| 109 | * @param[in] properties - The map of property values on the interface |
| 110 | */ |
| 111 | void checkProperties( |
| 112 | const std::string& sensorPath, const std::string& interface, |
| 113 | const std::map<std::string, std::variant<bool>>& properties); |
| 114 | |
| 115 | /** |
Matt Spinler | 50bf816 | 2021-02-01 16:24:01 -0600 | [diff] [blame] | 116 | * @brief Checks for active alarms on the path and threshold interface |
| 117 | * passed in and creates event logs if necessary. |
| 118 | * |
| 119 | * @param[in] interface - The threshold interface |
| 120 | * @param[in] sensorPath - The sensor D-Bus path |
| 121 | * @param[in] service - The D-Bus service that owns the interface |
| 122 | */ |
| 123 | void checkThresholds(const std::string& interface, |
| 124 | const std::string& sensorPath, |
| 125 | const std::string& service); |
| 126 | |
| 127 | /** |
Matt Spinler | 66e75a7 | 2021-05-14 10:32:47 -0500 | [diff] [blame] | 128 | * @brief Checks for all active alarms on all existing |
| 129 | * threshold interfaces and creates event logs |
| 130 | * if necessary. |
| 131 | */ |
| 132 | void checkThresholds(); |
| 133 | |
| 134 | /** |
Matt Spinler | 50bf816 | 2021-02-01 16:24:01 -0600 | [diff] [blame] | 135 | * @brief Creates an event log for the alarm set/clear |
| 136 | * |
| 137 | * @param[in] sensorPath - The sensor object path |
| 138 | * @param[in] interface - The threshold interface |
| 139 | * @param[in] alarmProperty - The alarm property name |
| 140 | * @param[in] alarmValue - The alarm value |
| 141 | */ |
| 142 | void createEventLog(const std::string& sensorPath, |
| 143 | const std::string& interface, |
| 144 | const std::string& alarmProperty, bool alarmValue); |
| 145 | |
| 146 | /** |
Matt Spinler | 2f18267 | 2021-02-01 16:51:38 -0600 | [diff] [blame] | 147 | * @brief Returns the type of the sensor using the path segment |
| 148 | * that precedes the sensor name. |
| 149 | * |
| 150 | * /xyz/openbmc_project/sensors/voltage/vout -> type == voltage |
| 151 | * |
| 152 | * @param[in] sensorPath - The sensor object path name |
| 153 | * |
| 154 | * @return std::string The type segment |
| 155 | */ |
| 156 | std::string getSensorType(std::string sensorPath); |
| 157 | |
| 158 | /** |
| 159 | * @brief Allows for skipping event logs based on the sensor type. |
| 160 | * |
| 161 | * Specifically for the 'utilization' type because its provider |
| 162 | * doesn't support configurable thresholds yet. |
| 163 | * |
| 164 | * @param[in] type - The sensor type, like 'temperature'. |
| 165 | * @return bool - If it can be skipped or not. |
| 166 | */ |
| 167 | bool skipSensorType(const std::string& type); |
| 168 | |
| 169 | /** |
| 170 | * @brief Returns the inventory path to use for a FRU callout |
| 171 | * for the alarm exceeded errors. |
| 172 | * |
| 173 | * It finds the path by looking for 'inventory' or 'chassis' |
| 174 | * association objects on the sensor that point to a FRU. |
| 175 | * |
| 176 | * @param[in] std::string - The sensor object path |
| 177 | * @return std::string - The inventory path for the FRU callout. |
| 178 | * May be empty if none found. |
| 179 | */ |
| 180 | std::string getCallout(const std::string& sensorPath); |
| 181 | |
| 182 | /** |
Matt Spinler | 66e75a7 | 2021-05-14 10:32:47 -0500 | [diff] [blame] | 183 | * @brief The power state changed handler. |
| 184 | * |
| 185 | * Checks alarms when power is turned on. |
| 186 | * |
| 187 | * @param[in] powerStateOn - If the power is now on or off. |
| 188 | */ |
| 189 | void powerStateChanged(bool powerStateOn); |
| 190 | |
| 191 | /** |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 192 | * @brief The sdbusplus bus object |
| 193 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 194 | sdbusplus::bus_t& bus; |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * @brief The sdeventplus Event object |
| 198 | */ |
| 199 | sdeventplus::Event& event; |
| 200 | |
| 201 | /** |
Matt Spinler | 66e75a7 | 2021-05-14 10:32:47 -0500 | [diff] [blame] | 202 | * @brief The PowerState object to track power state changes. |
| 203 | */ |
Matt Spinler | 7f6946b | 2021-05-14 12:43:50 -0500 | [diff] [blame] | 204 | std::shared_ptr<phosphor::fan::PowerState> _powerState; |
Matt Spinler | 66e75a7 | 2021-05-14 10:32:47 -0500 | [diff] [blame] | 205 | |
| 206 | /** |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 207 | * @brief The Warning interface match object |
| 208 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 209 | sdbusplus::bus::match_t warningMatch; |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 210 | |
| 211 | /** |
| 212 | * @brief The Critical interface match object |
| 213 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 214 | sdbusplus::bus::match_t criticalMatch; |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * @brief The PerformanceLoss interface match object |
| 218 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 219 | sdbusplus::bus::match_t perfLossMatch; |
Matt Spinler | 50bf816 | 2021-02-01 16:24:01 -0600 | [diff] [blame] | 220 | |
| 221 | /** |
Matt Spinler | b7a5540 | 2021-10-11 13:45:35 -0500 | [diff] [blame] | 222 | * @brief The InterfacesRemoved match object |
| 223 | */ |
Patrick Williams | cb356d4 | 2022-07-22 19:26:53 -0500 | [diff] [blame] | 224 | sdbusplus::bus::match_t ifacesRemovedMatch; |
Matt Spinler | b7a5540 | 2021-10-11 13:45:35 -0500 | [diff] [blame] | 225 | |
| 226 | /** |
Matt Spinler | 8ce6507 | 2022-11-03 15:15:55 -0400 | [diff] [blame] | 227 | * @brief The InterfacesAdded match object |
| 228 | */ |
| 229 | sdbusplus::bus::match_t ifacesAddedMatch; |
| 230 | |
| 231 | /** |
Matt Spinler | 50bf816 | 2021-02-01 16:24:01 -0600 | [diff] [blame] | 232 | * @brief The current alarm values |
| 233 | */ |
| 234 | std::map<InterfaceKey, std::map<PropertyName, bool>> alarms; |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 235 | }; |
| 236 | |
| 237 | } // namespace sensor::monitor |