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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2