summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarri Devender Rao <devenrao@in.ibm.com>2018-04-12 01:11:48 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-06-05 02:10:49 +0000
commit70aafbb58d98c6ca5a049433db87493784ec587a (patch)
tree917eab2118ec28d990de0b80714481fe8c5a0989
parentee4c6ebfd9e1697501b6fa0225d684867796a637 (diff)
downloadphosphor-dbus-monitor-70aafbb58d98c6ca5a049433db87493784ec587a.zip
phosphor-dbus-monitor-70aafbb58d98c6ca5a049433db87493784ec587a.tar.gz
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 <devenrao@in.ibm.com>
-rw-r--r--src/Makefile.am3
-rw-r--r--src/callback.hpp9
-rw-r--r--src/data_types.hpp8
-rw-r--r--src/snmp_trap.cpp15
-rw-r--r--src/snmp_trap.hpp84
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
OpenPOWER on IntegriCloud