version 1.2, 2005/12/08 00:06:34
|
version 1.8, 2006/08/11 19:47:07
|
|
|
//%2005//////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development | // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. | // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. | // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; | // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
// EMC Corporation; VERITAS Software Corporation; The Open Group. | // EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// | // |
//============================================================================== | //============================================================================== |
// | // |
// Author: Yi Zhou, Hewlett-Packard Company (Yi.Zhou@hp.com) |
|
// |
|
// Modified By: |
|
// |
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <Pegasus/Common/Packer.h> | #include <Pegasus/Common/Packer.h> |
|
|
| |
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) |
{ | { |
exceptionStr = _MSG_SESSION_OPEN_FAILED; | exceptionStr = _MSG_SESSION_OPEN_FAILED; |
| |
// Get library, system errno | // Get library, system errno |
snmp_sess_error(&snmpSession, &libErr, &sysErr, &errStr); |
snmp_error(&snmpSession, &libErr, &sysErr, &errStr); |
| |
exceptionStr.append(errStr); | exceptionStr.append(errStr); |
| |
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, |
|
|
communityName = securityName; | communityName = securityName; |
} | } |
| |
if (snmpSession.peername) |
|
{ |
|
free(snmpSession.peername); | free(snmpSession.peername); |
} |
|
| |
if (sessionPtr->community) |
|
{ |
|
free(sessionPtr->community); | free(sessionPtr->community); |
} |
|
| |
CString communityNameCStr = communityName.getCString(); | CString communityNameCStr = communityName.getCString(); |
size_t communityNameLen = strlen(communityNameCStr); | size_t communityNameLen = strlen(communityNameCStr); |
|
|
| |
snmp_sess_close(sessionHandle); | snmp_sess_close(sessionHandle); |
| |
SOCK_CLEANUP; |
|
|
|
PEG_METHOD_EXIT (); | PEG_METHOD_EXIT (); |
} | } |
| |
|
|
throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED, | throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED, |
MessageLoaderParms(_MSG_VERSION_NOT_SUPPORTED_KEY, | MessageLoaderParms(_MSG_VERSION_NOT_SUPPORTED_KEY, |
_MSG_VERSION_NOT_SUPPORTED)); | _MSG_VERSION_NOT_SUPPORTED)); |
break; |
|
} | } |
} | } |
| |
|
|
strcat(numericEntOid, oidSubIdentifiers[i]); | strcat(numericEntOid, oidSubIdentifiers[i]); |
} | } |
| |
if (oidSubIdentifiers[oidSubIdentifiers.size()-2] != "0") |
if (strcmp(oidSubIdentifiers[oidSubIdentifiers.size()-2], "0") != 0) |
{ | { |
strcat(numericEntOid, "."); | strcat(numericEntOid, "."); |
strcat(numericEntOid, | strcat(numericEntOid, |