healthMonitor: call configured unit when threshold exceeded
Add threshold target implementation.
Call the system target unit configured in config file when threshold
value exceeded.
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
Change-Id: I31f0cf4df0c913f10c47ecb9fa24b59b7b9de0e5
diff --git a/healthMonitor.cpp b/healthMonitor.cpp
index c87e4f0..3523b79 100644
--- a/healthMonitor.cpp
+++ b/healthMonitor.cpp
@@ -322,9 +322,12 @@
{
CriticalInterface::criticalAlarmHigh(true);
if (sensorConfig.criticalLog)
+ {
error(
"ASSERT: sensor {SENSOR} is above the upper threshold critical high",
"SENSOR", sensorConfig.name);
+ startUnit(sensorConfig.criticalTgt);
+ }
}
return;
}
@@ -345,9 +348,12 @@
{
WarningInterface::warningAlarmHigh(true);
if (sensorConfig.warningLog)
+ {
error(
"ASSERT: sensor {SENSOR} is above the upper threshold warning high",
"SENSOR", sensorConfig.name);
+ startUnit(sensorConfig.warningTgt);
+ }
}
return;
}
@@ -404,6 +410,20 @@
checkSensorThreshold(avgValue);
}
+void HealthSensor::startUnit(const std::string& sysdUnit)
+{
+ if (sysdUnit.empty())
+ {
+ return;
+ }
+
+ sdbusplus::message::message msg = bus.new_method_call(
+ "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager", "StartUnit");
+ msg.append(sysdUnit, "replace");
+ bus.call_noreply(msg);
+}
+
void HealthMon::recreateSensors()
{
PHOSPHOR_LOG2_USING;
diff --git a/healthMonitor.hpp b/healthMonitor.hpp
index d327cf0..b5013c8 100644
--- a/healthMonitor.hpp
+++ b/healthMonitor.hpp
@@ -125,6 +125,8 @@
sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> readTimer;
/** @brief Read sensor at regular intrval */
void readHealthSensor();
+ /** @brief Start configured threshold systemd unit */
+ void startUnit(const std::string& sysdUnit);
};
class HealthMon