summaryrefslogtreecommitdiff
path: root/redfish-core/include/utils
diff options
context:
space:
mode:
authorSzymon Dompke <szymon.dompke@intel.com>2022-03-04 15:11:38 +0300
committerEd Tanous <ed@tanous.net>2023-05-30 20:45:55 +0300
commitdd1c4a9ca36e742fc4796a152cd72b850738a648 (patch)
treecf3801d15197f07da2393992b8a62c6b288cb7a4 /redfish-core/include/utils
parent5db7dfd6278258fd069ae29881920e365a533547 (diff)
downloadbmcweb-dd1c4a9ca36e742fc4796a152cd72b850738a648.tar.xz
Add support for POST on TriggersCollection
Added POST method on /redfish/v1/TelemetryService/Triggers uri, which creates new trigger in telemetry service, by using dbus call AddTrigger. By DMTF, most of the properties are not required, and as such are treated as optional. Some values can be deduced from others (like 'MetricType', depending on 'DiscreteTriggers' or 'NumericThresholds'). All properties provided in POST body by user will be verified against each other, and errors will be raised. Few examples of such situations: - 'MetricType' is set to 'Discrete' but 'NumericThresholds' was passed. - 'MetricType' is set to 'Numeric' but "DiscreteTriggers' or 'DiscreteTriggerCondition' were passed - 'DiscreteTriggerCondition' is set to 'Specified' but 'DiscreteTriggers' is an empty array or was not passed. - 'DiscreteTriggerCondition' is set to 'Changed' but 'DiscreteTriggers' is passed and is not an empty array. Example 1 – Trigger with discrete values: ``` { "Id": "TestTrigger", "MetricType": "Discrete", "TriggerActions": [ "RedfishEvent" ], "DiscreteTriggerCondition": "Specified", "DiscreteTriggers": [ { "Value": "55.88", "DwellTime": "PT0.001S", "Severity": "Warning" }, { "Name": "My discrete trigger", "Value": "55.88", "DwellTime": "PT0.001S", "Severity": "OK" }, { "Value": "55.88", "DwellTime": "PT0.001S", "Severity": "Critical" } ], "MetricProperties": [ "/redfish/v1/Chassis/AC_Baseboard/Thermal#/Fans/0/Reading" ], "Links": { "MetricReportDefinitions": [] } } Example 2 – trigger with numeric threshold: { "Id": "TestTrigger2", "Name": "My Numeric Trigger", "MetricType": "Numeric", "TriggerActions": [ "RedfishEvent", "RedfishMetricReport" ], "NumericThresholds": { "UpperCritical": { "Reading": 50, "Activation": "Increasing", "DwellTime": "PT0.001S" }, "UpperWarning": { "Reading": 48.1, "Activation": "Increasing", "DwellTime": "PT0.004S" } }, "MetricProperties": [ "/redfish/v1/Chassis/AC_Baseboard/Thermal#/Fans/0/Reading", "/redfish/v1/Chassis/AC_Baseboard/Thermal#/Fans/17/Reading" ], "Links": { "MetricReportDefinitions": [ "/redfish/v1/TelemetryService/MetricReportDefinitions/PowerMetrics", "/redfish/v1/TelemetryService/MetricReportDefinitions/PowerMetricStats", "/redfish/v1/TelemetryService/MetricReportDefinitions/PlatformPowerUsage" ] } } ``` Tested: - Triggers were successfully created with above example message bodies. This can be checked by calling: 'busctl tree xyz.openbmc_project.Telemetry'. - Expected errors were returned for messages with incorrect or mutually exclusive properties and incorrect values. - Redfish service validator is passing. Signed-off-by: Szymon Dompke <szymon.dompke@intel.com> Change-Id: Ief8c76de8aa660ae0d2dbe4610c26a28186a290a
Diffstat (limited to 'redfish-core/include/utils')
-rw-r--r--redfish-core/include/utils/telemetry_utils.hpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/redfish-core/include/utils/telemetry_utils.hpp b/redfish-core/include/utils/telemetry_utils.hpp
index fc045f6742..58ab1c9d28 100644
--- a/redfish-core/include/utils/telemetry_utils.hpp
+++ b/redfish-core/include/utils/telemetry_utils.hpp
@@ -34,6 +34,25 @@ inline std::string getDbusTriggerPath(const std::string& id)
return {triggersPath / id};
}
+inline std::optional<std::string>
+ getTriggerIdFromDbusPath(const std::string& dbusPath)
+{
+ sdbusplus::message::object_path converted(dbusPath);
+
+ if (converted.parent_path() !=
+ "/xyz/openbmc_project/Telemetry/Triggers/TelemetryService")
+ {
+ return std::nullopt;
+ }
+
+ const std::string& id = converted.filename();
+ if (id.empty())
+ {
+ return std::nullopt;
+ }
+ return id;
+}
+
struct IncorrectMetricUri
{
std::string uri;