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