Modify Trigger dbus api
'AddTrigger' method is now using array of strings for actions instead
of boolean flags. The action names are following:
- 'UpdateReport' (same as old flag)
- 'LogToLogService' (old 'LogToJournal' flag)
- 'RedfishEvent' (old 'LogToRedfish' flag)
Additionally, isDiscrete flag was removed from 'AddTrigger' call, as
this value can be extracted depending on threshold.
As a result new 'AddTrigger" signature is: "sasa{os}asv"
Example call parameters:
- TestTrigger 1 UpdateReport 0 0 "a(stsd)" 1 LowerWarning 1000
Either 42.7'
- TestTrigger 2 UpdateReport RedfishEvent 0 0 "a(ssts)" 1 userId_1
Warning 10 15.2'
'Trigger' properties were also modified. Instead of action bool
properties (same as mentioned above), new property was introduced
'TriggerActions' - which has same values as those used in 'AddTrigger'
method. This also affects persistence: store/load functionality was
modified accordingly.
As a side change - isDiscrete is no longer stored, as this can be easily
recreated in the runtime.
Tested:
- Trigger was successfully created using dbus.
- busctl introspect was called on test trigger and properties are
modified and working as intended.
- persistency mechanic is working propetly.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: Icd64d4032fd6d446d9b6ad248e28e9031af1fed7
diff --git a/src/trigger_factory.cpp b/src/trigger_factory.cpp
index bdfc163..98cfefe 100644
--- a/src/trigger_factory.cpp
+++ b/src/trigger_factory.cpp
@@ -21,8 +21,7 @@
{}
std::unique_ptr<interfaces::Trigger> TriggerFactory::make(
- const std::string& name, bool isDiscrete, bool logToJournal,
- bool logToRedfish, bool updateReport,
+ const std::string& name, const std::vector<std::string>& triggerActionsIn,
const std::vector<std::string>& reportNames,
interfaces::TriggerManager& triggerManager,
interfaces::JsonStorage& triggerStorage,
@@ -30,9 +29,15 @@
const std::vector<LabeledSensorInfo>& labeledSensorsInfo) const
{
const auto& [sensors, sensorNames] = getSensors(labeledSensorsInfo);
+ std::vector<TriggerAction> triggerActions;
+ std::transform(triggerActionsIn.begin(), triggerActionsIn.end(),
+ std::back_inserter(triggerActions),
+ [](auto& triggerActionStr) {
+ return stringToTriggerAction(triggerActionStr);
+ });
std::vector<std::shared_ptr<interfaces::Threshold>> thresholds;
- if (isDiscrete)
+ if (isTriggerThresholdDiscrete(labeledThresholdParams))
{
const auto& labeledDiscreteThresholdParams =
std::get<std::vector<discrete::LabeledThresholdParam>>(
@@ -50,21 +55,8 @@
std::string thresholdValue =
labeledThresholdParam.at_label<ts::ThresholdValue>();
- if (logToJournal)
- {
- actions.emplace_back(
- std::make_unique<action::discrete::LogToJournal>(severity));
- }
- if (logToRedfish)
- {
- actions.emplace_back(
- std::make_unique<action::discrete::LogToRedfish>(severity));
- }
- if (updateReport)
- {
- actions.emplace_back(std::make_unique<action::UpdateReport>(
- reportManager, reportNames));
- }
+ action::discrete::fillActions(actions, triggerActions, severity,
+ reportManager, reportNames);
thresholds.emplace_back(std::make_shared<DiscreteThreshold>(
bus->get_io_context(), sensors, sensorNames, std::move(actions),
@@ -74,23 +66,8 @@
if (labeledDiscreteThresholdParams.empty())
{
std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
- if (logToJournal)
- {
- actions.emplace_back(
- std::make_unique<
- action::discrete::onChange::LogToJournal>());
- }
- if (logToRedfish)
- {
- actions.emplace_back(
- std::make_unique<
- action::discrete::onChange::LogToRedfish>());
- }
- if (updateReport)
- {
- actions.emplace_back(std::make_unique<action::UpdateReport>(
- reportManager, reportNames));
- }
+ action::discrete::onChange::fillActions(actions, triggerActions,
+ reportManager, reportNames);
thresholds.emplace_back(std::make_shared<OnChangeThreshold>(
sensors, sensorNames, std::move(actions)));
@@ -112,25 +89,9 @@
auto thresholdValue =
double{labeledThresholdParam.at_label<ts::ThresholdValue>()};
- if (logToJournal)
- {
- actions.emplace_back(
- std::make_unique<action::numeric::LogToJournal>(
- type, thresholdValue));
- }
-
- if (logToRedfish)
- {
- actions.emplace_back(
- std::make_unique<action::numeric::LogToRedfish>(
- type, thresholdValue));
- }
-
- if (updateReport)
- {
- actions.emplace_back(std::make_unique<action::UpdateReport>(
- reportManager, reportNames));
- }
+ action::numeric::fillActions(actions, triggerActions, type,
+ thresholdValue, reportManager,
+ reportNames);
thresholds.emplace_back(std::make_shared<NumericThreshold>(
bus->get_io_context(), sensors, sensorNames, std::move(actions),
@@ -139,10 +100,9 @@
}
return std::make_unique<Trigger>(
- bus->get_io_context(), objServer, name, isDiscrete, logToJournal,
- logToRedfish, updateReport, reportNames, labeledSensorsInfo,
- labeledThresholdParams, std::move(thresholds), triggerManager,
- triggerStorage);
+ bus->get_io_context(), objServer, name, triggerActionsIn, reportNames,
+ labeledSensorsInfo, labeledThresholdParams, std::move(thresholds),
+ triggerManager, triggerStorage);
}
std::pair<Sensors, std::vector<std::string>> TriggerFactory::getSensors(