diff options
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/callback.hpp | 9 | ||||
-rw-r--r-- | src/data_types.hpp | 8 | ||||
-rw-r--r-- | src/snmp_trap.cpp | 15 | ||||
-rw-r--r-- | src/snmp_trap.hpp | 84 |
5 files changed, 118 insertions, 1 deletions
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 <typename T> using InterfacesAdded = std::map<std::string, std::map<std::string, sdbusplus::message::variant<T>>>; +using Value = + sdbusplus::message::variant<bool, uint8_t, int16_t, uint16_t, int32_t, + uint32_t, int64_t, uint64_t, std::string>; + +/** @brief ObjectManager.InterfacesAdded signal signature alias. */ +using Interface = std::string; +using Property = std::string; +using PathInterfacesAdded = std::map<Interface, std::map<Property, Value>>; /** @brief ObjectMapper.GetObject response signature alias. */ using GetObject = std::map<MapperPath, std::vector<std::string>>; 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 <typename T> 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 |