(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.1 and 1.33

version 1.1.2.1, 2001/10/12 17:33:08 version 1.33, 2006/08/15 17:24:21
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001 BMC Software, Hewlett Packard, IBM, The Open Group,  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Tivoli Systems  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
   // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // 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
Line 21 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)  
 //  
 // Modified By:  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #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>
   #include <Pegasus/Common/Tracer.h>
  
 #include "snmpIndicationHandler.h" #include "snmpIndicationHandler.h"
  
 #ifdef HPUX_EMANATE #ifdef HPUX_EMANATE
 #include "snmpDeliverTrap_emanate.h" #include "snmpDeliverTrap_emanate.h"
   #elif defined (PEGASUS_USE_NET_SNMP)
   #include "snmpDeliverTrap_netsnmp.h"
 #else #else
 #include "snmpDeliverTrap_stub.h" #include "snmpDeliverTrap_stub.h"
 #endif #endif
  
 PEGASUS_NAMESPACE_BEGIN  // l10n
   #include <Pegasus/Common/MessageLoader.h>
  
 PEGASUS_USING_STD; PEGASUS_USING_STD;
  
 //#define DDD(X) X  PEGASUS_NAMESPACE_BEGIN
 #define DDD(X) // X  
  
 DDD(static const char* _SNMPINDICATIONHANDLER = "snmpIndicationHandler::";)  snmpIndicationHandler::snmpIndicationHandler()
   {
       PEG_METHOD_ENTER (TRC_IND_HANDLER,
           "snmpIndicationHandler::snmpIndicationHandler");
   
   #ifdef HPUX_EMANATE
       _snmpTrapSender = new snmpDeliverTrap_emanate();
   #elif defined (PEGASUS_USE_NET_SNMP)
       _snmpTrapSender = new snmpDeliverTrap_netsnmp();
   #else
       _snmpTrapSender = new snmpDeliverTrap_stub();
   #endif
   
       PEG_METHOD_EXIT();
   }
  
 void snmpIndicationHandler::initialize(CIMRepository* repository) void snmpIndicationHandler::initialize(CIMRepository* repository)
 { {
       PEG_METHOD_ENTER (TRC_IND_HANDLER,
           "snmpIndicationHandler::initialize");
   
     _repository = repository;     _repository = repository;
     DDD(cout << _SNMPINDICATIONHANDLER << "initialize()" << endl;)  
       _snmpTrapSender->initialize();
   
       PEG_METHOD_EXIT();
 } }
  
 void snmpIndicationHandler::handleIndication(CIMInstance& handlerInstance,  void snmpIndicationHandler::terminate()
     CIMInstance& indicationInstance,  
     String nameSpace)  
 { {
     String enterprise, trapOid, destination, trapType;      PEG_METHOD_ENTER (TRC_IND_HANDLER,
           "snmpIndicationHandler::terminate");
   
       _snmpTrapSender->terminate();
   
       PEG_METHOD_EXIT();
   }
  
   snmpIndicationHandler::~snmpIndicationHandler()
   {
       PEG_METHOD_ENTER (TRC_IND_HANDLER,
           "snmpIndicationHandler::~snmpIndicationHandler");
   
       delete _snmpTrapSender;
   
       PEG_METHOD_EXIT();
   }
   
   // l10n - note: ignoring indication language
   void snmpIndicationHandler::handleIndication(
       const OperationContext& context,
       const String nameSpace,
       CIMInstance& indication,
       CIMInstance& handler,
       CIMInstance& subscription,
       ContentLanguageList & contentLanguages)
   {
     Array<String> propOIDs;     Array<String> propOIDs;
     Array<String> propTYPEs;     Array<String> propTYPEs;
     Array<String> propVALUEs;     Array<String> propVALUEs;
  
     String propName;      CIMProperty prop;
       CIMQualifier trapQualifier;
  
     Uint32 propPos;  
     Uint32 qualifierPos;     Uint32 qualifierPos;
     Uint32 typePos;  
     CIMValue propValue;  
     CIMProperty trapProp;  
     CIMQualifier trapQualifier;  
  
       String propValue;
   
       String mapstr1;
       String mapstr2;
   
       PEG_METHOD_ENTER (TRC_IND_HANDLER,
           "snmpIndicationHandler::handleIndication");
   
       try
       {
     CIMClass indicationClass = _repository->getClass(     CIMClass indicationClass = _repository->getClass(
         nameSpace,              nameSpace, indication.getClassName(), false, true,
         indicationInstance.getClassName(),              false, CIMPropertyList());
         false);  
           Uint32 propertyCount = indication.getPropertyCount();
  
     //filling the array with enterprise first          for (Uint32 i=0; i < propertyCount; i++)
     propPos = indicationClass.findProperty("enterprise");          {
               prop = indication.getProperty(i);
   
               if (!prop.isUninitialized())
               {
                   CIMName propName = prop.getName();
                   Uint32 propPos = indicationClass.findProperty(propName);
     if (propPos != PEG_NOT_FOUND)     if (propPos != PEG_NOT_FOUND)
     {     {
         trapProp = indicationClass.getProperty(propPos);                      CIMProperty trapProp = indicationClass.getProperty(propPos);
         qualifierPos = trapProp.findQualifier("OID");  
         trapQualifier = trapProp.getQualifier(qualifierPos);  
         enterprise = trapQualifier.getValue().toString();  
  
         int i;                      qualifierPos = trapProp.findQualifier(CIMName ("MappingStrings"));
         for (i=0; i<indicationInstance.getPropertyCount();i++)                      if (qualifierPos != PEG_NOT_FOUND)
         {         {
             propValue = indicationInstance.getProperty(i).getValue();                          trapQualifier = trapProp.getQualifier(qualifierPos);
   
                           mapstr1.clear();
                           mapstr1 = trapQualifier.getValue().toString();
  
             if (!propValue.isNull())                          if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
                               (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
             {             {
                 propName = indicationInstance.getProperty(i).getName();                              if (mapstr1.subString(0, 8) == "OID.IETF")
                 propPos = indicationClass.findProperty(propName);                              {
                 trapProp = indicationClass.getProperty(propPos);                                  mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
                                   if (mapstr1.find("|") != PEG_NOT_FOUND)
                                   {
                                       mapstr2.clear();
                                       mapstr2 = mapstr1.subString(0,
                                           mapstr1.find("DataType.IETF")-1);
                                       propOIDs.append(mapstr2);
   
                                       propValue.clear();
                                       propValue = prop.getValue().toString();
                                       propVALUEs.append(propValue);
   
                                       mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
                                       mapstr2 = mapstr2.subString(0, mapstr2.size()-1);
                                       propTYPEs.append(mapstr2);
                                   }
                               }
                           }
                       }
                   }
               }
           }
   
           // Collected complete data in arrays and ready to send the trap.
           // trap destination and SNMP type are defined in handlerInstance
           // and passing this instance as it is to deliverTrap() call
  
                 if (trapProp.existsQualifier("OID"))          Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost"));
           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))
                 {                 {
                     if (propName == "trapOid")              // 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
               //
               if (context.contains(SnmpTrapOidContainer::NAME))
                     {                     {
                         trapOid = propValue.toString();                  SnmpTrapOidContainer trapContainer = context.get
                       (SnmpTrapOidContainer::NAME);
   
                   trapOid = trapContainer.getSnmpTrapOid();
                     }                     }
                     else                     else
                     {                     {
                         qualifierPos = trapProp.findQualifier("OID");                  // get trapOid from indication Class
                         trapQualifier = trapProp.getQualifier(qualifierPos);  
                         propOIDs.append(trapQualifier.getValue().toString());                  Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings"));
                         propVALUEs.append(propValue.toString());                  if (pos != PEG_NOT_FOUND)
                         if (trapProp.existsQualifier("SNMPTYPE"))                  {
                         {                      trapOid = indicationClass.getQualifier(pos).getValue().toString();
                             typePos = trapProp.findQualifier("SNMPTYPE");  
                             trapQualifier = trapProp.getQualifier(typePos);                      trapOid = trapOid.subString(11, PEG_NOT_FOUND);
                             propTYPEs.append(trapQualifier.getValue().toString());  
                       if ((String::compare(trapOid, "SNMP.", 5)) == 0)
                       {
                           trapOid = trapOid.subString(5, (trapOid.size()-6));
                         }                         }
                         else                         else
                             propTYPEs.append(TypeToString(trapProp.getType()));                      {
                           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);
             }             }
         }         }
  
         destination = handlerInstance.getProperty(              handler.getProperty(targetHostPos).getValue().get(targetHost);
             handlerInstance.findProperty("destination")).getValue().toString();              handler.getProperty(targetHostFormatPos).getValue().get(targetHostFormat);
               if (otherTargetHostFormatPos != PEG_NOT_FOUND)
         trapType = handlerInstance.getProperty(              {
             handlerInstance.findProperty("trapType")).getValue().toString();                  handler.getProperty(otherTargetHostFormatPos).getValue().get
                       (otherTargetHostFormat);
         // Collected complete data in arrays and ready to send the trap.              }
         // trap destination and SNMP type are defined in handlerInstance              if (portNumberPos != PEG_NOT_FOUND)
         // and passing this instance as it is to deliverTrap() call              {
 #ifdef HPUX_EMANATE                  handler.getProperty(portNumberPos).getValue().get(portNumber);
         snmpDeliverTrap_emanate emanateTrap;              }
 #else              else
         snmpDeliverTrap_stub emanateTrap;              {
 #endif                  // default port
                   portNumber = SNMP_TRAP_DEFAULT_PORT;
               }
  
         cout << "Trap to deliver " << endl;              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(trapOid,              _snmpTrapSender->deliverTrap(
             enterprise,                  trapOid,
             destination,                  securityName,
             trapType,                  targetHost,
                   targetHostFormat,
                   otherTargetHostFormat,
                   portNumber,
                   snmpVersion,
                   engineID,
             propOIDs,             propOIDs,
             propTYPEs,             propTYPEs,
             propVALUEs);             propVALUEs);
   
         cout << "Trap Delivered " << endl;  
     }     }
     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();
  
 // This is the dynamic entry point into this dynamic module. The name of          throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
 // this handler is "snmpIndicationHandler" which is appened to "PegasusCreateHandler_"      }
 // to form a symbol name. This function is called by the HandlerTable      catch (Exception& e)
 // to load this handler.      {
           PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
 extern "C" PEGASUS_EXPORT CIMHandler*          PEG_METHOD_EXIT();
     PegasusCreateHandler_snmpIndicationHandler() {  
     DDD(cout << "Called PegasusCreateHandler_snmpIndicationHandler" << endl;)          throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
     return new snmpIndicationHandler;      }
       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."));
       }
   
       PEG_METHOD_EXIT();
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
   
   PEGASUS_USING_PEGASUS;
   
   // This is the entry point into this dynamic module.
   
   extern "C" PEGASUS_EXPORT CIMHandler* PegasusCreateHandler(
       const String& handlerName)
   {
       if (handlerName == "snmpIndicationHandler")
       {
           return new snmpIndicationHandler;
       }
   
       return 0;
   }


Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.33

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2