(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.34.4.1 and 1.39

version 1.34.4.1, 2007/04/04 11:04:48 version 1.39, 2008/08/28 17:24:42
Line 116 
Line 116 
     Array<String> propTYPEs;     Array<String> propTYPEs;
     Array<String> propVALUEs;     Array<String> propVALUEs;
  
     CIMProperty prop;      Array<String> mapStr;
     CIMQualifier trapQualifier;  
   
     Uint32 qualifierPos;  
   
     String propValue;  
   
     String mapstr1;  
     String mapstr2;  
  
     PEG_METHOD_ENTER(TRC_IND_HANDLER,     PEG_METHOD_ENTER(TRC_IND_HANDLER,
         "snmpIndicationHandler::handleIndication");         "snmpIndicationHandler::handleIndication");
  
     try     try
     {     {
           PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
               "snmpIndicationHandler %s:%s.%s processing %s Indication",
              (const char*)(nameSpace.getCString()),
              (const char*)(handler.getClassName().getString().getCString()),
              (const char*)(handler.getProperty(
              handler.findProperty(PEGASUS_PROPERTYNAME_NAME)).
              getValue().toString().getCString()),
              (const char*)(indication.getClassName().getString().
              getCString())));
         CIMClass indicationClass = _repository->getClass(         CIMClass indicationClass = _repository->getClass(
             nameSpace, indication.getClassName(), false, true,             nameSpace, indication.getClassName(), false, true,
             false, CIMPropertyList());             false, CIMPropertyList());
Line 139 
Line 140 
  
         for (Uint32 i=0; i < propertyCount; i++)         for (Uint32 i=0; i < propertyCount; i++)
         {         {
             prop = indication.getProperty(i);              CIMProperty prop = indication.getProperty(i);
  
             if (!prop.isUninitialized())              Uint32 propDeclPos = indicationClass.findProperty(prop.getName());
               if (propDeclPos != PEG_NOT_FOUND)
             {             {
                 CIMName propName = prop.getName();                  CIMProperty propDecl = indicationClass.getProperty(propDeclPos);
                 Uint32 propPos = indicationClass.findProperty(propName);  
                 if (propPos != PEG_NOT_FOUND)  
                 {  
                     CIMProperty trapProp = indicationClass.getProperty(propPos);  
  
                     qualifierPos =                  Uint32 qualifierPos =
                         trapProp.findQualifier(CIMName("MappingStrings"));                      propDecl.findQualifier(CIMName("MappingStrings"));
                     if (qualifierPos != PEG_NOT_FOUND)                     if (qualifierPos != PEG_NOT_FOUND)
                     {                     {
                         trapQualifier = trapProp.getQualifier(qualifierPos);                      //
                       // 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);
   
                       String oidStr, dataType;
                       String mapStr1, mapStr2;
                       Boolean isValidAuthority = false;
                       Boolean isValidDataType = false;
   
                       for (Uint32 j=0; j < mapStr.size(); j++)
                       {
                           Uint32 barPos = mapStr[j].find("|");
  
                         mapstr1.clear();                          if (barPos != PEG_NOT_FOUND)
                         mapstr1 = trapQualifier.getValue().toString();                          {
                               mapStr1 = mapStr[j].subString(0, barPos);
                               mapStr2 = mapStr[j].subString(barPos + 1);
   
                               _trimWhitespace(mapStr1);
                               _trimWhitespace(mapStr2);
  
                         if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&                              if ((mapStr1 == "OID.IETF") &&
                             (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))                                  (String::compare(mapStr2,
                                    String("SNMP."), 5) == 0))
                         {                         {
                             if (mapstr1.subString(0, 8) == "OID.IETF")                                  isValidAuthority = true;
                             {                                  oidStr = mapStr2.subString(5);
                                 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);  
                                 }                                 }
                               else if (mapStr1 == "DataType.IETF")
                               {
                                   isValidDataType = true;
                                   dataType = mapStr2;
                               }
   
                               if (isValidAuthority && isValidDataType)
                               {
                                   propOIDs.append(oidStr);
                                   propTYPEs.append(dataType);
                                   propVALUEs.append(prop.getValue().toString());
   
                                   break;
                             }                             }
                         }                         }
                     }                     }
Line 204 
Line 225 
             handler.findProperty(CIMName("SNMPSecurityName"));             handler.findProperty(CIMName("SNMPSecurityName"));
         Uint32 engineIDPos = handler.findProperty(CIMName("SNMPEngineID"));         Uint32 engineIDPos = handler.findProperty(CIMName("SNMPEngineID"));
  
         if ((targetHostPos != PEG_NOT_FOUND) &&          if (targetHostPos == PEG_NOT_FOUND)
             (targetHostFormatPos != PEG_NOT_FOUND) &&          {
             (snmpVersionPos != PEG_NOT_FOUND))              PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
                   "Target host is not set for IndicationHandlerSNMPMapper %s"
                   " Indication.",
                   (const char*)(indication.getClassName().getString().
                   getCString())));
               PEG_METHOD_EXIT();
               throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
                   "Handler.snmpIndicationHandler.snmpIndicationHandler."
                   "INVALID_SNMP_INSTANCE",
                   "Invalid IndicationHandlerSNMPMapper instance"));
           }
           if (targetHostFormatPos == PEG_NOT_FOUND)
           {
               PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
                   "Target host format is not set for IndicationHandlerSNMPMapper"
                   " %s Indication.",
                   (const char*)(indication.getClassName().getString().
                   getCString())));
               PEG_METHOD_EXIT();
               throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
                   "Handler.snmpIndicationHandler.snmpIndicationHandler."
                   "INVALID_SNMP_INSTANCE",
                   "Invalid IndicationHandlerSNMPMapper instance"));
           }
           if (snmpVersionPos == PEG_NOT_FOUND)
           {
               PEG_TRACE((TRC_DISCARDED_DATA, Tracer::LEVEL1,
                   "SNMP Version is not set for IndicationHandlerSNMPMapper %s"
                   " Indication.",
                   (const char*)(indication.getClassName().getString().
                   getCString())));
               PEG_METHOD_EXIT();
               throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
                   "Handler.snmpIndicationHandler.snmpIndicationHandler."
                   "INVALID_SNMP_INSTANCE",
                   "Invalid IndicationHandlerSNMPMapper instance"));
           }
           else
         {         {
             // properties from the handler instance             // properties from the handler instance
             String targetHost;             String targetHost;
Line 218 
Line 276 
             Uint32 portNumber;             Uint32 portNumber;
  
             String trapOid;             String trapOid;
               Boolean trapOidAvailable = false;
             //             //
             //  Get snmpTrapOid from context             //  Get snmpTrapOid from context
             //             //
Line 227 
Line 286 
                     context.get(SnmpTrapOidContainer::NAME);                     context.get(SnmpTrapOidContainer::NAME);
  
                 trapOid = trapContainer.getSnmpTrapOid();                 trapOid = trapContainer.getSnmpTrapOid();
                   trapOidAvailable = true;
             }             }
             else             else
             {             {
Line 236 
Line 296 
                     indicationClass.findQualifier(CIMName("MappingStrings"));                     indicationClass.findQualifier(CIMName("MappingStrings"));
                 if (pos != PEG_NOT_FOUND)                 if (pos != PEG_NOT_FOUND)
                 {                 {
                     trapOid =                      Array<String> classMapStr;
                         indicationClass.getQualifier(pos).getValue().toString();                      indicationClass.getQualifier(pos).getValue().
                           get(classMapStr);
  
                     trapOid = trapOid.subString(11, PEG_NOT_FOUND);                      for (Uint32 i=0; i < classMapStr.size(); i++)
                       {
                           Uint32 barPos = classMapStr[i].find("|");
  
                     if ((String::compare(trapOid, "SNMP.", 5)) == 0)                          if (barPos != PEG_NOT_FOUND)
                     {                     {
                         trapOid = trapOid.subString(5, (trapOid.size()-6));                              String authorityName =
                                   classMapStr[i].subString(0, barPos);
                               String oidStr = classMapStr[i].subString(
                                   barPos+1, PEG_NOT_FOUND);
   
                               _trimWhitespace(authorityName);
                               _trimWhitespace(oidStr);
   
                               if ((authorityName == "OID.IETF") &&
                                   (String::compare(oidStr,
                                    String("SNMP."), 5) == 0))
                               {
                                   trapOid = oidStr.subString(5);
                                   trapOidAvailable = true;
                                   break;
                     }                     }
                     else                          }
                       }
   
                       if (!trapOidAvailable)
                     {                     {
                         PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,                          PEG_TRACE((
                             "Invalid MappingStrings Value " + trapOid);                              TRC_IND_HANDLER,
                               Tracer::LEVEL1,
                               "No MappingStrings for snmp trap is specified "
                                   "for class: %s",
                               (const char*)
                                 indication.getClassName().getString().getCString()
                               ));
   
                         PEG_METHOD_EXIT();                         PEG_METHOD_EXIT();
                         throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,  
                           throw PEGASUS_CIM_EXCEPTION_L(
                               CIM_ERR_FAILED,
                             MessageLoaderParms(                             MessageLoaderParms(
                                 "Handler.snmpIndicationHandler."                                 "Handler.snmpIndicationHandler."
                                     "snmpIndicationHandler.INVALID_MS_VALUE",                                  "snmpIndicationHandler.NO_MS_FOR_SNMP_TRAP",
                                 "Invalid MappingStrings Value"));                                  "No MappingStrings for snmp trap is specified "
                                       "for class: $0",
                                   indication.getClassName().getString()));
                     }                     }
                 }                 }
                 else                 else
                 {                 {
                     PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL4,                      PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
                         "Qualifier MappingStrings can not be found.");                         "Qualifier MappingStrings can not be found.");
                     PEG_METHOD_EXIT();                     PEG_METHOD_EXIT();
                     MessageLoaderParms parms(                     MessageLoaderParms parms(
Line 299 
Line 390 
                 handler.getProperty(engineIDPos).getValue().get(engineID);                 handler.getProperty(engineIDPos).getValue().get(engineID);
             }             }
  
               PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
                  "snmpIndicationHandler sending %s Indication trap %s to target"
                  " host %s target port %d",
                  (const char*)(indication.getClassName().getString().
                  getCString()),
                  (const char*)(trapOid.getCString()),
                  (const char*)(targetHost.getCString()),portNumber));
             _snmpTrapSender->deliverTrap(             _snmpTrapSender->deliverTrap(
                 trapOid,                 trapOid,
                 securityName,                 securityName,
Line 311 
Line 409 
                 propOIDs,                 propOIDs,
                 propTYPEs,                 propTYPEs,
                 propVALUEs);                 propVALUEs);
         }  
         else          PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
         {             "%s Indication trap %s sent to target host %s target port %d "
             PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL4,             "successfully",
                 "Invalid IndicationHandlerSNMPMapper instance.");             (const char*)(indication.getClassName().getString().getCString()),
             PEG_METHOD_EXIT();             (const char*)(trapOid.getCString()),
             throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(             (const char*)(targetHost.getCString()),portNumber));
                 "Handler.snmpIndicationHandler.snmpIndicationHandler."  
                     "INVALID_SNMP_INSTANCE",  
                 "Invalid IndicationHandlerSNMPMapper instance"));  
         }         }
     }     }
     catch (CIMException& c)     catch (CIMException& c)
     {     {
         PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage());          PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "CIMException %s",
               (const char*)c.getMessage().getCString()));
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, c.getMessage());         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, c.getMessage());
     }     }
     catch (Exception& e)     catch (Exception& e)
     {     {
         PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());          PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "Exception %s",
               (const char*)e.getMessage().getCString()));
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
  
         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());         throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
     }     }
     catch (...)     catch (...)
     {     {
         PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL4,          PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
             "Failed to deliver trap.");             "Failed to deliver trap.");
         PEG_METHOD_EXIT();         PEG_METHOD_EXIT();
  
Line 347 
Line 444 
                 "FAILED_TO_DELIVER_TRAP",                 "FAILED_TO_DELIVER_TRAP",
             "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();     PEG_METHOD_EXIT();
 } }


Legend:
Removed from v.1.34.4.1  
changed lines
  Added in v.1.39

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2