Check threshold values

Added check threshold functionality and logging required messages.

Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
Change-Id: I02a1fdff43754a913abbadff74c440fe8eda9bd4
diff --git a/healthMonitor.cpp b/healthMonitor.cpp
index 42bf77d..f7ca6ce 100644
--- a/healthMonitor.cpp
+++ b/healthMonitor.cpp
@@ -173,6 +173,51 @@
     readTimer.restart(std::chrono::milliseconds(sensorConfig.freq * 1000));
 }
 
+void HealthSensor::checkSensorThreshold(const double value)
+{
+    if (value > sensorConfig.criticalHigh)
+    {
+        if (!CriticalInterface::criticalAlarmHigh())
+        {
+            CriticalInterface::criticalAlarmHigh(true);
+            if (sensorConfig.criticalLog)
+                log<level::ERR>("ASSERT: Utilization Sensor has exceeded "
+                                "critical high threshold",
+                                entry("NAME = %s", sensorConfig.name.c_str()));
+        }
+    }
+    else
+    {
+        if (CriticalInterface::criticalAlarmHigh())
+        {
+            CriticalInterface::criticalAlarmHigh(false);
+            if (sensorConfig.criticalLog)
+                log<level::INFO>("DEASSERT: Utilization Sensor is under "
+                                 "critical high threshold",
+                                 entry("NAME = %s", sensorConfig.name.c_str()));
+        }
+
+        if ((value > sensorConfig.warningHigh) &&
+            (!WarningInterface::warningAlarmHigh()))
+        {
+            WarningInterface::warningAlarmHigh(true);
+            if (sensorConfig.warningLog)
+                log<level::ERR>("ASSERT: Utilization Sensor has exceeded "
+                                "warning high threshold",
+                                entry("NAME = %s", sensorConfig.name.c_str()));
+        }
+        else if ((value <= sensorConfig.warningHigh) &&
+                 (WarningInterface::warningAlarmHigh()))
+        {
+            WarningInterface::warningAlarmHigh(false);
+            if (sensorConfig.warningLog)
+                log<level::INFO>("DEASSERT: Utilization Sensor is under "
+                                 "warning high threshold",
+                                 entry("NAME = %s", sensorConfig.name.c_str()));
+        }
+    }
+}
+
 void HealthSensor::readHealthSensor()
 {
     /* Read current sensor value */
@@ -196,6 +241,9 @@
 
     /* Set this new value to dbus */
     setSensorValueToDbus(avgValue);
+
+    /* Check the sensor threshold  and log required message */
+    checkSensorThreshold(avgValue);
 }
 
 void printConfig(HealthConfig& cfg)