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

  1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3 kumpf 1.9 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
  4           // The Open Group, Tivoli Systems
  5 mike  1.2 //
  6           // Permission is hereby granted, free of charge, to any person obtaining a copy
  7 kumpf 1.9 // of this software and associated documentation files (the "Software"), to
  8           // deal in the Software without restriction, including without limitation the
  9           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 10 mike  1.2 // sell copies of the Software, and to permit persons to whom the Software is
 11           // furnished to do so, subject to the following conditions:
 12           // 
 13 kumpf 1.9 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 14 mike  1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16 kumpf 1.9 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 17           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 18           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 19 mike  1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21           //
 22           //==============================================================================
 23           //
 24           // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
 25           //
 26 kumpf 1.10 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
 27            //                (carolann_graves@hp.com)
 28 kumpf 1.13 //	      : Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
 29 mike  1.2  //
 30            //%/////////////////////////////////////////////////////////////////////////////
 31            
 32            #include <Pegasus/Common/Config.h>
 33 kumpf 1.7  #include <Pegasus/Common/PegasusVersion.h>
 34            
 35 mike  1.2  #include <iostream>
 36            #include <Pegasus/Handler/CIMHandler.h>
 37            #include <Pegasus/Repository/CIMRepository.h>
 38            
 39            #include "snmpIndicationHandler.h"
 40            
 41            #ifdef HPUX_EMANATE
 42            #include "snmpDeliverTrap_emanate.h"
 43            #else
 44            #include "snmpDeliverTrap_stub.h"
 45            #endif
 46            
 47 humberto 1.15 // l10n
 48               #include <Pegasus/Common/MessageLoader.h>
 49               
 50 mike     1.2  PEGASUS_NAMESPACE_BEGIN
 51               
 52               PEGASUS_USING_STD;
 53               
 54               void snmpIndicationHandler::initialize(CIMRepository* repository)
 55               {
 56                   _repository = repository;
 57               }
 58               
 59 chuck    1.14 // l10n - note: ignoring indication language
 60 kumpf    1.16 void snmpIndicationHandler::handleIndication(
 61                   const OperationContext& context,
 62                   CIMInstance& handler, 
 63 chuck    1.14     CIMInstance& indication, String nameSpace,
 64                   ContentLanguages & contentLanguages)
 65 mike     1.2  {
 66                   Array<String> propOIDs;
 67                   Array<String> propTYPEs;
 68                   Array<String> propVALUEs;
 69               
 70                   CIMProperty prop;
 71 kumpf    1.3      CIMQualifier trapQualifier;
 72               
 73                   Uint32 qualifierPos;
 74                   
 75                   String propValue;
 76               
 77                   String mapstr1;
 78                   String mapstr2;
 79 mike     1.2  
 80                   CIMClass indicationClass = _repository->getClass(
 81 kumpf    1.3  	nameSpace, indication.getClassName(), false);
 82 mike     1.2  
 83 kumpf    1.13     Uint32 propertyCount = indication.getPropertyCount();
 84               
 85                   for (Uint32 i=0; i < propertyCount; i++)
 86 mike     1.2      {
 87 kumpf    1.3  	prop = indication.getProperty(i);
 88 mike     1.2  
 89 kumpf    1.11 	if (!prop.isUninitialized())
 90 mike     1.2          {
 91 kumpf    1.12             CIMName propName = prop.getName();
 92 kumpf    1.3              Uint32 propPos = indicationClass.findProperty(propName);
 93 kumpf    1.4              if (propPos != PEG_NOT_FOUND)
 94                           {
 95 kumpf    1.3              CIMProperty trapProp = indicationClass.getProperty(propPos);
 96 mike     1.2  
 97 kumpf    1.12             qualifierPos = trapProp.findQualifier(CIMName ("MappingStrings"));
 98 kumpf    1.10             if (qualifierPos != PEG_NOT_FOUND)
 99 mike     1.2              {
100 kumpf    1.3  		trapQualifier = trapProp.getQualifier(qualifierPos);
101               		
102               		mapstr1.clear();
103               		mapstr1 = trapQualifier.getValue().toString();
104               
105               		if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
106               		    (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
107               		{
108               		    if (mapstr1.subString(0, 8) == "OID.IETF")
109               		    {
110               			mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
111                                       if (mapstr1.find("|") != PEG_NOT_FOUND)
112                                       {
113               			    mapstr2.clear();
114               			    mapstr2 = mapstr1.subString(0, 
115               				mapstr1.find("DataType.IETF")-1);
116               			    propOIDs.append(mapstr2);
117                                           
118               			    propValue.clear();
119                                           propValue = prop.getValue().toString();
120               			    propVALUEs.append(propValue);
121 kumpf    1.3                              
122               			    mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
123 kumpf    1.6                              mapstr2 = mapstr2.subString(0, mapstr2.size()-1);
124 kumpf    1.4  			    propTYPEs.append(mapstr2);
125 kumpf    1.3                          }
126 mike     1.2  		    }
127 kumpf    1.3  		}
128               	    }
129 kumpf    1.4              }
130 mike     1.2          }
131 kumpf    1.3      }
132 mike     1.2  
133                       // Collected complete data in arrays and ready to send the trap.
134                       // trap destination and SNMP type are defined in handlerInstance
135                       // and passing this instance as it is to deliverTrap() call
136               
137               #ifdef HPUX_EMANATE
138                       snmpDeliverTrap_emanate emanateTrap;
139               #else
140                       snmpDeliverTrap_stub emanateTrap;
141               #endif
142               
143 kumpf    1.13     Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost"));
144                   Uint32 targetHostFormatPos = handler.findProperty(CIMName ("TargetHostFormat"));
145                   Uint32 otherTargetHostFormatPos = handler.findProperty(CIMName (
146               				      "OtherTargetHostFormat"));
147                   Uint32 portNumberPos = handler.findProperty(CIMName ("PortNumber"));
148                   Uint32 snmpVersionPos = handler.findProperty(CIMName ("SNMPVersion"));
149                   Uint32 securityNamePos =  handler.findProperty(CIMName ("SNMPSecurityName"));
150                   Uint32 engineIDPos =  handler.findProperty(CIMName ("SNMPEngineID"));
151               
152                   if ((targetHostPos != PEG_NOT_FOUND) &&
153                       (targetHostFormatPos != PEG_NOT_FOUND) && 
154                       (snmpVersionPos != PEG_NOT_FOUND) && 
155 kumpf    1.12         (indicationClass.findQualifier(CIMName ("MappingStrings")) != 
156                           PEG_NOT_FOUND))
157 kumpf    1.3      {
158 kumpf    1.13 	// properties from the handler instance
159                       String targetHost, otherTargetHostFormat;
160               	String securityName, engineID;
161               	Uint16 targetHostFormat, snmpVersion;
162               	Uint32 portNumber;
163 kumpf    1.3  
164 kumpf    1.16 	String trapOid;
165               	//
166                       //  Get snmpTrapOid from context
167                       //
168               	try
169               	{
170                           SnmpTrapOidContainer trapContainer = context.get
171                               (SnmpTrapOidContainer::NAME);
172 kumpf    1.3  
173 kumpf    1.16             trapOid = trapContainer.getSnmpTrapOid();
174 kumpf    1.13 	}
175 kumpf    1.16 	catch (Exception& e)
176                       {
177               	    // get trapOid from indication Class
178 humberto 1.15 
179 kumpf    1.16 	    Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings"));
180               	    if (pos != PEG_NOT_FOUND)
181               	    {
182               	        trapOid = indicationClass.getQualifier(pos).getValue().toString();
183               
184               		trapOid = trapOid.subString(11, PEG_NOT_FOUND);
185               
186                               if ((String::compare(trapOid, "SNMP.", 5)) == 0)
187                               {
188                                   trapOid = trapOid.subString(5, (trapOid.size()-6));
189                               }
190               	        else
191               	        {
192               		    // l10n
193               	            // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Invalid MappingStrings Value");
194               		    throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
195 humberto 1.18 						   MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_MS_VALUE",
196               								       "Invalid MappingStrings Value")); 
197 kumpf    1.16 	        }
198               	    }
199               	    else
200               	    {
201 humberto 1.17 		//L10N_ TODO DONE
202               	        //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Qualifier MappingStrings can not be found");
203               		MessageLoaderParms parms("Handler.snmpIndicationHandler.snmpIndicationHandler.QUALIFIER_MAPPINGS_NOT_FOUND",
204               								 "Qualifier MappingStrings can not be found");
205               		throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms);
206 kumpf    1.16 	    }
207 kumpf    1.13 	}
208               
209               	handler.getProperty(targetHostPos).getValue().get(targetHost);
210               	handler.getProperty(targetHostFormatPos).getValue().get(targetHostFormat);
211               	handler.getProperty(otherTargetHostFormatPos).getValue().get
212               		(otherTargetHostFormat);
213               	handler.getProperty(portNumberPos).getValue().get(portNumber);
214               	handler.getProperty(snmpVersionPos).getValue().get(snmpVersion);
215               	handler.getProperty(securityNamePos).getValue().get(securityName);
216               	handler.getProperty(engineIDPos).getValue().get(engineID);
217 kumpf    1.3  
218               	emanateTrap.deliverTrap(
219                           trapOid,
220 kumpf    1.13             securityName,
221                           targetHost,
222                           targetHostFormat,
223               	    otherTargetHostFormat,
224               	    portNumber,
225               	    snmpVersion,
226               	    engineID,
227 kumpf    1.3              propOIDs,  
228                           propTYPEs, 
229                           propVALUEs);
230 mike     1.2      }
231 kumpf    1.5      else
232 kumpf    1.13     {
233 humberto 1.15       // l10n
234               
235                     // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, 
236                     // "Invalid IndicationHandlerSNMPMapper instance");
237               
238                     throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, 
239 humberto 1.18 				     MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_SNMP_INSTANCE", 
240               							"Invalid IndicationHandlerSNMPMapper instance"));
241 kumpf    1.13     }
242 mike     1.2  }
243               
244               // This is the dynamic entry point into this dynamic module. The name of
245 kumpf    1.13 // this handler is "snmpIndicationHandler" which is appended to "PegasusCreateHandler_"
246 mike     1.2  // to form a symbol name. This function is called by the HandlerTable
247               // to load this handler.
248               
249               extern "C" PEGASUS_EXPORT CIMHandler* 
250                   PegasusCreateHandler_snmpIndicationHandler() {
251                   return new snmpIndicationHandler;
252               }
253               
254               PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2