(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.2 and 1.36

version 1.1.2.2, 2001/11/08 20:02:27 version 1.36, 2007/04/10 20:31:14
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  #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::terminate()
   {
       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();
 } }
  
 void snmpIndicationHandler::handleIndication(CIMInstance& handlerInstance,  // l10n - note: ignoring indication language
     CIMInstance& indicationInstance,  void snmpIndicationHandler::handleIndication(
     String nameSpace)      const OperationContext& context,
       const String nameSpace,
       CIMInstance& indication,
       CIMInstance& handler,
       CIMInstance& subscription,
       ContentLanguageList & 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;      Array<String> mapStr;
   
       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();
   
           for (Uint32 i=0; i < propertyCount; i++)
           {
               CIMProperty prop = indication.getProperty(i);
  
     Uint32 propPos = indicationClass.findProperty("enterprise");              Uint32 propDeclPos = indicationClass.findProperty(prop.getName());
     if (propPos != PEG_NOT_FOUND)              if (propDeclPos != PEG_NOT_FOUND)
     {     {
         CIMProperty trapProp = indicationClass.getProperty(propPos);                  CIMProperty propDecl = indicationClass.getProperty(propDeclPos);
  
         Uint32 qualifierPos = trapProp.findQualifier("MappingStrings");                  Uint32 qualifierPos =
                       propDecl.findQualifier(CIMName("MappingStrings"));
         if (qualifierPos != PEG_NOT_FOUND)         if (qualifierPos != PEG_NOT_FOUND)
         {         {
             CIMQualifier trapQualifier = trapProp.getQualifier(qualifierPos);                      //
             enterprise = trapQualifier.getValue().toString();                      // We are looking for following fields:
                       // MappingStrings {"OID.IETF | SNMP." oidStr,
                       //     "DataType.IETF |" dataType}
                       // oidStr is the object identifier (e.g. "1.3.6.1.2.1.5..."
                       // dataType is either Integer, or OctetString,
                       // or OID
                       // Following is one example:
                       // MappingStrings {"OID.IETF | SNMP.1.3.6.6.3.1.1.5.2",
                       //    "DataType.IETF | Integer"}
                       //
   
                       propDecl.getQualifier(qualifierPos).getValue().get(
                           mapStr);
  
             for (int i=0; i<indicationInstance.getPropertyCount();i++)                      String oidStr, dataType;
                       String mapStr1, mapStr2;
                       Boolean isValidAuthority = false;
                       Boolean isValidDataType = false;
   
                       for (Uint32 j=0; j < mapStr.size(); j++)
             {             {
                 char* property_oid = NULL;                          Uint32 barPos = mapStr[j].find("|");
                 char* property_value = NULL;  
                 char* property_datatype = NULL;  
  
                 prop = indicationInstance.getProperty(i);                          if (barPos != PEG_NOT_FOUND)
                           {
                               mapStr1 = mapStr[j].subString(0, barPos);
                               mapStr2 = mapStr[j].subString(barPos + 1);
  
                 if (prop != NULL)                              _trimWhitespace(mapStr1);
                               _trimWhitespace(mapStr2);
   
                               if ((mapStr1 == "OID.IETF") &&
                                   (String::compare(mapStr2,
                                    String("SNMP."), 5) == 0))
                               {
                                   isValidAuthority = true;
                                   oidStr = mapStr2.subString(5);
                               }
                               else if (mapStr1 == "DataType.IETF")
                 {                 {
                     String propName = prop.getName();                                  isValidDataType = true;
                     Uint32 propPos = indicationClass.findProperty(propName);                                  dataType = mapStr2;
                     CIMProperty trapProp = indicationClass.getProperty(propPos);                              }
  
                     if (trapProp.existsQualifier("MappingStrings"))                              if (isValidAuthority && isValidDataType)
                     {                     {
                         if (propName == "trapOid")                                  propOIDs.append(oidStr);
                                   propTYPEs.append(dataType);
                                   propVALUEs.append(prop.getValue().toString());
   
                                   break;
                               }
                           }
                       }
                   }
               }
           }
   
           // 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
   
           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))
           {
               // 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;
               Boolean trapOidAvailable = false;
               String exceptionStr;
               //
               //  Get snmpTrapOid from context
               //
               if (context.contains(SnmpTrapOidContainer::NAME))
                         {                         {
                             trapOid = prop.getValue().toString();                  SnmpTrapOidContainer trapContainer =
                       context.get(SnmpTrapOidContainer::NAME);
   
                   trapOid = trapContainer.getSnmpTrapOid();
                   trapOidAvailable = true;
                         }                         }
                         else                         else
                         {                         {
                             Uint32 qualifierPos = trapProp.findQualifier("MappingStrings");                  // get trapOid from indication Class
                             CIMQualifier trapQualifier = trapProp.getQualifier(qualifierPos);  
  
                             String mapstr1 = trapQualifier.getValue().toString();                  Uint32 pos =
                             String mapstr2 = "";                      indicationClass.findQualifier(CIMName("MappingStrings"));
                   if (pos != PEG_NOT_FOUND)
                             if ((mapstr1.find("OID") != PEG_NOT_FOUND) &&  
                                 (mapstr1.find("SNMP") != PEG_NOT_FOUND))  
                             {                             {
                                 if (mapstr1.subString(0, 4) == "OID.")                      Array<String> classMapStr;
                       indicationClass.getQualifier(pos).getValue().
                           get(classMapStr);
   
                       for (Uint32 i=0; i < classMapStr.size(); i++)
                                 {                                 {
                                     mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);                          Uint32 barPos = classMapStr[i].find("|");
                                     if (mapstr1.find("|") != PEG_NOT_FOUND)  
                           if (barPos != PEG_NOT_FOUND)
                                     {                                     {
                                         mapstr2 = mapstr1.subString(0, mapstr1.find("|"));                              String authorityName =
                                   classMapStr[i].subString(0, barPos);
                               String oidStr = classMapStr[i].subString(
                                   barPos+1, PEG_NOT_FOUND);
  
                                         propOIDs.append(mapstr2);                              _trimWhitespace(authorityName);
                                         propVALUEs.append(prop.getValue().toString());                              _trimWhitespace(oidStr);
                                         propTYPEs.append(mapstr1.subString(mapstr1.find("|")+1));  
                                     }                              if ((authorityName == "OID.IETF") &&
                                   (String::compare(oidStr,
                                    String("SNMP."), 5) == 0))
                               {
                                   trapOid = oidStr.subString(5);
                                   trapOidAvailable = true;
                                   break;
                                 }                                 }
                             }                             }
                         }                         }
   
                       if (!trapOidAvailable)
                       {
                           exceptionStr = "No MappingStrings for snmp trap"
                               "is specified for class: ";
   
                           exceptionStr.append(
                               indication.getClassName().getString());
   
                           PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
                               exceptionStr);
                           PEG_METHOD_EXIT();
   
                           throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
                               MessageLoaderParms(
                                   "Handler.snmpIndicationHandler."
                                   "snmpIndicationHandler.NO_MS_FOR_SNMP_TRAP",
                                   exceptionStr));
                     }                     }
                 }                 }
                   else
                   {
                       PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL4,
                           "Qualifier MappingStrings can not be found.");
                       PEG_METHOD_EXIT();
                       MessageLoaderParms parms(
                           "Handler.snmpIndicationHandler.snmpIndicationHandler."
                               "QUALIFIER_MAPPINGS_NOT_FOUND",
                           "Qualifier MappingStrings can not be found");
                       throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms);
             }             }
         }         }
  
         // Collected complete data in arrays and ready to send the trap.              handler.getProperty(targetHostPos).getValue().get(targetHost);
         // trap destination and SNMP type are defined in handlerInstance              handler.getProperty(targetHostFormatPos).getValue().get(
         // and passing this instance as it is to deliverTrap() call                  targetHostFormat);
               if (otherTargetHostFormatPos != PEG_NOT_FOUND)
 #ifdef HPUX_EMANATE              {
         snmpDeliverTrap_emanate emanateTrap;                  handler.getProperty(otherTargetHostFormatPos).getValue().get(
 #else                      otherTargetHostFormat);
         snmpDeliverTrap_stub emanateTrap;              }
 #endif              if (portNumberPos != PEG_NOT_FOUND)
               {
                   handler.getProperty(portNumberPos).getValue().get(portNumber);
               }
               else
               {
                   // default port
                   portNumber = SNMP_TRAP_DEFAULT_PORT;
               }
  
         if ((handlerInstance.findProperty("Destination") != PEG_NOT_FOUND) &&              handler.getProperty(snmpVersionPos).getValue().get(snmpVersion);
             (handlerInstance.findProperty("trapType") != PEG_NOT_FOUND))              if (securityNamePos != PEG_NOT_FOUND)
               {
                   handler.getProperty(securityNamePos).getValue().get(
                       securityName);
               }
               if (engineIDPos != PEG_NOT_FOUND)
         {         {
             emanateTrap.deliverTrap(trapOid,                  handler.getProperty(engineIDPos).getValue().get(engineID);
                 enterprise,              }
                 handlerInstance.getProperty(handlerInstance.findProperty("Destination"))  
                     .getValue().toString(),              _snmpTrapSender->deliverTrap(
                 handlerInstance.getProperty(handlerInstance.findProperty("trapType"))                  trapOid,
                     .getValue().toString(),                  securityName,
                   targetHost,
                   targetHostFormat,
                   otherTargetHostFormat,
                   portNumber,
                   snmpVersion,
                   engineID,
                 propOIDs,                 propOIDs,
                 propTYPEs,                 propTYPEs,
                 propVALUEs);                 propVALUEs);
         }         }
     }  
     else     else
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,          {
             "Indication is without enterprise OID");              PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL4,
                   "Invalid IndicationHandlerSNMPMapper instance.");
               PEG_METHOD_EXIT();
               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();
  
 // This is the dynamic entry point into this dynamic module. The name of          throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
 // this handler is "snmpIndicationHandler" which is appened to "PegasusCreateHandler_"      }
 // to form a symbol name. This function is called by the HandlerTable      catch (...)
 // to load this handler.      {
           PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL4,
 extern "C" PEGASUS_EXPORT CIMHandler*              "Failed to deliver trap.");
     PegasusCreateHandler_snmpIndicationHandler() {          PEG_METHOD_EXIT();
     DDD(cout << "Called PegasusCreateHandler_snmpIndicationHandler" << endl;)  
     return new snmpIndicationHandler;          throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
               "Handler.snmpIndicationHandler.snmpIndicationHandler."
                   "FAILED_TO_DELIVER_TRAP",
               "Failed to deliver trap."));
       }
   
       PEG_METHOD_EXIT();
   }
   
   void snmpIndicationHandler::_trimWhitespace(
       String & nameStr)
   {
       PEG_METHOD_ENTER(TRC_IND_HANDLER,
           "snmpIndicationHandler::_trimWhitespace");
   
       Uint32 ps = 0;
       // skip begining whitespace
       for (ps = 0; ps < nameStr.size(); ps++)
       {
           if (nameStr[ps] != ' ')
           {
               break;
           }
       }
   
       if (ps != 0)
       {
           nameStr.remove(0, ps);
       }
   
       // skip the appended whitespace
       for (ps = nameStr.size(); ps != 0; ps--)
       {
           if (nameStr[ps-1] != ' ')
           {
               break;
           }
       }
   
       if (ps !=  nameStr.size())
       {
           nameStr.remove(ps);
       }
   
       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.2  
changed lines
  Added in v.1.36

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2