Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:sschapiro:openstack:upstream
clustermon
bz561413-13-Convert-traps-to-C.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File bz561413-13-Convert-traps-to-C.patch of Package clustermon
From c69cd24c4368e5c865005b788babf0aa770d4d48 Mon Sep 17 00:00:00 2001 From: Lon Hohberger <lhh@redhat.com> Date: Fri, 14 May 2010 11:52:49 -0400 Subject: [PATCH 13/16] modclusterd: Convert traps to C++ Signed-off-by: Lon Hohberger <lhh@redhat.com> --- .../modules/cluster/clumon/src/snmp-agent/Makefile | 1 + .../modules/cluster/clumon/src/snmp-agent/Trap.cpp | 74 ++++++++++++++++++++ ricci/modules/cluster/clumon/src/snmp-agent/Trap.h | 19 +++++ .../clumon/src/snmp-agent/clusterMonitorSnmp.cpp | 36 ++-------- .../cluster/clumon/src/snmp-agent/rhc_oid.cpp | 39 ++++++----- 5 files changed, 122 insertions(+), 47 deletions(-) create mode 100644 ricci/modules/cluster/clumon/src/snmp-agent/Trap.cpp create mode 100644 ricci/modules/cluster/clumon/src/snmp-agent/Trap.h diff --git a/ricci/modules/cluster/clumon/src/snmp-agent/Makefile b/ricci/modules/cluster/clumon/src/snmp-agent/Makefile index 727a641..f67a5c7 100644 --- a/ricci/modules/cluster/clumon/src/snmp-agent/Makefile +++ b/ricci/modules/cluster/clumon/src/snmp-agent/Makefile @@ -40,6 +40,7 @@ OBJECTS = clusterMonitorSnmp.o \ servicesMIB_access.o \ servicesMIB_checkfns.o \ servicesMIB_checkfns_local.o \ + Trap.o \ rhc_oid.o TARGET = libClusterMonitorSnmp.so diff --git a/ricci/modules/cluster/clumon/src/snmp-agent/Trap.cpp b/ricci/modules/cluster/clumon/src/snmp-agent/Trap.cpp new file mode 100644 index 0000000..b368997 --- /dev/null +++ b/ricci/modules/cluster/clumon/src/snmp-agent/Trap.cpp @@ -0,0 +1,74 @@ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> +#include <String.h> +#include "Trap.h" +#include "rhc_oid.h" +#include <string.h> + +using namespace std; + +Trap::Trap(oid trap_oid[], size_t trap_len) +{ + my_vars = NULL; + + Add(snmp_trap, snmp_trap_len, trap_oid, trap_len); +} + +Trap::~Trap() +{ + snmp_free_varbind(my_vars); + my_vars = NULL; +} + +int +Trap::Add(oid o[], size_t o_len, int data) +{ + if (snmp_varlist_add_variable(&my_vars, o, o_len, + ASN_INTEGER, + (u_char *)&data, + sizeof(data)) == NULL); + return 1; + return 0; +} + +int +Trap::Add(oid o[], size_t o_len, oid data[], size_t data_len) +{ + if (snmp_varlist_add_variable(&my_vars, o, o_len, + ASN_OBJECT_ID, + (u_char *)data, + data_len * sizeof(oid)) == NULL) + return 1; + return 0; +} + +int +Trap::Add(oid o[], size_t o_len, String& data) +{ + if (snmp_varlist_add_variable(&my_vars, o, o_len, + ASN_OCTET_STR, + (u_char *)(data.c_str()), + data.size()) == NULL) + return 1; + return 0; +} + +int +Trap::Add(oid o[], size_t o_len, const char *data) +{ + if (snmp_varlist_add_variable(&my_vars, o, o_len, + ASN_OCTET_STR, + (u_char *)(data), + strlen(data)) == NULL) + return 1; + return 0; +} + +void +Trap::Send() +{ + send_v2trap(my_vars); +} + + diff --git a/ricci/modules/cluster/clumon/src/snmp-agent/Trap.h b/ricci/modules/cluster/clumon/src/snmp-agent/Trap.h new file mode 100644 index 0000000..cbfee72 --- /dev/null +++ b/ricci/modules/cluster/clumon/src/snmp-agent/Trap.h @@ -0,0 +1,19 @@ +#include <net-snmp/net-snmp-config.h> +#include <net-snmp/net-snmp-includes.h> +#include <net-snmp/agent/net-snmp-agent-includes.h> +#include "rhc_oid.h" + +class Trap +{ + public: + Trap(oid trap_oid[], size_t trap_len); + ~Trap(); + + int Add(oid o[], size_t o_len, String& data); + int Add(oid o[], size_t o_len, const char *data); + int Add(oid o[], size_t o_len, oid data[], size_t data_len); + int Add(oid o[], size_t o_len, int data); + void Send(); + private: + netsnmp_variable_list *my_vars; +}; diff --git a/ricci/modules/cluster/clumon/src/snmp-agent/clusterMonitorSnmp.cpp b/ricci/modules/cluster/clumon/src/snmp-agent/clusterMonitorSnmp.cpp index 36fabb3..3afe972 100644 --- a/ricci/modules/cluster/clumon/src/snmp-agent/clusterMonitorSnmp.cpp +++ b/ricci/modules/cluster/clumon/src/snmp-agent/clusterMonitorSnmp.cpp @@ -28,40 +28,13 @@ #include <syslog.h> #include "Cluster.h" #include "rhc_oid.h" +#include "Trap.h" using namespace ClusterMonitoring; ClusterMonitoring::ClusterMonitor monitor; -static void -init_trap(netsnmp_variable_list **vars, oid notif[], size_t notif_len) -{ - snmp_varlist_add_variable(vars, snmp_trap, snmp_trap_len, - ASN_OBJECT_ID, - (u_char *)notif, notif_len * sizeof(oid)); -} - - -void -config_update_trap(unsigned int new_version) -{ - netsnmp_variable_list *vars = NULL; - - init_trap(&vars, rhcConfigVersion_trap, rhcConfigVersion_len); - - snmp_varlist_add_variable(&vars, - rhcClusterConfigVersion_oid, - rhcClusterConfigVersion_len, - ASN_INTEGER, - (u_char *)&new_version, - sizeof(new_version)); - - send_v2trap(vars); - snmp_free_varbind(vars); -} - - void check_cluster_state(unsigned int clientreg, void *clientarg) { @@ -73,7 +46,12 @@ check_cluster_state(unsigned int clientreg, void *clientarg) if (old_status->config_version() != cluster->config_version()) { // Send configuration version update trap - config_update_trap(cluster->config_version()); + Trap trap(rhcConfigVersion_trap, rhcConfigVersion_len); + + trap.Add(rhcClusterConfigVersion_oid, + rhcClusterConfigVersion_len, + cluster->config_version()); + trap.Send(); } } diff --git a/ricci/modules/cluster/clumon/src/snmp-agent/rhc_oid.cpp b/ricci/modules/cluster/clumon/src/snmp-agent/rhc_oid.cpp index 6c1dcc7..e8fb375 100644 --- a/ricci/modules/cluster/clumon/src/snmp-agent/rhc_oid.cpp +++ b/ricci/modules/cluster/clumon/src/snmp-agent/rhc_oid.cpp @@ -2,6 +2,9 @@ #include <net-snmp/net-snmp-includes.h> #include <net-snmp/agent/net-snmp-agent-includes.h> +/* NOTE: rhc_oid.cpp is used for automatic generation of rhc_oid.h; + * utilize the same format when editing rhc_oid.cpp */ + /* SNMP OIDs we need to know about */ oid snmp_trap[] = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 }; size_t snmp_trap_len = OID_LENGTH(snmp_trap); @@ -10,8 +13,8 @@ size_t snmp_trap_len = OID_LENGTH(snmp_trap); oid rhcConfigVersion_trap[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 0, 1 }; size_t rhcConfigVersion_len = OID_LENGTH(rhcConfigVersion_trap); -oid rhcQuorumState_trap[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 0, 2 }; -size_t rhcQuorumState_len = OID_LENGTH(rhcQuorumState_trap); +oid rhcQuorumState_trap[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 0, 2 }; +size_t rhcQuorumState_len = OID_LENGTH(rhcQuorumState_trap); oid rhcNodeState_trap[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 0, 3 }; size_t rhcNodeState_len = OID_LENGTH(rhcNodeState_trap); @@ -21,10 +24,10 @@ size_t rhcServiceState_len = OID_LENGTH(rhcServiceState_trap); /* Objects */ oid rhcMIBVersion_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 1, 1 }; -size_t rhcMIBVersion_len = OID_LENGTH(rhcMIBVersion_oid); +size_t rhcMIBVersion_len = OID_LENGTH(rhcMIBVersion_oid); -oid rhcClusterName_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 1 }; -size_t rhcClusterName_len = OID_LENGTH(rhcClusterName_oid); +oid rhcClusterName_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 1 }; +size_t rhcClusterName_len = OID_LENGTH(rhcClusterName_oid); oid rhcClusterStatusCode_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 2 }; size_t rhcClusterStatusCode_len = OID_LENGTH(rhcClusterStatusCode_oid); @@ -32,10 +35,10 @@ size_t rhcClusterStatusCode_len = OID_LENGTH(rhcClusterStatusCode_oid); oid rhcClusterStatusDesc_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 3 }; size_t rhcClusterStatusDesc_len = OID_LENGTH(rhcClusterStatusDesc_oid); -oid rhcClusterVotesNeededForQuorum_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 4 }; -size_t rhcClusterVotesNeededForQuorum_len = OID_LENGTH(rhcClusterVotesNeededForQuorum_oid); +oid rhcClusterVotesNeededForQuorum_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 4 }; +size_t rhcClusterVotesNeededForQuorum_len = OID_LENGTH(rhcClusterVotesNeededForQuorum_oid); -oid rhcClusterVotes_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 5 }; +oid rhcClusterVotes_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 5 }; size_t rhcClusterVotes_len = OID_LENGTH(rhcClusterVotes_oid); oid rhcClusterQuorate_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 6 }; @@ -47,7 +50,7 @@ size_t rhcClusterNodesNum_len = OID_LENGTH(rhcClusterNodesNum_oid); oid rhcClusterNodesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 8 }; size_t rhcClusterNodesNames_len = OID_LENGTH(rhcClusterNodesNames_oid); -oid rhcClusterAvailNodesNum_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 9 }; +oid rhcClusterAvailNodesNum_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 9 }; size_t rhcClusterAvailNodesNum_len = OID_LENGTH(rhcClusterAvailNodesNum_oid); oid rhcClusterAvailNodesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 10 }; @@ -60,35 +63,35 @@ oid rhcClusterUnavailNodesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 12 }; size_t rhcClusterUnavailNodesNames_len = OID_LENGTH(rhcClusterUnavailNodesNames_oid); oid rhcClusterServicesNum_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 13 }; -size_t rhcClusterServicesNum_len = OID_LENGTH(rhcClusterServicesNum_oid); +size_t rhcClusterServicesNum_len = OID_LENGTH(rhcClusterServicesNum_oid); -oid rhcClusterServicesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 14 }; +oid rhcClusterServicesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 14 }; size_t rhcClusterServicesNames_len = OID_LENGTH(rhcClusterServicesNames_oid); oid rhcClusterRunningServicesNum_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 15 }; size_t rhcClusterRunningServicesNum_len = OID_LENGTH(rhcClusterRunningServicesNum_oid); -oid rhcClusterRunningServicesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 16 }; -size_t rhcClusterRunningServicesNames_len = OID_LENGTH(rhcClusterRunningServicesNames_oid); +oid rhcClusterRunningServicesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 16 }; +size_t rhcClusterRunningServicesNames_len = OID_LENGTH(rhcClusterRunningServicesNames_oid); oid rhcClusterStoppedServicesNum_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 17 }; size_t rhcClusterStoppedServicesNum_len = OID_LENGTH(rhcClusterStoppedServicesNum_oid); -oid rhcClusterStoppedServicesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 18 }; -size_t rhcClusterStoppedServicesNames_len = OID_LENGTH(rhcClusterStoppedServicesNames_oid); +oid rhcClusterStoppedServicesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 18 }; +size_t rhcClusterStoppedServicesNames_len = OID_LENGTH(rhcClusterStoppedServicesNames_oid); oid rhcClusterFailedServicesNum_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 19 }; size_t rhcClusterFailedServicesNum_len = OID_LENGTH(rhcClusterFailedServicesNum_oid); oid rhcClusterFailedServicesNames_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 20 }; -size_t rhcClusterFailedServicesNames_len = OID_LENGTH(rhcClusterFailedServicesNames_oid); +size_t rhcClusterFailedServicesNames_len = OID_LENGTH(rhcClusterFailedServicesNames_oid); -oid rhcClusterConfigVersion_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 21 }; +oid rhcClusterConfigVersion_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 2, 21 }; size_t rhcClusterConfigVersion_len = OID_LENGTH(rhcClusterConfigVersion_oid); /* Tables */ oid rhcNodesTable_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 3, 1 }; -size_t rhcNodesTable_len = OID_LENGTH(rhcNodesTable_oid); +size_t rhcNodesTable_len = OID_LENGTH(rhcNodesTable_oid); oid rhcServicesTable_oid[] = { 1, 3, 6, 1, 4, 1, 2312, 8, 3, 2 }; size_t rhcServicesTable_len = OID_LENGTH(rhcServicesTable_oid); -- 1.6.2.5
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor