From 70aafbb58d98c6ca5a049433db87493784ec587a Mon Sep 17 00:00:00 2001 From: Marri Devender Rao Date: Thu, 12 Apr 2018 01:11:48 -0500 Subject: Add SNMP event callback for error notification Added callback support for SNMP events. Parse the callback message and raise SNMP trap Clients specify the object paths to watch and callbacks to invoke in the config yaml. Change-Id: I105652f65e4e1c5354c934c88e4d59866540f71c Signed-off-by: Marri Devender Rao --- src/Makefile.am | 3 +- src/callback.hpp | 9 ++++++ src/data_types.hpp | 8 ++++++ src/snmp_trap.cpp | 15 ++++++++++ src/snmp_trap.hpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 src/snmp_trap.cpp create mode 100644 src/snmp_trap.hpp (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index e5827e6..23c6009 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,8 @@ phosphor_dbus_monitor_SOURCES = \ propertywatch.cpp \ resolve_errors.cpp \ event_manager.cpp \ - event_serialize.cpp + event_serialize.cpp \ + snmp_trap.cpp phosphor_dbus_monitor_LDADD = \ $(SDBUSPLUS_LIBS) \ diff --git a/src/callback.hpp b/src/callback.hpp index 26cd2a1..e1e2325 100644 --- a/src/callback.hpp +++ b/src/callback.hpp @@ -33,6 +33,15 @@ class Callback * */ virtual void operator()(Context ctx) = 0; + + /** @brief Run the callback. + * @param[in] ctx - caller context + * Context could be Startup or Signal + * Startup: Callback is called as part of process startup. + * Signal: Callback is called as part of watch condition has been met. + * @param[in] msg - The sdbusplus signal message + */ + virtual void operator()(Context ctx, sdbusplus::message::message& msg){}; }; /** @class Conditional diff --git a/src/data_types.hpp b/src/data_types.hpp index 6be6431..cf0d69e 100644 --- a/src/data_types.hpp +++ b/src/data_types.hpp @@ -61,6 +61,14 @@ template using InterfacesAdded = std::map>>; +using Value = + sdbusplus::message::variant; + +/** @brief ObjectManager.InterfacesAdded signal signature alias. */ +using Interface = std::string; +using Property = std::string; +using PathInterfacesAdded = std::map>; /** @brief ObjectMapper.GetObject response signature alias. */ using GetObject = std::map>; diff --git a/src/snmp_trap.cpp b/src/snmp_trap.cpp new file mode 100644 index 0000000..06e8b18 --- /dev/null +++ b/src/snmp_trap.cpp @@ -0,0 +1,15 @@ +#include "snmp_trap.hpp" +namespace phosphor +{ +namespace dbus +{ +namespace monitoring +{ +void ErrorTrap::trap(sdbusplus::message::message& msg) const +{ + // TODO openbmc/openbmc#3059 + // TODO: Send trap to SNMP to be added after phoshpor-snmp is merged +} +} // namespace monitoring +} // namespace dbus +} // namespace phosphor diff --git a/src/snmp_trap.hpp b/src/snmp_trap.hpp new file mode 100644 index 0000000..2f93189 --- /dev/null +++ b/src/snmp_trap.hpp @@ -0,0 +1,84 @@ +#pragma once +#include "callback.hpp" + +namespace phosphor +{ +namespace dbus +{ +namespace monitoring +{ +/** @class Trap + * @brief Raises SNMP trap + */ +class Trap +{ + public: + Trap() = default; + Trap(const Trap&) = delete; + Trap(Trap&&) = default; + Trap& operator=(const Trap&) = delete; + Trap& operator=(Trap&&) = default; + virtual ~Trap() = default; + /** @brief Raise SNMP trap by parsing the sdbus message. + * @param[in] msg - sdbus message. + */ + virtual void trap(sdbusplus::message::message& msg) const = 0; +}; + +/** @class ErrorTrap + * @brief Sends SNMP trap for the elog error + */ +class ErrorTrap : public Trap +{ + public: + ErrorTrap() = default; + ErrorTrap(const ErrorTrap&) = delete; + ErrorTrap(ErrorTrap&&) = default; + ErrorTrap& operator=(const ErrorTrap&) = delete; + ErrorTrap& operator=(ErrorTrap&&) = default; + ~ErrorTrap() = default; + + /** @brief Raise SNMP trap by parsing the sdbus message. + * @param[in] msg - sdbus message. + */ + void trap(sdbusplus::message::message& msg) const override; +}; + +/** @class SNMPTrap + * @brief SNMP trap callback implementation. + */ +template class SNMPTrap : public Callback +{ + public: + SNMPTrap(const SNMPTrap&) = delete; + SNMPTrap(SNMPTrap&&) = default; + SNMPTrap& operator=(const SNMPTrap&) = delete; + SNMPTrap& operator=(SNMPTrap&&) = default; + virtual ~SNMPTrap() = default; + SNMPTrap() : Callback() + { + } + + /** @brief Callback interface implementation. + * @param[in] ctc - context. + */ + void operator()(Context ctx) + { + } + + /** @brief Callback interface implementation. + * @param[in] ctc - context. + * @param[in] msg - sdbus message. + */ + void operator()(Context ctx, sdbusplus::message::message& msg) + { + event.trap(msg); + } + + private: + T event; +}; + +} // namespace monitoring +} // namespace dbus +} // namespace phosphor -- cgit v1.2.1