Check for sensor parameters before using them
This change adds a find() call to only attempt to get and use
sensor parameters if they exist.
Tested:
Triggered a threshold sensor and confirmed that the event is
logged.
Change-Id: I064cafdf179703f22dd765d0bebe7b887f443a57
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/include/threshold_event_monitor.hpp b/include/threshold_event_monitor.hpp
index 74cc86e..b2473ef 100644
--- a/include/threshold_event_monitor.hpp
+++ b/include/threshold_event_monitor.hpp
@@ -127,12 +127,25 @@
<< "\n";
return;
}
- double max =
- std::visit(ipmi::VariantToDoubleVisitor(), sensorValue["MaxValue"]);
- double min =
- std::visit(ipmi::VariantToDoubleVisitor(), sensorValue["MinValue"]);
- double sensorVal =
- std::visit(ipmi::VariantToDoubleVisitor(), sensorValue["Value"]);
+ double max = 0;
+ auto findMax = sensorValue.find("MaxValue");
+ if (findMax != sensorValue.end())
+ {
+ max = std::visit(ipmi::VariantToDoubleVisitor(), findMax->second);
+ }
+ double min = 0;
+ auto findMin = sensorValue.find("MinValue");
+ if (findMin != sensorValue.end())
+ {
+ min = std::visit(ipmi::VariantToDoubleVisitor(), findMin->second);
+ }
+ double sensorVal = 0;
+ auto findVal = sensorValue.find("Value");
+ if (findVal != sensorValue.end())
+ {
+ sensorVal =
+ std::visit(ipmi::VariantToDoubleVisitor(), findVal->second);
+ }
try
{
eventData[1] = ipmi::getScaledIPMIValue(sensorVal, max, min);