Patrick Venture | ca44b2f | 2019-10-31 11:02:26 -0700 | [diff] [blame] | 1 | #include "Thresholds.hpp" |
| 2 | |
| 3 | #include "VariantVisitors.hpp" |
| 4 | #include "sensor.hpp" |
| 5 | |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 6 | #include <array> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 7 | #include <boost/algorithm/string/replace.hpp> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 8 | #include <boost/container/flat_map.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 9 | #include <boost/lexical_cast.hpp> |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 10 | #include <cmath> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 11 | #include <fstream> |
| 12 | #include <iostream> |
Patrick Venture | 96e97db | 2019-10-31 13:44:38 -0700 | [diff] [blame] | 13 | #include <memory> |
| 14 | #include <stdexcept> |
| 15 | #include <string> |
| 16 | #include <utility> |
| 17 | #include <variant> |
| 18 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 19 | |
| 20 | static constexpr bool DEBUG = false; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 21 | namespace thresholds |
| 22 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 23 | unsigned int toBusValue(const Level& level) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 24 | { |
| 25 | switch (level) |
| 26 | { |
| 27 | case (Level::WARNING): |
| 28 | { |
| 29 | return 0; |
| 30 | } |
| 31 | case (Level::CRITICAL): |
| 32 | { |
| 33 | return 1; |
| 34 | } |
| 35 | default: |
| 36 | { |
| 37 | return -1; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 42 | std::string toBusValue(const Direction& direction) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 43 | { |
| 44 | switch (direction) |
| 45 | { |
| 46 | case (Direction::LOW): |
| 47 | { |
| 48 | return "less than"; |
| 49 | } |
| 50 | case (Direction::HIGH): |
| 51 | { |
| 52 | return "greater than"; |
| 53 | } |
| 54 | default: |
| 55 | { |
| 56 | return "err"; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 61 | bool parseThresholdsFromConfig( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 62 | const SensorData& sensorData, |
| 63 | std::vector<thresholds::Threshold>& thresholdVector, |
| 64 | const std::string* matchLabel) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 65 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 66 | for (const auto& item : sensorData) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 67 | { |
| 68 | if (item.first.find("Thresholds") == std::string::npos) |
| 69 | { |
| 70 | continue; |
| 71 | } |
| 72 | if (matchLabel != nullptr) |
| 73 | { |
| 74 | auto labelFind = item.second.find("Label"); |
| 75 | if (labelFind == item.second.end()) |
| 76 | continue; |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 77 | if (std::visit(VariantToStringVisitor(), labelFind->second) != |
| 78 | *matchLabel) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 79 | continue; |
| 80 | } |
| 81 | auto directionFind = item.second.find("Direction"); |
| 82 | auto severityFind = item.second.find("Severity"); |
| 83 | auto valueFind = item.second.find("Value"); |
| 84 | if (valueFind == item.second.end() || |
| 85 | severityFind == item.second.end() || |
| 86 | directionFind == item.second.end()) |
| 87 | { |
| 88 | std::cerr << "Malformed threshold in configuration\n"; |
| 89 | return false; |
| 90 | } |
| 91 | Level level; |
| 92 | Direction direction; |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 93 | if (std::visit(VariantToUnsignedIntVisitor(), severityFind->second) == |
| 94 | 0) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 95 | { |
| 96 | level = Level::WARNING; |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | level = Level::CRITICAL; |
| 101 | } |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 102 | if (std::visit(VariantToStringVisitor(), directionFind->second) == |
| 103 | "less than") |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 104 | { |
| 105 | direction = Direction::LOW; |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | direction = Direction::HIGH; |
| 110 | } |
James Feist | 13f340b | 2019-03-07 16:36:11 -0800 | [diff] [blame] | 111 | double val = std::visit(VariantToDoubleVisitor(), valueFind->second); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 112 | |
| 113 | thresholdVector.emplace_back(level, direction, val); |
| 114 | } |
| 115 | return true; |
| 116 | } |
| 117 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 118 | void persistThreshold(const std::string& path, const std::string& baseInterface, |
| 119 | const thresholds::Threshold& threshold, |
James Feist | a222ba7 | 2019-03-01 15:57:51 -0800 | [diff] [blame] | 120 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 121 | size_t thresholdCount) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 122 | { |
Brad Bishop | fbb44ad | 2019-11-08 09:42:37 -0500 | [diff] [blame] | 123 | for (size_t ii = 0; ii < thresholdCount; ii++) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 124 | { |
| 125 | std::string thresholdInterface = |
| 126 | baseInterface + ".Thresholds" + std::to_string(ii); |
| 127 | conn->async_method_call( |
| 128 | [&, path, threshold, thresholdInterface]( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 129 | const boost::system::error_code& ec, |
| 130 | const boost::container::flat_map<std::string, BasicVariantType>& |
| 131 | result) { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 132 | if (ec) |
| 133 | { |
| 134 | return; // threshold not supported |
| 135 | } |
| 136 | |
| 137 | auto directionFind = result.find("Direction"); |
| 138 | auto severityFind = result.find("Severity"); |
| 139 | auto valueFind = result.find("Value"); |
| 140 | if (valueFind == result.end() || severityFind == result.end() || |
| 141 | directionFind == result.end()) |
| 142 | { |
| 143 | std::cerr << "Malformed threshold in configuration\n"; |
| 144 | return; |
| 145 | } |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 146 | unsigned int level = std::visit(VariantToUnsignedIntVisitor(), |
| 147 | severityFind->second); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 148 | |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 149 | std::string dir = |
| 150 | std::visit(VariantToStringVisitor(), directionFind->second); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 151 | if ((toBusValue(threshold.level) != level) || |
| 152 | (toBusValue(threshold.direction) != dir)) |
| 153 | { |
| 154 | return; // not the droid we're looking for |
| 155 | } |
| 156 | |
James Feist | 3eb8262 | 2019-02-08 13:10:22 -0800 | [diff] [blame] | 157 | std::variant<double> value(threshold.value); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 158 | conn->async_method_call( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 159 | [](const boost::system::error_code& ec) { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 160 | if (ec) |
| 161 | { |
| 162 | std::cerr << "Error setting threshold " << ec |
| 163 | << "\n"; |
| 164 | } |
| 165 | }, |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 166 | entityManagerName, path, "org.freedesktop.DBus.Properties", |
| 167 | "Set", thresholdInterface, "Value", value); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 168 | }, |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 169 | entityManagerName, path, "org.freedesktop.DBus.Properties", |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 170 | "GetAll", thresholdInterface); |
| 171 | } |
| 172 | } |
| 173 | |
Jae Hyun Yoo | 95b8a2d | 2019-02-25 20:15:09 -0800 | [diff] [blame] | 174 | void updateThresholds(Sensor* sensor) |
| 175 | { |
| 176 | if (sensor->thresholds.empty()) |
| 177 | { |
| 178 | return; |
| 179 | } |
| 180 | |
| 181 | for (const auto& threshold : sensor->thresholds) |
| 182 | { |
| 183 | std::shared_ptr<sdbusplus::asio::dbus_interface> interface; |
| 184 | std::string property; |
| 185 | if (threshold.level == thresholds::Level::CRITICAL) |
| 186 | { |
| 187 | interface = sensor->thresholdInterfaceCritical; |
| 188 | if (threshold.direction == thresholds::Direction::HIGH) |
| 189 | { |
| 190 | property = "CriticalHigh"; |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | property = "CriticalLow"; |
| 195 | } |
| 196 | } |
| 197 | else if (threshold.level == thresholds::Level::WARNING) |
| 198 | { |
| 199 | interface = sensor->thresholdInterfaceWarning; |
| 200 | if (threshold.direction == thresholds::Direction::HIGH) |
| 201 | { |
| 202 | property = "WarningHigh"; |
| 203 | } |
| 204 | else |
| 205 | { |
| 206 | property = "WarningLow"; |
| 207 | } |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | continue; |
| 212 | } |
| 213 | if (!interface) |
| 214 | { |
| 215 | continue; |
| 216 | } |
| 217 | interface->set_property(property, threshold.value); |
| 218 | } |
| 219 | } |
| 220 | |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 221 | static std::vector<std::pair<Threshold, bool>> checkThresholds(Sensor* sensor, |
| 222 | double value) |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 223 | { |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 224 | std::vector<std::pair<Threshold, bool>> thresholdChanges; |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 225 | if (sensor->thresholds.empty()) |
| 226 | { |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 227 | return thresholdChanges; |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 228 | } |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 229 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 230 | for (auto& threshold : sensor->thresholds) |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 231 | { |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 232 | if (threshold.direction == thresholds::Direction::HIGH) |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 233 | { |
James Feist | 551087a | 2019-12-09 11:17:12 -0800 | [diff] [blame^] | 234 | if (value >= threshold.value) |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 235 | { |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 236 | thresholdChanges.push_back(std::make_pair(threshold, true)); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 237 | } |
Patrick Venture | 66235d4 | 2019-10-11 08:31:27 -0700 | [diff] [blame] | 238 | else |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 239 | { |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 240 | thresholdChanges.push_back(std::make_pair(threshold, false)); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | else |
| 244 | { |
James Feist | 551087a | 2019-12-09 11:17:12 -0800 | [diff] [blame^] | 245 | if (value <= threshold.value) |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 246 | { |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 247 | thresholdChanges.push_back(std::make_pair(threshold, true)); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 248 | } |
Patrick Venture | 66235d4 | 2019-10-11 08:31:27 -0700 | [diff] [blame] | 249 | else |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 250 | { |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 251 | thresholdChanges.push_back(std::make_pair(threshold, false)); |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | } |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 255 | return thresholdChanges; |
| 256 | } |
| 257 | |
| 258 | bool checkThresholds(Sensor* sensor) |
| 259 | { |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 260 | bool status = true; |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 261 | std::vector<std::pair<Threshold, bool>> changes = |
| 262 | checkThresholds(sensor, sensor->value); |
| 263 | for (const auto& [threshold, asserted] : changes) |
| 264 | { |
| 265 | assertThresholds(sensor, threshold.level, threshold.direction, |
| 266 | asserted); |
| 267 | if (threshold.level == thresholds::Level::CRITICAL && asserted) |
| 268 | { |
James Feist | 7b18b1e | 2019-05-14 13:42:09 -0700 | [diff] [blame] | 269 | status = false; |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | |
James Feist | dc6c55f | 2018-10-31 12:53:20 -0700 | [diff] [blame] | 273 | return status; |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 274 | } |
| 275 | |
James Feist | 46342ec | 2019-03-06 14:03:41 -0800 | [diff] [blame] | 276 | void checkThresholdsPowerDelay(Sensor* sensor, ThresholdTimer& thresholdTimer) |
| 277 | { |
| 278 | |
| 279 | std::vector<std::pair<Threshold, bool>> changes = |
| 280 | checkThresholds(sensor, sensor->value); |
| 281 | for (const auto& [threshold, asserted] : changes) |
| 282 | { |
| 283 | if (asserted) |
| 284 | { |
| 285 | thresholdTimer.startTimer(threshold); |
| 286 | } |
| 287 | else |
| 288 | { |
| 289 | assertThresholds(sensor, threshold.level, threshold.direction, |
| 290 | false); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 295 | void assertThresholds(Sensor* sensor, thresholds::Level level, |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 296 | thresholds::Direction direction, bool assert) |
| 297 | { |
| 298 | std::string property; |
| 299 | std::shared_ptr<sdbusplus::asio::dbus_interface> interface; |
| 300 | if (level == thresholds::Level::WARNING && |
| 301 | direction == thresholds::Direction::HIGH) |
| 302 | { |
| 303 | property = "WarningAlarmHigh"; |
| 304 | interface = sensor->thresholdInterfaceWarning; |
| 305 | } |
| 306 | else if (level == thresholds::Level::WARNING && |
| 307 | direction == thresholds::Direction::LOW) |
| 308 | { |
| 309 | property = "WarningAlarmLow"; |
| 310 | interface = sensor->thresholdInterfaceWarning; |
| 311 | } |
| 312 | else if (level == thresholds::Level::CRITICAL && |
| 313 | direction == thresholds::Direction::HIGH) |
| 314 | { |
| 315 | property = "CriticalAlarmHigh"; |
| 316 | interface = sensor->thresholdInterfaceCritical; |
| 317 | } |
| 318 | else if (level == thresholds::Level::CRITICAL && |
| 319 | direction == thresholds::Direction::LOW) |
| 320 | { |
| 321 | property = "CriticalAlarmLow"; |
| 322 | interface = sensor->thresholdInterfaceCritical; |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | std::cerr << "Unknown threshold, level " << level << "direction " |
| 327 | << direction << "\n"; |
| 328 | return; |
| 329 | } |
| 330 | if (!interface) |
| 331 | { |
| 332 | std::cout << "trying to set uninitialized interface\n"; |
| 333 | return; |
| 334 | } |
| 335 | interface->set_property(property, assert); |
| 336 | } |
| 337 | |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 338 | static constexpr std::array<const char*, 4> attrTypes = {"lcrit", "min", "max", |
| 339 | "crit"}; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 340 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 341 | bool parseThresholdsFromAttr( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 342 | std::vector<thresholds::Threshold>& thresholdVector, |
Vijay Khemka | 86dea2b | 2019-06-06 11:14:37 -0700 | [diff] [blame] | 343 | const std::string& inputPath, const double& scaleFactor, |
| 344 | const double& offset) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 345 | { |
James Feist | b6c0b91 | 2019-07-09 12:21:44 -0700 | [diff] [blame] | 346 | for (const std::string& type : attrTypes) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 347 | { |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 348 | auto attrPath = boost::replace_all_copy(inputPath, "input", type); |
| 349 | std::ifstream attrFile(attrPath); |
| 350 | if (!attrFile.good()) |
| 351 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 352 | continue; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 353 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 354 | std::string attr; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 355 | std::getline(attrFile, attr); |
| 356 | attrFile.close(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 357 | |
| 358 | Level level; |
| 359 | Direction direction; |
Jae Hyun Yoo | 7fa17c4 | 2019-09-09 13:20:37 -0700 | [diff] [blame] | 360 | double val; |
| 361 | try |
| 362 | { |
| 363 | val = std::stod(attr) / scaleFactor; |
| 364 | } |
| 365 | catch (const std::invalid_argument&) |
| 366 | { |
| 367 | return false; |
| 368 | } |
| 369 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 370 | if (type == "min" || type == "max") |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 371 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 372 | level = Level::WARNING; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 373 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 374 | else |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 375 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 376 | level = Level::CRITICAL; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 377 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 378 | if (type == "min" || type == "lcrit") |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 379 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 380 | direction = Direction::LOW; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 381 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 382 | else |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 383 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 384 | direction = Direction::HIGH; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 385 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 386 | |
Vijay Khemka | 86dea2b | 2019-06-06 11:14:37 -0700 | [diff] [blame] | 387 | if (type == "crit") |
| 388 | { |
| 389 | val += offset; |
| 390 | } |
| 391 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 392 | if (DEBUG) |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 393 | { |
| 394 | std::cout << "Threshold: " << attrPath << ": " << val << "\n"; |
| 395 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 396 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 397 | thresholdVector.emplace_back(level, direction, val); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 398 | } |
Jae Hyun Yoo | 7fa17c4 | 2019-09-09 13:20:37 -0700 | [diff] [blame] | 399 | // no thresholds is allowed, not an error so return true. |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 400 | return true; |
| 401 | } |
| 402 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 403 | bool hasCriticalInterface( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 404 | const std::vector<thresholds::Threshold>& thresholdVector) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 405 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 406 | for (auto& threshold : thresholdVector) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 407 | { |
| 408 | if (threshold.level == Level::CRITICAL) |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 409 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 410 | return true; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 411 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 412 | } |
| 413 | return false; |
| 414 | } |
| 415 | |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 416 | bool hasWarningInterface( |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 417 | const std::vector<thresholds::Threshold>& thresholdVector) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 418 | { |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 419 | for (auto& threshold : thresholdVector) |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 420 | { |
| 421 | if (threshold.level == Level::WARNING) |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 422 | { |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 423 | return true; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 424 | } |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 425 | } |
| 426 | return false; |
| 427 | } |
| 428 | } // namespace thresholds |