version 1.6, 2002/04/17 22:46:33
|
version 1.20, 2003/10/16 21:06:11
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 BMC Software, Hewlett Packard, IBM, The Open Group, |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
// Tivoli Systems |
// The Open Group, Tivoli Systems |
// | // |
// 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: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com) | // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com) |
// | // |
// Modified By: |
// Modified By: Carol Ann Krug Graves, Hewlett-Packard Company |
|
// (carolann_graves@hp.com) |
|
// : Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com) |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
|
#include <Pegasus/Common/PegasusVersion.h> |
|
|
#include <iostream> | #include <iostream> |
#include <Pegasus/Handler/CIMHandler.h> | #include <Pegasus/Handler/CIMHandler.h> |
#include <Pegasus/Repository/CIMRepository.h> | #include <Pegasus/Repository/CIMRepository.h> |
|
|
#include "snmpDeliverTrap_stub.h" | #include "snmpDeliverTrap_stub.h" |
#endif | #endif |
| |
|
// l10n |
|
#include <Pegasus/Common/MessageLoader.h> |
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
//#define DDD(X) X |
|
#define DDD(X) // X |
|
|
|
DDD(static const char* _SNMPINDICATIONHANDLER = "snmpIndicationHandler::";) |
|
|
|
void snmpIndicationHandler::initialize(CIMRepository* repository) | void snmpIndicationHandler::initialize(CIMRepository* repository) |
{ | { |
_repository = repository; | _repository = repository; |
DDD(cout << _SNMPINDICATIONHANDLER << "initialize()" << endl;) |
|
} | } |
| |
void snmpIndicationHandler::handleIndication(CIMInstance& handler, |
// l10n - note: ignoring indication language |
CIMInstance& indication, String nameSpace) |
void snmpIndicationHandler::handleIndication( |
|
const OperationContext& context, |
|
CIMInstance& handler, |
|
CIMInstance& indication, String nameSpace, |
|
ContentLanguages & contentLanguages) |
{ | { |
Array<String> propOIDs; | Array<String> propOIDs; |
Array<String> propTYPEs; | Array<String> propTYPEs; |
|
|
String mapstr1; | String mapstr1; |
String mapstr2; | String mapstr2; |
| |
|
PEG_METHOD_ENTER (TRC_IND_HANDLER, |
|
"snmpIndicationHandler::handleIndication"); |
|
|
|
try |
|
{ |
CIMClass indicationClass = _repository->getClass( | CIMClass indicationClass = _repository->getClass( |
nameSpace, indication.getClassName(), false); |
nameSpace, indication.getClassName(), false, true, |
|
false, CIMPropertyList()); |
|
|
|
Uint32 propertyCount = indication.getPropertyCount(); |
| |
for (Uint32 i=0; i<indication.getPropertyCount();i++) |
for (Uint32 i=0; i < propertyCount; i++) |
{ | { |
prop = indication.getProperty(i); | prop = indication.getProperty(i); |
| |
if (prop) |
if (!prop.isUninitialized()) |
{ | { |
String propName = prop.getName(); |
CIMName propName = prop.getName(); |
Uint32 propPos = indicationClass.findProperty(propName); | Uint32 propPos = indicationClass.findProperty(propName); |
if (propPos != PEG_NOT_FOUND) | if (propPos != PEG_NOT_FOUND) |
{ | { |
CIMProperty trapProp = indicationClass.getProperty(propPos); | CIMProperty trapProp = indicationClass.getProperty(propPos); |
| |
if (trapProp.existsQualifier("MappingStrings")) |
qualifierPos = trapProp.findQualifier(CIMName ("MappingStrings")); |
|
if (qualifierPos != PEG_NOT_FOUND) |
{ | { |
qualifierPos = trapProp.findQualifier("MappingStrings"); |
|
trapQualifier = trapProp.getQualifier(qualifierPos); | trapQualifier = trapProp.getQualifier(qualifierPos); |
| |
mapstr1.clear(); | mapstr1.clear(); |
|
|
snmpDeliverTrap_stub emanateTrap; | snmpDeliverTrap_stub emanateTrap; |
#endif | #endif |
| |
if ((handler.findProperty("TrapDestination") != PEG_NOT_FOUND) && |
Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost")); |
(handler.findProperty("SNMPVersion") != PEG_NOT_FOUND) && |
Uint32 targetHostFormatPos = handler.findProperty(CIMName ("TargetHostFormat")); |
(indicationClass.findQualifier("MappingStrings") != PEG_NOT_FOUND)) |
Uint32 otherTargetHostFormatPos = handler.findProperty(CIMName ( |
|
"OtherTargetHostFormat")); |
|
Uint32 portNumberPos = handler.findProperty(CIMName ("PortNumber")); |
|
Uint32 snmpVersionPos = handler.findProperty(CIMName ("SNMPVersion")); |
|
Uint32 securityNamePos = handler.findProperty(CIMName ("SNMPSecurityName")); |
|
Uint32 engineIDPos = handler.findProperty(CIMName ("SNMPEngineID")); |
|
|
|
if ((targetHostPos != PEG_NOT_FOUND) && |
|
(targetHostFormatPos != PEG_NOT_FOUND) && |
|
(snmpVersionPos != PEG_NOT_FOUND) && |
|
(indicationClass.findQualifier(CIMName ("MappingStrings")) != |
|
PEG_NOT_FOUND)) |
{ | { |
String community, trapType, destination; // from handler instance |
// properties from the handler instance |
String trapOid; // from indication Class |
String targetHost; |
|
String otherTargetHostFormat = String(); |
|
String securityName = String(); |
|
String engineID = String(); |
|
Uint16 targetHostFormat = 0; |
|
Uint16 snmpVersion = 0; |
|
Uint32 portNumber; |
| |
trapOid = indicationClass.getQualifier( |
String trapOid; |
indicationClass.findQualifier("MappingStrings")).getValue().toString(); |
// |
|
// Get snmpTrapOid from context |
|
// |
|
try |
|
{ |
|
SnmpTrapOidContainer trapContainer = context.get |
|
(SnmpTrapOidContainer::NAME); |
| |
trapOid = trapOid.subString(trapOid.find("OID.IETF | SNMP.")+16); |
trapOid = trapContainer.getSnmpTrapOid(); |
|
} |
|
catch (Exception& e) |
|
{ |
|
// get trapOid from indication Class |
| |
community = handler.getProperty( |
Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings")); |
handler.findProperty("SNMPCommunityName")).getValue().toString(); |
if (pos != PEG_NOT_FOUND) |
|
{ |
|
trapOid = indicationClass.getQualifier(pos).getValue().toString(); |
| |
destination = handler.getProperty( |
trapOid = trapOid.subString(11, PEG_NOT_FOUND); |
handler.findProperty("TrapDestination")).getValue().toString(); |
|
| |
trapType = handler.getProperty( |
if ((String::compare(trapOid, "SNMP.", 5)) == 0) |
handler.findProperty("SNMPVersion")).getValue().toString(); |
{ |
|
trapOid = trapOid.subString(5, (trapOid.size()-6)); |
|
} |
|
else |
|
{ |
|
PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, |
|
"Invalid MappingStrings Value " + trapOid); |
|
PEG_METHOD_EXIT(); |
|
// l10n |
|
// throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Invalid MappingStrings Value"); |
|
throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, |
|
MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_MS_VALUE", |
|
"Invalid MappingStrings Value")); |
|
} |
|
} |
|
else |
|
{ |
|
PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, |
|
"Qualifier MappingStrings can not be found."); |
|
PEG_METHOD_EXIT(); |
|
//L10N_ TODO DONE |
|
//throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Qualifier MappingStrings can not be found"); |
|
MessageLoaderParms parms("Handler.snmpIndicationHandler.snmpIndicationHandler.QUALIFIER_MAPPINGS_NOT_FOUND", |
|
"Qualifier MappingStrings can not be found"); |
|
throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms); |
|
} |
|
} |
|
|
|
handler.getProperty(targetHostPos).getValue().get(targetHost); |
|
handler.getProperty(targetHostFormatPos).getValue().get(targetHostFormat); |
|
if (otherTargetHostFormatPos != PEG_NOT_FOUND) |
|
{ |
|
handler.getProperty(otherTargetHostFormatPos).getValue().get |
|
(otherTargetHostFormat); |
|
} |
|
if (portNumberPos != PEG_NOT_FOUND) |
|
{ |
|
handler.getProperty(portNumberPos).getValue().get(portNumber); |
|
} |
|
else |
|
{ |
|
// default port |
|
portNumber = SNMP_TRAP_DEFAULT_PORT; |
|
} |
|
|
|
handler.getProperty(snmpVersionPos).getValue().get(snmpVersion); |
|
if (securityNamePos != PEG_NOT_FOUND) |
|
{ |
|
handler.getProperty(securityNamePos).getValue().get(securityName); |
|
} |
|
if (engineIDPos != PEG_NOT_FOUND) |
|
{ |
|
handler.getProperty(engineIDPos).getValue().get(engineID); |
|
} |
| |
emanateTrap.deliverTrap( | emanateTrap.deliverTrap( |
trapOid, | trapOid, |
community, |
securityName, |
destination, |
targetHost, |
trapType, |
targetHostFormat, |
|
otherTargetHostFormat, |
|
portNumber, |
|
snmpVersion, |
|
engineID, |
propOIDs, | propOIDs, |
propTYPEs, | propTYPEs, |
propVALUEs); | propVALUEs); |
} | } |
else | else |
cout << "Invalid Indication" << endl; |
{ |
|
PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, |
|
"Invalid IndicationHandlerSNMPMapper instance."); |
|
PEG_METHOD_EXIT(); |
|
// l10n |
|
|
|
// throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, |
|
// "Invalid IndicationHandlerSNMPMapper instance"); |
|
|
|
throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, |
|
MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_SNMP_INSTANCE", |
|
"Invalid IndicationHandlerSNMPMapper instance")); |
|
} |
|
} |
|
catch (CIMException & c) |
|
{ |
|
PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage()); |
|
PEG_METHOD_EXIT(); |
|
|
|
throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage()); |
|
} |
|
catch (Exception& e) |
|
{ |
|
PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage()); |
|
PEG_METHOD_EXIT(); |
|
|
|
throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage()); |
|
} |
|
catch (...) |
|
{ |
|
PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, |
|
"Failed to deliver trap."); |
|
PEG_METHOD_EXIT(); |
|
|
|
throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, |
|
MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.FAILED_TO_DELIVER_TRAP", |
|
"Failed to deliver trap.")); |
|
} |
} | } |
| |
// This is the dynamic entry point into this dynamic module. The name of | // This is the dynamic entry point into this dynamic module. The name of |
// this handler is "snmpIndicationHandler" which is appened to "PegasusCreateHandler_" |
// this handler is "snmpIndicationHandler" which is appended to "PegasusCreateHandler_" |
// to form a symbol name. This function is called by the HandlerTable | // to form a symbol name. This function is called by the HandlerTable |
// to load this handler. | // to load this handler. |
| |
extern "C" PEGASUS_EXPORT CIMHandler* | extern "C" PEGASUS_EXPORT CIMHandler* |
PegasusCreateHandler_snmpIndicationHandler() { | PegasusCreateHandler_snmpIndicationHandler() { |
DDD(cout << "Called PegasusCreateHandler_snmpIndicationHandler" << endl;) |
|
return new snmpIndicationHandler; | return new snmpIndicationHandler; |
} | } |
| |