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