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 | |
| 18 | #include <sdbusplus/bus.hpp> |
| 19 | #include <sdbusplus/bus/match.hpp> |
| 20 | #include <sdeventplus/event.hpp> |
| 21 | |
| 22 | namespace sensor::monitor |
| 23 | { |
| 24 | |
Matt Spinler | 50bf816 | 2021-02-01 16:24:01 -0600 | [diff] [blame] | 25 | using InterfaceName = std::string; |
| 26 | using PropertyName = std::string; |
| 27 | using ErrorName = std::string; |
| 28 | using ObjectPath = std::string; |
| 29 | using InterfaceKey = std::tuple<ObjectPath, InterfaceName>; |
| 30 | |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 31 | /** |
| 32 | * @class ThresholdAlarmLogger |
| 33 | * |
| 34 | * This class watches the threshold interfaces |
| 35 | * openbmc_project.Sensor.Threshold.Warning |
| 36 | * openbmc_project.Sensor.Threshold.Critical |
| 37 | * openbmc_project.Sensor.Threshold.PerformanceLoss |
| 38 | * |
| 39 | * and creates event logs when their high and low alarm |
| 40 | * properties set and clear. The error names of the |
| 41 | * event logs are based on the sensor type and look like: |
| 42 | * |
| 43 | * xyz.openbmc_project.Sensor.Threshold.Error.TemperatureWarningHigh |
| 44 | * xyz.openbmc_project.Sensor.Threshold.Error.TemperatureWarningHighClear |
| 45 | */ |
| 46 | class ThresholdAlarmLogger |
| 47 | { |
| 48 | public: |
| 49 | ThresholdAlarmLogger() = delete; |
| 50 | ~ThresholdAlarmLogger() = default; |
| 51 | ThresholdAlarmLogger(const ThresholdAlarmLogger&) = default; |
| 52 | ThresholdAlarmLogger& operator=(const ThresholdAlarmLogger&) = default; |
| 53 | ThresholdAlarmLogger(ThresholdAlarmLogger&&) = default; |
| 54 | ThresholdAlarmLogger& operator=(ThresholdAlarmLogger&&) = default; |
| 55 | |
| 56 | /** |
| 57 | * @brief Constructor |
| 58 | * |
| 59 | * Looks for existing active threshold alarms. |
| 60 | * |
| 61 | * @param[in] bus - The sdbusplus bus object |
| 62 | * @param[in] event - The sdeventplus event object |
| 63 | */ |
| 64 | ThresholdAlarmLogger(sdbusplus::bus::bus& bus, sdeventplus::Event& event); |
| 65 | |
| 66 | private: |
| 67 | /** |
| 68 | * @brief The propertiesChanged handler for all of the thresholds |
| 69 | * interfaces. |
| 70 | * |
| 71 | * Creates event logs for high/low alarm sets and clears. |
| 72 | * |
| 73 | * @param[in] msg - The signal message payload. |
| 74 | */ |
| 75 | void propertiesChanged(sdbusplus::message::message& msg); |
| 76 | |
| 77 | /** |
Matt Spinler | 50bf816 | 2021-02-01 16:24:01 -0600 | [diff] [blame] | 78 | * @brief Checks for active alarms on the path and threshold interface |
| 79 | * passed in and creates event logs if necessary. |
| 80 | * |
| 81 | * @param[in] interface - The threshold interface |
| 82 | * @param[in] sensorPath - The sensor D-Bus path |
| 83 | * @param[in] service - The D-Bus service that owns the interface |
| 84 | */ |
| 85 | void checkThresholds(const std::string& interface, |
| 86 | const std::string& sensorPath, |
| 87 | const std::string& service); |
| 88 | |
| 89 | /** |
| 90 | * @brief Creates an event log for the alarm set/clear |
| 91 | * |
| 92 | * @param[in] sensorPath - The sensor object path |
| 93 | * @param[in] interface - The threshold interface |
| 94 | * @param[in] alarmProperty - The alarm property name |
| 95 | * @param[in] alarmValue - The alarm value |
| 96 | */ |
| 97 | void createEventLog(const std::string& sensorPath, |
| 98 | const std::string& interface, |
| 99 | const std::string& alarmProperty, bool alarmValue); |
| 100 | |
| 101 | /** |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 102 | * @brief The sdbusplus bus object |
| 103 | */ |
| 104 | sdbusplus::bus::bus& bus; |
| 105 | |
| 106 | /** |
| 107 | * @brief The sdeventplus Event object |
| 108 | */ |
| 109 | sdeventplus::Event& event; |
| 110 | |
| 111 | /** |
| 112 | * @brief The Warning interface match object |
| 113 | */ |
| 114 | sdbusplus::bus::match::match warningMatch; |
| 115 | |
| 116 | /** |
| 117 | * @brief The Critical interface match object |
| 118 | */ |
| 119 | sdbusplus::bus::match::match criticalMatch; |
| 120 | |
| 121 | /** |
| 122 | * @brief The PerformanceLoss interface match object |
| 123 | */ |
| 124 | sdbusplus::bus::match::match perfLossMatch; |
Matt Spinler | 50bf816 | 2021-02-01 16:24:01 -0600 | [diff] [blame] | 125 | |
| 126 | /** |
| 127 | * @brief The current alarm values |
| 128 | */ |
| 129 | std::map<InterfaceKey, std::map<PropertyName, bool>> alarms; |
Matt Spinler | 403d1f5 | 2021-02-01 15:35:25 -0600 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | } // namespace sensor::monitor |