(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 yi.zhou  1.31             (snmpVersionPos != PEG_NOT_FOUND))
213 kumpf    1.16         {
214 kumpf    1.20     	    // properties from the handler instance
215                           String targetHost;
216               	    String otherTargetHostFormat = String();
217               	    String securityName = String();
218               	    String engineID = String();
219               	    Uint16 targetHostFormat = 0;
220               	    Uint16 snmpVersion = 0;
221               	    Uint32 portNumber;
222               
223               	    String trapOid;
224               	    //
225                           //  Get snmpTrapOid from context
226                           //
227               	    try
228 kumpf    1.16 	    {
229 kumpf    1.20                 SnmpTrapOidContainer trapContainer = context.get
230                                   (SnmpTrapOidContainer::NAME);
231 kumpf    1.16 
232 kumpf    1.20                 trapOid = trapContainer.getSnmpTrapOid();
233               	    }
234               	    catch (Exception& e)
235                           {
236               	        // get trapOid from indication Class
237 kumpf    1.16 
238 kumpf    1.20 	        Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings"));
239               	        if (pos != PEG_NOT_FOUND)
240 kumpf    1.16 	        {
241 kumpf    1.20 	            trapOid = indicationClass.getQualifier(pos).getValue().toString();
242               
243               		    trapOid = trapOid.subString(11, PEG_NOT_FOUND);
244               
245                                   if ((String::compare(trapOid, "SNMP.", 5)) == 0)
246                                   {
247                                       trapOid = trapOid.subString(5, (trapOid.size()-6));
248                                   }
249               	            else
250               	            {
251               			PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
252               			    		 "Invalid MappingStrings Value " + trapOid);
253               			PEG_METHOD_EXIT();
254               		        // l10n
255               	                // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Invalid MappingStrings Value");
256               		        throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
257 humberto 1.18 						   MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_MS_VALUE",
258               								       "Invalid MappingStrings Value")); 
259 kumpf    1.20 	            }
260               	        }
261               	        else
262               	        {
263               		    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
264               		    		 "Qualifier MappingStrings can not be found.");
265               		    PEG_METHOD_EXIT();
266               	    	    //L10N_ TODO DONE
267               	            //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Qualifier MappingStrings can not be found");
268               		    MessageLoaderParms parms("Handler.snmpIndicationHandler.snmpIndicationHandler.QUALIFIER_MAPPINGS_NOT_FOUND",
269               								 "Qualifier MappingStrings can not be found");
270               		    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms);
271 kumpf    1.16 	        }
272               	    }
273 kumpf    1.20 
274               	    handler.getProperty(targetHostPos).getValue().get(targetHost);
275               	    handler.getProperty(targetHostFormatPos).getValue().get(targetHostFormat);
276               	    if (otherTargetHostFormatPos != PEG_NOT_FOUND)
277               	    { 
278               	        handler.getProperty(otherTargetHostFormatPos).getValue().get
279               		    (otherTargetHostFormat);
280               	    }
281               	    if (portNumberPos != PEG_NOT_FOUND)
282               	    {
283               	        handler.getProperty(portNumberPos).getValue().get(portNumber);
284               	    }
285 kumpf    1.16 	    else
286               	    {
287 kumpf    1.20 	        // default port
288               	        portNumber = SNMP_TRAP_DEFAULT_PORT;
289               	    }
290               
291               	    handler.getProperty(snmpVersionPos).getValue().get(snmpVersion);
292               	    if (securityNamePos != PEG_NOT_FOUND)
293               	    {
294               	        handler.getProperty(securityNamePos).getValue().get(securityName);
295               	    }
296               	    if (engineIDPos != PEG_NOT_FOUND)
297               	    {
298               	        handler.getProperty(engineIDPos).getValue().get(engineID);
299 kumpf    1.16 	    }
300 kumpf    1.13 
301 yi.zhou  1.30 	    snmpTrap.deliverTrap(
302 kumpf    1.20                 trapOid,
303                               securityName,
304                               targetHost,
305                               targetHostFormat,
306               	        otherTargetHostFormat,
307               	        portNumber,
308               	        snmpVersion,
309               	        engineID,
310                               propOIDs,  
311                               propTYPEs, 
312                               propVALUEs);
313                       }
314                       else
315                       {
316               	    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
317               		"Invalid IndicationHandlerSNMPMapper instance.");
318               	    PEG_METHOD_EXIT();
319                         // l10n
320 humberto 1.15 
321 kumpf    1.20           // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, 
322                         // "Invalid IndicationHandlerSNMPMapper instance");
323 humberto 1.15 
324 kumpf    1.20           throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, 
325 humberto 1.18 				     MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_SNMP_INSTANCE", 
326               							"Invalid IndicationHandlerSNMPMapper instance"));
327 kumpf    1.20         }
328                   } 
329                   catch (CIMException & c)
330                   {
331               	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage()); 
332               	PEG_METHOD_EXIT();
333               
334               	throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
335                   }
336                   catch (Exception& e)
337                   {
338               	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
339               	PEG_METHOD_EXIT();
340               
341               	throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
342                   }
343                   catch (...)
344                   {
345               	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
346               		"Failed to deliver trap.");
347               	PEG_METHOD_EXIT();
348 kumpf    1.20 
349               	throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
350               		MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.FAILED_TO_DELIVER_TRAP", 
351               				   "Failed to deliver trap."));
352 kumpf    1.13     }
353 yi.zhou  1.30 
354                   PEG_METHOD_EXIT();
355 mike     1.2  }
356               
357               // This is the dynamic entry point into this dynamic module. The name of
358 kumpf    1.13 // this handler is "snmpIndicationHandler" which is appended to "PegasusCreateHandler_"
359 mike     1.2  // to form a symbol name. This function is called by the HandlerTable
360               // to load this handler.
361               
362               extern "C" PEGASUS_EXPORT CIMHandler* 
363                   PegasusCreateHandler_snmpIndicationHandler() {
364                   return new snmpIndicationHandler;
365               }
366               
367               PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2