Update Trigger Actions implementation
Dbus trigger action names were modified to reflect separation of
Telemetry Service from Redfish:
- LogToLogService is renamed to LogToJournal,
- RedfishEvent was renamed to LogToRedfishEventLog
Both of those logging actions, now also include trigger id and threshold
name. Threshold naming logic:
- For discrete triggers, it can be specified by user, if left empty it
will be changed to "{Severity} condition".
- Numeric triggers have no way of naming threshold, instead its type
will be converted to string, example "UpperWarning"
- Discrete OnChange threshold will always be named "OnChange"
Additionally, defect was found with timestamp attached to Trigger Logs:
it was a steady_clock timestamp instead of system_clock. The function
which was supposed to format it was also working incorrectly, and was
improved to work with milliseconds. This change required major refactor
of unit tests, especially for numeric threshold.
Testing done:
- LogToJournal action is working properly,
- LogToRedfishEventLog action is working properly,
- UTs are passing.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: Iae2490682f0e9e2a610b45fd8af5cc5e21e66f35
diff --git a/src/numeric_threshold.cpp b/src/numeric_threshold.cpp
index cb6dbdd..9bda509 100644
--- a/src/numeric_threshold.cpp
+++ b/src/numeric_threshold.cpp
@@ -3,13 +3,16 @@
#include <phosphor-logging/log.hpp>
NumericThreshold::NumericThreshold(
- boost::asio::io_context& ioc, Sensors sensorsIn,
+ boost::asio::io_context& ioc, const std::string& triggerIdIn,
+ Sensors sensorsIn,
std::vector<std::unique_ptr<interfaces::TriggerAction>> actionsIn,
Milliseconds dwellTimeIn, numeric::Direction directionIn,
- double thresholdValueIn, numeric::Type typeIn) :
+ double thresholdValueIn, numeric::Type typeIn,
+ std::unique_ptr<interfaces::Clock> clockIn) :
ioc(ioc),
- actions(std::move(actionsIn)), dwellTime(dwellTimeIn),
- direction(directionIn), thresholdValue(thresholdValueIn), type(typeIn)
+ triggerId(triggerIdIn), actions(std::move(actionsIn)),
+ dwellTime(dwellTimeIn), direction(directionIn),
+ thresholdValue(thresholdValueIn), type(typeIn), clock(std::move(clockIn))
{
for (const auto& sensor : sensorsIn)
{
@@ -57,14 +60,14 @@
(direction == numeric::Direction::increasing && increasing) ||
(direction == numeric::Direction::either && (increasing || decreasing)))
{
- startTimer(details, timestamp, value);
+ startTimer(details, value);
}
prevValue = value;
}
void NumericThreshold::startTimer(NumericThreshold::ThresholdDetail& details,
- Milliseconds timestamp, double value)
+ double value)
{
const auto& sensorName = details.sensorName;
auto& dwell = details.dwell;
@@ -72,13 +75,13 @@
if (dwellTime == Milliseconds::zero())
{
- commit(sensorName, timestamp, value);
+ commit(sensorName, value);
}
else
{
dwell = true;
timer.expires_after(dwellTime);
- timer.async_wait([this, &sensorName, &dwell, timestamp,
+ timer.async_wait([this, &sensorName, &dwell,
value](const boost::system::error_code ec) {
if (ec)
{
@@ -86,18 +89,18 @@
"Timer has been canceled");
return;
}
- commit(sensorName, timestamp, value);
+ commit(sensorName, value);
dwell = false;
});
}
}
-void NumericThreshold::commit(const std::string& sensorName,
- Milliseconds timestamp, double value)
+void NumericThreshold::commit(const std::string& sensorName, double value)
{
+ Milliseconds timestamp = clock->systemTimestamp();
for (const auto& action : actions)
{
- action->commit(sensorName, timestamp, value);
+ action->commit(triggerId, std::nullopt, sensorName, timestamp, value);
}
}