blob: 07dce13de47c01ae9a4622144c4b40900e2362bb [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
18#include <sdbusplus/bus.hpp>
19#include <sdbusplus/bus/match.hpp>
20#include <sdeventplus/event.hpp>
21
22namespace sensor::monitor
23{
24
Matt Spinler50bf8162021-02-01 16:24:01 -060025using InterfaceName = std::string;
26using PropertyName = std::string;
27using ErrorName = std::string;
28using ObjectPath = std::string;
29using InterfaceKey = std::tuple<ObjectPath, InterfaceName>;
30
Matt Spinler403d1f52021-02-01 15:35:25 -060031/**
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 */
46class 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 Spinler50bf8162021-02-01 16:24:01 -060078 * @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 Spinler2f182672021-02-01 16:51:38 -0600102 * @brief Returns the type of the sensor using the path segment
103 * that precedes the sensor name.
104 *
105 * /xyz/openbmc_project/sensors/voltage/vout -> type == voltage
106 *
107 * @param[in] sensorPath - The sensor object path name
108 *
109 * @return std::string The type segment
110 */
111 std::string getSensorType(std::string sensorPath);
112
113 /**
114 * @brief Allows for skipping event logs based on the sensor type.
115 *
116 * Specifically for the 'utilization' type because its provider
117 * doesn't support configurable thresholds yet.
118 *
119 * @param[in] type - The sensor type, like 'temperature'.
120 * @return bool - If it can be skipped or not.
121 */
122 bool skipSensorType(const std::string& type);
123
124 /**
125 * @brief Returns the inventory path to use for a FRU callout
126 * for the alarm exceeded errors.
127 *
128 * It finds the path by looking for 'inventory' or 'chassis'
129 * association objects on the sensor that point to a FRU.
130 *
131 * @param[in] std::string - The sensor object path
132 * @return std::string - The inventory path for the FRU callout.
133 * May be empty if none found.
134 */
135 std::string getCallout(const std::string& sensorPath);
136
137 /**
Matt Spinler403d1f52021-02-01 15:35:25 -0600138 * @brief The sdbusplus bus object
139 */
140 sdbusplus::bus::bus& bus;
141
142 /**
143 * @brief The sdeventplus Event object
144 */
145 sdeventplus::Event& event;
146
147 /**
148 * @brief The Warning interface match object
149 */
150 sdbusplus::bus::match::match warningMatch;
151
152 /**
153 * @brief The Critical interface match object
154 */
155 sdbusplus::bus::match::match criticalMatch;
156
157 /**
158 * @brief The PerformanceLoss interface match object
159 */
160 sdbusplus::bus::match::match perfLossMatch;
Matt Spinler50bf8162021-02-01 16:24:01 -0600161
162 /**
163 * @brief The current alarm values
164 */
165 std::map<InterfaceKey, std::map<PropertyName, bool>> alarms;
Matt Spinler403d1f52021-02-01 15:35:25 -0600166};
167
168} // namespace sensor::monitor