Fix trigger type for OnChange triggers
Triggers with no threshold parameters should be treated as ones that
activate on change of monitored metric values', with `Discrete` property
value set to true. Otherwise they will be wrongly treated as numeric
triggers on Redfish side. This patch corrects this behavior.
Tested:
1. Created simple discrete trigger: `TestTriggerDiscreteOnChange`, with
`DiscreteTriggerCondition` set to `Changed`.
2. busctl introspect xyz.openbmc_project.Telemetry
/xyz/openbmc_project/Telemetry/Triggers/TelemetryService/
TestTriggerDiscreteOnChange
3. Verified that `Discrete` property is true
All unit tests have passed.
Change-Id: I06762c94b38a9da42a64c9a014d3f6dd47577176
Signed-off-by: Michal Orzel <michalx.orzel@intel.com>
diff --git a/src/trigger.cpp b/src/trigger.cpp
index f534dbd..f71e515 100644
--- a/src/trigger.cpp
+++ b/src/trigger.cpp
@@ -186,8 +186,8 @@
});
dbusIface.register_property_r(
- "Discrete", isDiscreate(), sdbusplus::vtable::property_::const_,
- [this](const auto& x) { return isDiscreate(); });
+ "Discrete", isDiscrete(), sdbusplus::vtable::property_::const_,
+ [this](const auto& x) { return isDiscrete(); });
dbusIface.register_property_rw(
"Name", name, sdbusplus::vtable::property_::emits_change,
@@ -278,9 +278,13 @@
});
}
-bool Trigger::isDiscreate() const
+bool Trigger::isDiscrete() const
{
const auto labeledThresholds = getLabeledThresholds();
+ if (labeledThresholds.empty())
+ {
+ return true;
+ }
return utils::isFirstElementOfType<std::monostate>(labeledThresholds) ||
utils::isFirstElementOfType<discrete::LabeledThresholdParam>(
diff --git a/src/trigger.hpp b/src/trigger.hpp
index e636334..c0b2845 100644
--- a/src/trigger.hpp
+++ b/src/trigger.hpp
@@ -48,7 +48,7 @@
private:
std::vector<LabeledSensorInfo> getLabeledSensorInfo() const;
std::vector<LabeledThresholdParam> getLabeledThresholds() const;
- bool isDiscreate() const;
+ bool isDiscrete() const;
const TriggerId id;
const sdbusplus::message::object_path path;