314 lines
8.5 KiB
Diff
314 lines
8.5 KiB
Diff
--- pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpIndicationHandler.cpp.obz4978 2006-01-30 11:17:54.000000000 -0500
|
|
+++ pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpIndicationHandler.cpp 2006-05-02 15:23:37.000000000 -0400
|
|
@@ -62,9 +62,54 @@
|
|
|
|
PEGASUS_USING_STD;
|
|
|
|
+#ifdef HPUX_EMANATE
|
|
+ static snmpDeliverTrap_emanate snmpTrap;
|
|
+#elif defined (PEGASUS_USE_NET_SNMP)
|
|
+ static snmpDeliverTrap_netsnmp snmpTrap;
|
|
+#else
|
|
+ static snmpDeliverTrap_stub snmpTrap;
|
|
+#endif
|
|
+
|
|
+snmpIndicationHandler::snmpIndicationHandler()
|
|
+{
|
|
+ PEG_METHOD_ENTER (TRC_IND_HANDLER,
|
|
+ "snmpIndicationHandler::snmpIndicationHandler");
|
|
+ PEG_METHOD_EXIT();
|
|
+}
|
|
+
|
|
void snmpIndicationHandler::initialize(CIMRepository* repository)
|
|
{
|
|
+ PEG_METHOD_ENTER (TRC_IND_HANDLER,
|
|
+ "snmpIndicationHandler::initialize");
|
|
+
|
|
_repository = repository;
|
|
+
|
|
+#ifdef PEGASUS_USE_NET_SNMP
|
|
+ snmpTrap.initialize();
|
|
+#endif
|
|
+
|
|
+ PEG_METHOD_EXIT();
|
|
+}
|
|
+
|
|
+void snmpIndicationHandler::terminate()
|
|
+{
|
|
+ PEG_METHOD_ENTER (TRC_IND_HANDLER,
|
|
+ "snmpIndicationHandler::terminate");
|
|
+
|
|
+#ifdef PEGASUS_USE_NET_SNMP
|
|
+ snmpTrap.terminate();
|
|
+#endif
|
|
+
|
|
+ PEG_METHOD_EXIT();
|
|
+}
|
|
+
|
|
+snmpIndicationHandler::~snmpIndicationHandler()
|
|
+{
|
|
+ PEG_METHOD_ENTER (TRC_IND_HANDLER,
|
|
+ "snmpIndicationHandler::~snmpIndicationHandler");
|
|
+
|
|
+
|
|
+ PEG_METHOD_EXIT();
|
|
}
|
|
|
|
// l10n - note: ignoring indication language
|
|
@@ -153,14 +198,6 @@
|
|
// trap destination and SNMP type are defined in handlerInstance
|
|
// and passing this instance as it is to deliverTrap() call
|
|
|
|
-#ifdef HPUX_EMANATE
|
|
- static snmpDeliverTrap_emanate emanateTrap;
|
|
-#elif defined (PEGASUS_USE_NET_SNMP)
|
|
- static snmpDeliverTrap_netsnmp emanateTrap;
|
|
-#else
|
|
- static snmpDeliverTrap_stub emanateTrap;
|
|
-#endif
|
|
-
|
|
Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost"));
|
|
Uint32 targetHostFormatPos = handler.findProperty(CIMName ("TargetHostFormat"));
|
|
Uint32 otherTargetHostFormatPos = handler.findProperty(CIMName (
|
|
@@ -263,7 +300,7 @@
|
|
handler.getProperty(engineIDPos).getValue().get(engineID);
|
|
}
|
|
|
|
- emanateTrap.deliverTrap(
|
|
+ snmpTrap.deliverTrap(
|
|
trapOid,
|
|
securityName,
|
|
targetHost,
|
|
@@ -315,6 +352,8 @@
|
|
MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.FAILED_TO_DELIVER_TRAP",
|
|
"Failed to deliver trap."));
|
|
}
|
|
+
|
|
+ PEG_METHOD_EXIT();
|
|
}
|
|
|
|
// This is the dynamic entry point into this dynamic module. The name of
|
|
--- pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpDeliverTrap_netsnmp.cpp.obz4978 2006-01-30 11:17:54.000000000 -0500
|
|
+++ pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpDeliverTrap_netsnmp.cpp 2006-05-02 15:23:37.000000000 -0400
|
|
@@ -41,6 +41,49 @@
|
|
|
|
PEGASUS_NAMESPACE_BEGIN
|
|
|
|
+void snmpDeliverTrap_netsnmp::initialize()
|
|
+{
|
|
+
|
|
+ PEG_METHOD_ENTER (TRC_IND_HANDLER,
|
|
+ "snmpDeliverTrap_netsnmp::initialize");
|
|
+
|
|
+ // Defined default MIB modules (in net-snmp-config.h) do not need to be
|
|
+ // loaded and loading them can cause some stderr;
|
|
+ // use environment variable MIBS to override the default MIB modules.
|
|
+ // If there is no MIBS environment variable, add it in.
|
|
+ char *envVar;
|
|
+ envVar = getenv("MIBS");
|
|
+
|
|
+ if (envVar == NULL)
|
|
+ {
|
|
+ putenv("MIBS=");
|
|
+ }
|
|
+
|
|
+ // Initialize the mib reader
|
|
+ netsnmp_set_mib_directory("");
|
|
+ init_mib();
|
|
+
|
|
+ // Initializes the SNMP library
|
|
+ init_snmp("snmpIndicationHandler");
|
|
+
|
|
+ // windows32 specific initialization (is a NOOP on unix)
|
|
+ SOCK_STARTUP;
|
|
+
|
|
+ PEG_METHOD_EXIT ();
|
|
+
|
|
+}
|
|
+
|
|
+void snmpDeliverTrap_netsnmp::terminate()
|
|
+{
|
|
+
|
|
+ PEG_METHOD_ENTER (TRC_IND_HANDLER,
|
|
+ "snmpDeliverTrap_netsnmp::terminate");
|
|
+
|
|
+ SOCK_CLEANUP;
|
|
+
|
|
+ PEG_METHOD_EXIT ();
|
|
+}
|
|
+
|
|
void snmpDeliverTrap_netsnmp::deliverTrap(
|
|
const String& trapOid,
|
|
const String& securityName,
|
|
@@ -59,12 +102,12 @@
|
|
"snmpDeliverTrap_netsnmp::deliverTrap");
|
|
|
|
void *sessionHandle;
|
|
- struct snmp_session snmpSession, *sessionPtr;
|
|
+ struct snmp_session *sessionPtr;
|
|
|
|
struct snmp_pdu *snmpPdu;
|
|
|
|
// Creates a SNMP session
|
|
- _createSession(targetHost, portNumber, securityName, snmpSession,
|
|
+ _createSession(targetHost, portNumber, securityName,
|
|
sessionHandle, sessionPtr);
|
|
|
|
try
|
|
@@ -138,7 +181,6 @@
|
|
const String & targetHost,
|
|
Uint32 portNumber,
|
|
const String & securityName,
|
|
- snmp_session & snmpSession,
|
|
void *&sessionHandle,
|
|
snmp_session *&sessionPtr)
|
|
{
|
|
@@ -148,34 +190,13 @@
|
|
Sint32 libErr, sysErr;
|
|
char *errStr;
|
|
String exceptionStr;
|
|
+
|
|
+ struct snmp_session snmpSession;
|
|
|
|
- // Defined default MIB modules (in net-snmp-config.h) do not need to be
|
|
- // loaded and loading them can cause some stderr;
|
|
- // use environment variable MIBS to override the default MIB modules.
|
|
- // If there is no MIBS environment variable, add it in.
|
|
-
|
|
- char *envVar;
|
|
- envVar = getenv("MIBS");
|
|
-
|
|
- if (envVar == NULL)
|
|
{
|
|
- putenv("MIBS=");
|
|
- }
|
|
-
|
|
- // Initialize the mib reader
|
|
- netsnmp_set_mib_directory("");
|
|
- init_mib();
|
|
-
|
|
- // Initializes the SNMP library
|
|
- init_snmp("snmpIndicationHandler");
|
|
-
|
|
- // Prepares a struct snmp_session that will be used for a set of
|
|
- // SNMP transactions
|
|
+ AutoMutex autoMut(_sessionInitMutex);
|
|
snmp_sess_init(&snmpSession);
|
|
|
|
- // windows32 specific initialization (is a NOOP on unix)
|
|
- SOCK_STARTUP;
|
|
-
|
|
CString targetHostCStr = targetHost.getCString();
|
|
|
|
// peername has format: targetHost:portNumber
|
|
@@ -183,7 +204,9 @@
|
|
1+32));
|
|
sprintf(snmpSession.peername, "%s:%u", (const char*)targetHostCStr,
|
|
portNumber);
|
|
+
|
|
sessionHandle = snmp_sess_open(&snmpSession);
|
|
+ }
|
|
|
|
if (sessionHandle == NULL)
|
|
{
|
|
@@ -196,8 +219,6 @@
|
|
|
|
free(errStr);
|
|
|
|
- SOCK_CLEANUP;
|
|
-
|
|
PEG_METHOD_EXIT ();
|
|
|
|
throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
|
|
@@ -276,8 +297,6 @@
|
|
|
|
snmp_sess_close(sessionHandle);
|
|
|
|
- SOCK_CLEANUP;
|
|
-
|
|
PEG_METHOD_EXIT ();
|
|
}
|
|
|
|
--- pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpIndicationHandler.h.obz4978 2006-01-30 11:17:54.000000000 -0500
|
|
+++ pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpIndicationHandler.h 2006-05-02 15:23:37.000000000 -0400
|
|
@@ -50,19 +50,13 @@
|
|
|
|
CIMRepository* _repository;
|
|
|
|
- snmpIndicationHandler()
|
|
- {
|
|
- }
|
|
-
|
|
- virtual ~snmpIndicationHandler()
|
|
- {
|
|
- }
|
|
+ snmpIndicationHandler();
|
|
+
|
|
+ virtual ~snmpIndicationHandler();
|
|
|
|
void initialize(CIMRepository* repository);
|
|
|
|
- void terminate()
|
|
- {
|
|
- }
|
|
+ void terminate();
|
|
|
|
void handleIndication(
|
|
const OperationContext& context,
|
|
@@ -71,6 +65,7 @@
|
|
CIMInstance& handler,
|
|
CIMInstance& subscription,
|
|
ContentLanguageList& contentLanguages);
|
|
+
|
|
};
|
|
|
|
PEGASUS_NAMESPACE_END
|
|
--- pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpDeliverTrap_netsnmp.h.obz4978 2006-01-30 11:17:54.000000000 -0500
|
|
+++ pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpDeliverTrap_netsnmp.h 2006-05-02 15:23:37.000000000 -0400
|
|
@@ -37,6 +37,7 @@
|
|
|
|
#include <iostream>
|
|
|
|
+#include <Pegasus/Common/IPC.h>
|
|
#include <net-snmp/net-snmp-config.h>
|
|
#include <net-snmp/net-snmp-includes.h>
|
|
#include "snmpDeliverTrap.h"
|
|
@@ -120,6 +121,10 @@
|
|
{
|
|
public:
|
|
|
|
+ void initialize();
|
|
+
|
|
+ void terminate();
|
|
+
|
|
void deliverTrap(
|
|
const String& trapOid,
|
|
const String& securityName,
|
|
@@ -135,6 +140,10 @@
|
|
|
|
private:
|
|
|
|
+ // Mutex is needed before a session is created. Sessions created
|
|
+ // using the Single API do not interact with other SNMP sessions.
|
|
+ Mutex _sessionInitMutex;
|
|
+
|
|
/**
|
|
Creates a SNMP session.
|
|
|
|
@@ -143,7 +152,6 @@
|
|
to receive a trap
|
|
@param portNumber the port number to receive a trap
|
|
@param securityName the human readable community name
|
|
- @param snmpSession the SNMP session
|
|
@param sessionHandle an opaque pointer of the SNMP session
|
|
@param sessionPtr the SNMP session pointer to its associated
|
|
struct snmp_session
|
|
@@ -153,7 +161,6 @@
|
|
void _createSession(const String & targetHost,
|
|
Uint32 portNumber,
|
|
const String & securityName,
|
|
- struct snmp_session & snmpSession,
|
|
void *&sessionHandle,
|
|
struct snmp_session *&sessionPtr);
|
|
|