version 1.3, 2006/01/30 16:17:54
|
version 1.3.2.1, 2006/04/19 22:33:44
|
|
|
| |
PEGASUS_NAMESPACE_BEGIN | 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( | void snmpDeliverTrap_netsnmp::deliverTrap( |
const String& trapOid, | const String& trapOid, |
const String& securityName, | const String& securityName, |
|
|
"snmpDeliverTrap_netsnmp::deliverTrap"); | "snmpDeliverTrap_netsnmp::deliverTrap"); |
| |
void *sessionHandle; | void *sessionHandle; |
struct snmp_session snmpSession, *sessionPtr; |
struct snmp_session *sessionPtr; |
| |
struct snmp_pdu *snmpPdu; | struct snmp_pdu *snmpPdu; |
| |
// Creates a SNMP session | // Creates a SNMP session |
_createSession(targetHost, portNumber, securityName, snmpSession, |
_createSession(targetHost, portNumber, securityName, |
sessionHandle, sessionPtr); | sessionHandle, sessionPtr); |
| |
try | try |
|
|
const String & targetHost, | const String & targetHost, |
Uint32 portNumber, | Uint32 portNumber, |
const String & securityName, | const String & securityName, |
snmp_session & snmpSession, |
|
void *&sessionHandle, | void *&sessionHandle, |
snmp_session *&sessionPtr) | snmp_session *&sessionPtr) |
{ | { |
|
|
char *errStr; | char *errStr; |
String exceptionStr; | String exceptionStr; |
| |
// Defined default MIB modules (in net-snmp-config.h) do not need to be |
struct snmp_session snmpSession; |
// 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="); |
AutoMutex autoMut(_sessionInitMutex); |
} |
|
|
|
// 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 |
|
snmp_sess_init(&snmpSession); | snmp_sess_init(&snmpSession); |
| |
// windows32 specific initialization (is a NOOP on unix) |
|
SOCK_STARTUP; |
|
|
|
CString targetHostCStr = targetHost.getCString(); | CString targetHostCStr = targetHost.getCString(); |
| |
// peername has format: targetHost:portNumber | // peername has format: targetHost:portNumber |
|
|
1+32)); | 1+32)); |
sprintf(snmpSession.peername, "%s:%u", (const char*)targetHostCStr, | sprintf(snmpSession.peername, "%s:%u", (const char*)targetHostCStr, |
portNumber); | portNumber); |
|
|
sessionHandle = snmp_sess_open(&snmpSession); | sessionHandle = snmp_sess_open(&snmpSession); |
|
} |
| |
if (sessionHandle == NULL) | if (sessionHandle == NULL) |
{ | { |
|
|
| |
free(errStr); | free(errStr); |
| |
SOCK_CLEANUP; |
|
|
|
PEG_METHOD_EXIT (); | PEG_METHOD_EXIT (); |
| |
throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, | throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, |
|
|
| |
snmp_sess_close(sessionHandle); | snmp_sess_close(sessionHandle); |
| |
SOCK_CLEANUP; |
|
|
|
PEG_METHOD_EXIT (); | PEG_METHOD_EXIT (); |
} | } |
| |