blob: 3e611d8adb8e5cbd79cae22dda023b2eba1f7615 [file] [log] [blame]
Matt Spinler403d1f52021-02-01 15:35:25 -06001/**
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 Spinler66e75a72021-05-14 10:32:47 -050018#include "power_state.hpp"
19
Matt Spinler403d1f52021-02-01 15:35:25 -060020#include <sdbusplus/bus.hpp>
21#include <sdbusplus/bus/match.hpp>
22#include <sdeventplus/event.hpp>
23
24namespace sensor::monitor
25{
26
Matt Spinler50bf8162021-02-01 16:24:01 -060027using InterfaceName = std::string;
28using PropertyName = std::string;
29using ErrorName = std::string;
30using ObjectPath = std::string;
31using InterfaceKey = std::tuple<ObjectPath, InterfaceName>;
32
Matt Spinler403d1f52021-02-01 15:35:25 -060033/**
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 Spinler66e75a72021-05-14 10:32:47 -050047 *
48 * Event logs are only created when the power is on.
Matt Spinler403d1f52021-02-01 15:35:25 -060049 */
50class 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
67 */
68 ThresholdAlarmLogger(sdbusplus::bus::bus& bus, sdeventplus::Event& event);
69
70 private:
71 /**
72 * @brief The propertiesChanged handler for all of the thresholds
73 * interfaces.
74 *
75 * Creates event logs for high/low alarm sets and clears.
76 *
77 * @param[in] msg - The signal message payload.
78 */
79 void propertiesChanged(sdbusplus::message::message& msg);
80
81 /**
Matt Spinler50bf8162021-02-01 16:24:01 -060082 * @brief Checks for active alarms on the path and threshold interface
83 * passed in and creates event logs if necessary.
84 *
85 * @param[in] interface - The threshold interface
86 * @param[in] sensorPath - The sensor D-Bus path
87 * @param[in] service - The D-Bus service that owns the interface
88 */
89 void checkThresholds(const std::string& interface,
90 const std::string& sensorPath,
91 const std::string& service);
92
93 /**
Matt Spinler66e75a72021-05-14 10:32:47 -050094 * @brief Checks for all active alarms on all existing
95 * threshold interfaces and creates event logs
96 * if necessary.
97 */
98 void checkThresholds();
99
100 /**
Matt Spinler50bf8162021-02-01 16:24:01 -0600101 * @brief Creates an event log for the alarm set/clear
102 *
103 * @param[in] sensorPath - The sensor object path
104 * @param[in] interface - The threshold interface
105 * @param[in] alarmProperty - The alarm property name
106 * @param[in] alarmValue - The alarm value
107 */
108 void createEventLog(const std::string& sensorPath,
109 const std::string& interface,
110 const std::string& alarmProperty, bool alarmValue);
111
112 /**
Matt Spinler2f182672021-02-01 16:51:38 -0600113 * @brief Returns the type of the sensor using the path segment
114 * that precedes the sensor name.
115 *
116 * /xyz/openbmc_project/sensors/voltage/vout -> type == voltage
117 *
118 * @param[in] sensorPath - The sensor object path name
119 *
120 * @return std::string The type segment
121 */
122 std::string getSensorType(std::string sensorPath);
123
124 /**
125 * @brief Allows for skipping event logs based on the sensor type.
126 *
127 * Specifically for the 'utilization' type because its provider
128 * doesn't support configurable thresholds yet.
129 *
130 * @param[in] type - The sensor type, like 'temperature'.
131 * @return bool - If it can be skipped or not.
132 */
133 bool skipSensorType(const std::string& type);
134
135 /**
136 * @brief Returns the inventory path to use for a FRU callout
137 * for the alarm exceeded errors.
138 *
139 * It finds the path by looking for 'inventory' or 'chassis'
140 * association objects on the sensor that point to a FRU.
141 *
142 * @param[in] std::string - The sensor object path
143 * @return std::string - The inventory path for the FRU callout.
144 * May be empty if none found.
145 */
146 std::string getCallout(const std::string& sensorPath);
147
148 /**
Matt Spinler66e75a72021-05-14 10:32:47 -0500149 * @brief The power state changed handler.
150 *
151 * Checks alarms when power is turned on.
152 *
153 * @param[in] powerStateOn - If the power is now on or off.
154 */
155 void powerStateChanged(bool powerStateOn);
156
157 /**
Matt Spinler403d1f52021-02-01 15:35:25 -0600158 * @brief The sdbusplus bus object
159 */
160 sdbusplus::bus::bus& bus;
161
162 /**
163 * @brief The sdeventplus Event object
164 */
165 sdeventplus::Event& event;
166
167 /**
Matt Spinler66e75a72021-05-14 10:32:47 -0500168 * @brief The PowerState object to track power state changes.
169 */
170 std::unique_ptr<phosphor::fan::PowerState> _powerState;
171
172 /**
Matt Spinler403d1f52021-02-01 15:35:25 -0600173 * @brief The Warning interface match object
174 */
175 sdbusplus::bus::match::match warningMatch;
176
177 /**
178 * @brief The Critical interface match object
179 */
180 sdbusplus::bus::match::match criticalMatch;
181
182 /**
183 * @brief The PerformanceLoss interface match object
184 */
185 sdbusplus::bus::match::match perfLossMatch;
Matt Spinler50bf8162021-02-01 16:24:01 -0600186
187 /**
188 * @brief The current alarm values
189 */
190 std::map<InterfaceKey, std::map<PropertyName, bool>> alarms;
Matt Spinler403d1f52021-02-01 15:35:25 -0600191};
192
193} // namespace sensor::monitor