Adjust LogToRedfish trigger action to DMTF standard
This patch modifies messages sent to Redfish event log to be compliant
with message registry schema [1].
Tested:
On platform, with corresponding bmcweb patch [2]. Verified that messages
appearing in Redfish event log are compliant with schema. UTs passed.
[1] https://redfish.dmtf.org/registries/Telemetry.1.0.0.json
[2] https://gerrit.openbmc.org/c/openbmc/bmcweb/+/72315
Change-Id: Ide3d5a13e5be077806df6398c5f51da41f7a7922
Signed-off-by: Michal Orzel <michalx.orzel@intel.com>
diff --git a/src/trigger_actions.cpp b/src/trigger_actions.cpp
index ef4a50b..9466b77 100644
--- a/src/trigger_actions.cpp
+++ b/src/trigger_actions.cpp
@@ -64,19 +64,40 @@
phosphor::logging::log<phosphor::logging::level::INFO>(msg.c_str());
}
-const char* LogToRedfishEventLog::getRedfishMessageId() const
+const char* LogToRedfishEventLog::getRedfishMessageId(const double value) const
{
- switch (type)
+ std::string direction(getDirection(value, threshold));
+
+ if (direction == "decreasing")
{
- case ::numeric::Type::upperCritical:
- return redfish_message_ids::TriggerNumericCritical;
- case ::numeric::Type::lowerCritical:
- return redfish_message_ids::TriggerNumericCritical;
- case ::numeric::Type::upperWarning:
- return redfish_message_ids::TriggerNumericWarning;
- case ::numeric::Type::lowerWarning:
- return redfish_message_ids::TriggerNumericWarning;
+ switch (type)
+ {
+ case ::numeric::Type::upperCritical:
+ return redfish_message_ids::TriggerNumericBelowUpperCritical;
+ case ::numeric::Type::lowerCritical:
+ return redfish_message_ids::TriggerNumericBelowLowerCritical;
+ case ::numeric::Type::upperWarning:
+ return redfish_message_ids::TriggerNumericReadingNormal;
+ case ::numeric::Type::lowerWarning:
+ return redfish_message_ids::TriggerNumericBelowLowerWarning;
+ }
}
+
+ if (direction == "increasing")
+ {
+ switch (type)
+ {
+ case ::numeric::Type::upperCritical:
+ return redfish_message_ids::TriggerNumericAboveUpperCritical;
+ case ::numeric::Type::lowerCritical:
+ return redfish_message_ids::TriggerNumericAboveLowerCritical;
+ case ::numeric::Type::upperWarning:
+ return redfish_message_ids::TriggerNumericAboveUpperWarning;
+ case ::numeric::Type::lowerWarning:
+ return redfish_message_ids::TriggerNumericReadingNormal;
+ }
+ }
+
throw std::runtime_error("Invalid type");
}
@@ -87,18 +108,26 @@
const TriggerValue triggerValue)
{
double value = std::get<double>(triggerValue);
- std::string thresholdName = ::numeric::typeToString(type);
- auto direction = getDirection(value, threshold);
- auto timestampStr = timestampToString(timestamp);
+ auto messageId = getRedfishMessageId(value);
- phosphor::logging::log<phosphor::logging::level::INFO>(
- "Logging numeric trigger action to Redfish Event Log.",
- phosphor::logging::entry("REDFISH_MESSAGE_ID=%s",
- getRedfishMessageId()),
- phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%s,%s,%f,%s,%s",
- thresholdName.c_str(), triggerId.c_str(),
- sensorName.c_str(), value, direction,
- timestampStr.c_str()));
+ if (messageId == redfish_message_ids::TriggerNumericReadingNormal)
+ {
+ phosphor::logging::log<phosphor::logging::level::INFO>(
+ "Logging numeric trigger action to Redfish Event Log.",
+ phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", messageId),
+ phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%f,%s",
+ sensorName.c_str(), value,
+ triggerId.c_str()));
+ }
+ else
+ {
+ phosphor::logging::log<phosphor::logging::level::INFO>(
+ "Logging numeric trigger action to Redfish Event Log.",
+ phosphor::logging::entry("REDFISH_MESSAGE_ID=%s", messageId),
+ phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%f,%f,%s",
+ sensorName.c_str(), value, threshold,
+ triggerId.c_str()));
+ }
}
void fillActions(
@@ -157,20 +186,6 @@
phosphor::logging::log<phosphor::logging::level::INFO>(msg.c_str());
}
-const char* LogToRedfishEventLog::getRedfishMessageId() const
-{
- switch (severity)
- {
- case ::discrete::Severity::ok:
- return redfish_message_ids::TriggerDiscreteOK;
- case ::discrete::Severity::warning:
- return redfish_message_ids::TriggerDiscreteWarning;
- case ::discrete::Severity::critical:
- return redfish_message_ids::TriggerDiscreteCritical;
- }
- throw std::runtime_error("Invalid severity");
-}
-
void LogToRedfishEventLog::commit(const std::string& triggerId,
const ThresholdName thresholdNameIn,
const std::string& sensorName,
@@ -178,16 +193,15 @@
const TriggerValue triggerValue)
{
auto value = std::get<std::string>(triggerValue);
- auto timestampStr = timestampToString(timestamp);
phosphor::logging::log<phosphor::logging::level::INFO>(
"Logging discrete trigger action to Redfish Event Log.",
- phosphor::logging::entry("REDFISH_MESSAGE_ID=%s",
- getRedfishMessageId()),
- phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%s,%s,%s,%s",
- thresholdNameIn->get().c_str(),
- triggerId.c_str(), sensorName.c_str(),
- value.c_str(), timestampStr.c_str()));
+ phosphor::logging::entry(
+ "REDFISH_MESSAGE_ID=%s",
+ redfish_message_ids::TriggerDiscreteConditionMet),
+ phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%s,%s",
+ sensorName.c_str(), value.c_str(),
+ triggerId.c_str()));
}
void fillActions(
@@ -210,7 +224,7 @@
case TriggerAction::LogToRedfishEventLog:
{
actionsIf.emplace_back(
- std::make_unique<LogToRedfishEventLog>(severity));
+ std::make_unique<LogToRedfishEventLog>());
break;
}
case TriggerAction::UpdateReport:
@@ -247,16 +261,15 @@
const TriggerValue triggerValue)
{
auto value = triggerValueToString(triggerValue);
- auto timestampStr = timestampToString(timestamp);
phosphor::logging::log<phosphor::logging::level::INFO>(
"Logging onChange discrete trigger action to Redfish Event Log.",
- phosphor::logging::entry("REDFISH_MESSAGE_ID=%s",
- redfish_message_ids::TriggerDiscreteOK),
- phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%s,%s,%s,%s",
- "OnChange", triggerId.c_str(),
+ phosphor::logging::entry(
+ "REDFISH_MESSAGE_ID=%s",
+ redfish_message_ids::TriggerDiscreteConditionMet),
+ phosphor::logging::entry("REDFISH_MESSAGE_ARGS=%s,%s,%s",
sensorName.c_str(), value.c_str(),
- timestampStr.c_str()));
+ triggerId.c_str()));
}
void fillActions(
diff --git a/src/trigger_actions.hpp b/src/trigger_actions.hpp
index 14f6294..3e2c33c 100644
--- a/src/trigger_actions.hpp
+++ b/src/trigger_actions.hpp
@@ -10,15 +10,22 @@
namespace redfish_message_ids
{
-constexpr const char* TriggerNumericWarning =
- "OpenBMC.0.1.TriggerNumericWarning";
-constexpr const char* TriggerNumericCritical =
- "OpenBMC.0.1.TriggerNumericCritical";
-constexpr const char* TriggerDiscreteOK = "OpenBMC.0.1.TriggerDiscreteOK";
-constexpr const char* TriggerDiscreteWarning =
- "OpenBMC.0.1.TriggerDiscreteWarning";
-constexpr const char* TriggerDiscreteCritical =
- "OpenBMC.0.1.TriggerDiscreteCritical";
+constexpr const char* TriggerDiscreteConditionMet =
+ "Telemetry.1.0.TriggerDiscreteConditionMet";
+constexpr const char* TriggerNumericAboveLowerCritical =
+ "Telemetry.1.0.TriggerNumericAboveLowerCritical";
+constexpr const char* TriggerNumericAboveUpperCritical =
+ "Telemetry.1.0.TriggerNumericAboveUpperCritical";
+constexpr const char* TriggerNumericAboveUpperWarning =
+ "Telemetry.1.0.TriggerNumericAboveUpperWarning";
+constexpr const char* TriggerNumericBelowLowerCritical =
+ "Telemetry.1.0.TriggerNumericBelowLowerCritical";
+constexpr const char* TriggerNumericBelowLowerWarning =
+ "Telemetry.1.0.TriggerNumericBelowLowerWarning";
+constexpr const char* TriggerNumericBelowUpperCritical =
+ "Telemetry.1.0.TriggerNumericBelowUpperCritical";
+constexpr const char* TriggerNumericReadingNormal =
+ "Telemetry.1.0.TriggerNumericReadingNormal";
} // namespace redfish_message_ids
namespace numeric
@@ -53,7 +60,7 @@
const ::numeric::Type type;
const double threshold;
- const char* getRedfishMessageId() const;
+ const char* getRedfishMessageId(const double value) const;
};
void fillActions(
@@ -81,18 +88,11 @@
class LogToRedfishEventLog : public interfaces::TriggerAction
{
public:
- explicit LogToRedfishEventLog(::discrete::Severity severity) :
- severity(severity)
- {}
+ explicit LogToRedfishEventLog() {}
void commit(const std::string& triggerId, const ThresholdName thresholdName,
const std::string& sensorName, const Milliseconds timestamp,
const TriggerValue value) override;
-
- private:
- const ::discrete::Severity severity;
-
- const char* getRedfishMessageId() const;
};
void fillActions(
diff --git a/tests/src/test_trigger_actions.cpp b/tests/src/test_trigger_actions.cpp
index 8711378..8e8274f 100644
--- a/tests/src/test_trigger_actions.cpp
+++ b/tests/src/test_trigger_actions.cpp
@@ -14,22 +14,35 @@
{
namespace numeric
{
-using LogParam = std::tuple<::numeric::Type, double, double>;
+using LogParam = std::tuple<::numeric::Type, double, TriggerValue>;
static auto getCorrectParams()
{
- return Values(std::make_tuple(::numeric::Type::upperCritical, 91.1, 90),
- std::make_tuple(::numeric::Type::lowerCritical, 91.2, 90),
- std::make_tuple(::numeric::Type::upperWarning, 88.5, 90),
- std::make_tuple(::numeric::Type::lowerWarning, 88.6, 90));
+ return Values(
+ std::make_tuple(::numeric::Type::upperCritical, 91.1,
+ TriggerValue(90.0)),
+ std::make_tuple(::numeric::Type::upperCritical, 90, TriggerValue(91.1)),
+ std::make_tuple(::numeric::Type::lowerCritical, 91.2,
+ TriggerValue(90.0)),
+ std::make_tuple(::numeric::Type::lowerCritical, 90, TriggerValue(91.2)),
+ std::make_tuple(::numeric::Type::upperWarning, 88.5,
+ TriggerValue(90.0)),
+ std::make_tuple(::numeric::Type::upperWarning, 90, TriggerValue(88.5)),
+ std::make_tuple(::numeric::Type::lowerWarning, 88.6,
+ TriggerValue(90.0)),
+ std::make_tuple(::numeric::Type::lowerWarning, 90, TriggerValue(88.6)));
}
static auto getIncorrectParams()
{
- return Values(
- std::make_tuple(::numeric::Type::upperCritical, 90.0, 90),
- std::make_tuple(static_cast<::numeric::Type>(-1), 88.0, 90),
- std::make_tuple(static_cast<::numeric::Type>(123), 123.0, 90));
+ return Values(std::make_tuple(::numeric::Type::upperCritical, 90.0,
+ TriggerValue(90.0)),
+ std::make_tuple(static_cast<::numeric::Type>(-1), 88.0,
+ TriggerValue(90.0)),
+ std::make_tuple(static_cast<::numeric::Type>(123), 123.0,
+ TriggerValue(90.0)),
+ std::make_tuple(::numeric::Type::upperCritical, 90.0,
+ TriggerValue("numeric")));
}
template <typename ActionType>
@@ -50,7 +63,7 @@
}
std::unique_ptr<ActionType> sut;
- double commmitValue;
+ TriggerValue commmitValue;
};
class TestLogToJournalNumeric : public TestActionNumeric<LogToJournal>
@@ -125,14 +138,15 @@
std::make_tuple(::discrete::Severity::ok, TriggerValue(0.1)));
}
-template <typename ActionType>
-class TestActionDiscrete : public Test, public WithParamInterface<LogParam>
+class TestLogToJournalDiscrete :
+ public Test,
+ public WithParamInterface<LogParam>
{
public:
void SetUp() override
{
auto [severity, value] = GetParam();
- sut = std::make_unique<ActionType>(severity);
+ sut = std::make_unique<LogToJournal>(severity);
commitValue = value;
}
@@ -144,12 +158,9 @@
}
TriggerValue commitValue;
- std::unique_ptr<ActionType> sut;
+ std::unique_ptr<LogToJournal> sut;
};
-class TestLogToJournalDiscrete : public TestActionDiscrete<LogToJournal>
-{};
-
INSTANTIATE_TEST_SUITE_P(LogToJournalDiscreteParams, TestLogToJournalDiscrete,
getCorrectParams());
@@ -169,28 +180,32 @@
EXPECT_ANY_THROW(commit());
}
-class TestLogToRedfishEventLogDiscrete :
- public TestActionDiscrete<LogToRedfishEventLog>
-{};
-
-INSTANTIATE_TEST_SUITE_P(LogToRedfishEventLogDiscreteParams,
- TestLogToRedfishEventLogDiscrete, getCorrectParams());
-
-TEST_P(TestLogToRedfishEventLogDiscrete, commitExpectNoThrow)
+class TestLogToRedfishEventLogDiscrete : public Test
{
- EXPECT_NO_THROW(commit());
+ public:
+ void SetUp()
+ {
+ sut = std::make_unique<LogToRedfishEventLog>();
+ }
+
+ void commit(TriggerValue value)
+ {
+ std::string thresholdName = "MyThreshold";
+ sut->commit("MyTrigger", std::cref(thresholdName), "MySensor",
+ Milliseconds{100'000}, value);
+ }
+
+ std::unique_ptr<LogToRedfishEventLog> sut;
+};
+
+TEST_F(TestLogToRedfishEventLogDiscrete, commitDiscreteValueExpectNoThrow)
+{
+ EXPECT_NO_THROW(commit("DiscreteVal"));
}
-class TestLogToRedfishEventLogDiscreteThrow :
- public TestLogToRedfishEventLogDiscrete
-{};
-
-INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishEventLogDiscreteThrow,
- getIncorrectParams());
-
-TEST_P(TestLogToRedfishEventLogDiscreteThrow, commitExpectToThrow)
+TEST_F(TestLogToRedfishEventLogDiscrete, commitNumericValueExpectToThrow)
{
- EXPECT_ANY_THROW(commit());
+ EXPECT_ANY_THROW(commit(42.0));
}
namespace onChange