(file) Return to snmpIndicationHandler.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / snmpIndicationHandler

Diff for /pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpIndicationHandler.cpp between version 1.1.2.3 and 1.20

version 1.1.2.3, 2001/11/15 20:15:24 version 1.20, 2003/10/16 21:06:11
Line 1 
Line 1 
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
 // //
 // 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
Line 23 
Line 23 
 // //
 // 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 <iostream>  
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
   #include <Pegasus/Common/PegasusVersion.h>
   
   #include <iostream>
 #include <Pegasus/Handler/CIMHandler.h> #include <Pegasus/Handler/CIMHandler.h>
 #include <Pegasus/Repository/CIMRepository.h> #include <Pegasus/Repository/CIMRepository.h>
  
Line 40 
Line 44 
 #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& handlerInstance,  // l10n - note: ignoring indication language
     CIMInstance& indicationInstance,  void snmpIndicationHandler::handleIndication(
     String nameSpace)      const OperationContext& context,
       CIMInstance& handler,
       CIMInstance& indication, String nameSpace,
       ContentLanguages & contentLanguages)
 { {
     String enterprise, trapOid, destination;  
     Array<String> propOIDs;     Array<String> propOIDs;
     Array<String> propTYPEs;     Array<String> propTYPEs;
     Array<String> propVALUEs;     Array<String> propVALUEs;
  
     CIMProperty prop;     CIMProperty prop;
       CIMQualifier trapQualifier;
  
     CIMClass indicationClass = _repository->getClass(      Uint32 qualifierPos;
         nameSpace,  
         indicationInstance.getClassName(),  
         false);  
  
     Uint32 propPos = indicationClass.findProperty("enterprise");      String propValue;
     if (propPos != PEG_NOT_FOUND)  
     {  
         CIMProperty trapProp = indicationClass.getProperty(propPos);  
  
         Uint32 qualifierPos = trapProp.findQualifier("MappingStrings");      String mapstr1;
         if (qualifierPos != PEG_NOT_FOUND)      String mapstr2;
         {  
             CIMQualifier trapQualifier = trapProp.getQualifier(qualifierPos);      PEG_METHOD_ENTER (TRC_IND_HANDLER,
             // ATTN: Catch TypeMismatch exception on the next line          "snmpIndicationHandler::handleIndication");
             trapQualifier.getValue().get(enterprise);  
  
             for (int i=0; i<indicationInstance.getPropertyCount();i++)      try
             {             {
                 char* property_oid = NULL;          CIMClass indicationClass = _repository->getClass(
                 char* property_value = NULL;              nameSpace, indication.getClassName(), false, true,
                 char* property_datatype = NULL;              false, CIMPropertyList());
  
                 prop = indicationInstance.getProperty(i);          Uint32 propertyCount = indication.getPropertyCount();
  
                 if (prop != NULL)          for (Uint32 i=0; i < propertyCount; i++)
                 {                 {
                     String propName = prop.getName();              prop = indication.getProperty(i);
                     Uint32 propPos = indicationClass.findProperty(propName);  
                     CIMProperty trapProp = indicationClass.getProperty(propPos);  
  
                     if (trapProp.existsQualifier("MappingStrings"))              if (!prop.isUninitialized())
                     {                     {
                         if (propName == "trapOid")                  CIMName propName = prop.getName();
                   Uint32 propPos = indicationClass.findProperty(propName);
                   if (propPos != PEG_NOT_FOUND)
                         {                         {
                             // ATTN: Catch TypeMismatch exception on the next line                      CIMProperty trapProp = indicationClass.getProperty(propPos);
                             prop.getValue().get(trapOid);  
                         }                      qualifierPos = trapProp.findQualifier(CIMName ("MappingStrings"));
                         else                      if (qualifierPos != PEG_NOT_FOUND)
                         {                         {
                             Uint32 qualifierPos = trapProp.findQualifier("MappingStrings");                          trapQualifier = trapProp.getQualifier(qualifierPos);
                             CIMQualifier trapQualifier = trapProp.getQualifier(qualifierPos);  
  
                             String mapstr1;                          mapstr1.clear();
                             // ATTN: Catch TypeMismatch exception on the next line                          mapstr1 = trapQualifier.getValue().toString();
                             trapQualifier.getValue().get(mapstr1);  
                             String mapstr2 = "";  
  
                             if ((mapstr1.find("OID") != PEG_NOT_FOUND) &&                          if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
                                 (mapstr1.find("SNMP") != PEG_NOT_FOUND))                              (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
                             {                             {
                                 if (mapstr1.subString(0, 4) == "OID.")                              if (mapstr1.subString(0, 8) == "OID.IETF")
                                 {                                 {
                                     mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);                                     mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
                                     if (mapstr1.find("|") != PEG_NOT_FOUND)                                     if (mapstr1.find("|") != PEG_NOT_FOUND)
                                     {                                     {
                                         mapstr2 = mapstr1.subString(0, mapstr1.find("|"));                                      mapstr2.clear();
                                       mapstr2 = mapstr1.subString(0,
                                           mapstr1.find("DataType.IETF")-1);
                                         propOIDs.append(mapstr2);                                         propOIDs.append(mapstr2);
                                         String propValue;  
                                         // ATTN: Catch TypeMismatch exception on the next line                                      propValue.clear();
                                         prop.getValue().get(propValue);                                      propValue = prop.getValue().toString();
                                         propVALUEs.append(propValue);                                         propVALUEs.append(propValue);
                                         propTYPEs.append(mapstr1.subString(mapstr1.find("|")+1));  
                                     }                                      mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
                                       mapstr2 = mapstr2.subString(0, mapstr2.size()-1);
                                       propTYPEs.append(mapstr2);
                                 }                                 }
                             }                             }
                         }                         }
Line 149 
Line 146 
         snmpDeliverTrap_stub emanateTrap;         snmpDeliverTrap_stub emanateTrap;
 #endif #endif
  
         if ((handlerInstance.findProperty("Destination") != PEG_NOT_FOUND) &&          Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost"));
             (handlerInstance.findProperty("trapType") != PEG_NOT_FOUND))          Uint32 targetHostFormatPos = handler.findProperty(CIMName ("TargetHostFormat"));
           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))
           {
               // properties from the handler instance
               String targetHost;
               String otherTargetHostFormat = String();
               String securityName = String();
               String engineID = String();
               Uint16 targetHostFormat = 0;
               Uint16 snmpVersion = 0;
               Uint32 portNumber;
   
               String trapOid;
               //
               //  Get snmpTrapOid from context
               //
               try
               {
                   SnmpTrapOidContainer trapContainer = context.get
                       (SnmpTrapOidContainer::NAME);
   
                   trapOid = trapContainer.getSnmpTrapOid();
               }
               catch (Exception& e)
               {
                   // get trapOid from indication Class
   
                   Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings"));
                   if (pos != PEG_NOT_FOUND)
                   {
                       trapOid = indicationClass.getQualifier(pos).getValue().toString();
   
                       trapOid = trapOid.subString(11, PEG_NOT_FOUND);
   
                       if ((String::compare(trapOid, "SNMP.", 5)) == 0)
                       {
                           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)
         {         {
             String destination;                  handler.getProperty(engineIDPos).getValue().get(engineID);
             String trapType;              }
             // ATTN: Add error checking  
             // ATTN: Catch TypeMismatch exception on the next line              emanateTrap.deliverTrap(
             handlerInstance.getProperty(                  trapOid,
                 handlerInstance.findProperty("Destination"))                  securityName,
                 .getValue().get(destination);                  targetHost,
             // ATTN: Add error checking                  targetHostFormat,
             // ATTN: Catch TypeMismatch exception on the next line                  otherTargetHostFormat,
             handlerInstance.getProperty(                  portNumber,
                 handlerInstance.findProperty("trapType"))                  snmpVersion,
                 .getValue().get(trapType);                  engineID,
   
             emanateTrap.deliverTrap(trapOid,  
                 enterprise,  
                 destination,  
                 trapType,  
                 propOIDs,                 propOIDs,
                 propTYPEs,                 propTYPEs,
                 propVALUEs);                 propVALUEs);
         }         }
     }  
     else     else
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,          {
             "Indication is without enterprise OID");              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;
 } }
  


Legend:
Removed from v.1.1.2.3  
changed lines
  Added in v.1.20

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2