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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2