(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            //%/////////////////////////////////////////////////////////////////////////////
 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 yi.zhou 1.27 #elif defined (PEGASUS_USE_NET_SNMP)
 47              #include "snmpDeliverTrap_netsnmp.h"
 48 mike    1.2  #else
 49              #include "snmpDeliverTrap_stub.h"
 50              #endif
 51              
 52 humberto 1.15 // l10n
 53               #include <Pegasus/Common/MessageLoader.h>
 54               
 55 kumpf    1.32 PEGASUS_USING_STD;
 56               
 57 mike     1.2  PEGASUS_NAMESPACE_BEGIN
 58               
 59 kumpf    1.32 snmpIndicationHandler::snmpIndicationHandler()
 60               {
 61                   PEG_METHOD_ENTER (TRC_IND_HANDLER,
 62                       "snmpIndicationHandler::snmpIndicationHandler");
 63 mike     1.2  
 64 yi.zhou  1.30 #ifdef HPUX_EMANATE
 65 kumpf    1.32     _snmpTrapSender = new snmpDeliverTrap_emanate();
 66 yi.zhou  1.30 #elif defined (PEGASUS_USE_NET_SNMP)
 67 kumpf    1.32     _snmpTrapSender = new snmpDeliverTrap_netsnmp();
 68 yi.zhou  1.30 #else
 69 kumpf    1.32     _snmpTrapSender = new snmpDeliverTrap_stub();
 70 yi.zhou  1.30 #endif
 71               
 72                   PEG_METHOD_EXIT();
 73               }
 74               
 75 mike     1.2  void snmpIndicationHandler::initialize(CIMRepository* repository)
 76               {
 77 yi.zhou  1.30     PEG_METHOD_ENTER (TRC_IND_HANDLER,
 78                       "snmpIndicationHandler::initialize");
 79               
 80 mike     1.2      _repository = repository;
 81 yi.zhou  1.30 
 82 kumpf    1.32     _snmpTrapSender->initialize();
 83 yi.zhou  1.30 
 84                   PEG_METHOD_EXIT();
 85               }
 86               
 87               void snmpIndicationHandler::terminate()
 88               {
 89                   PEG_METHOD_ENTER (TRC_IND_HANDLER,
 90                       "snmpIndicationHandler::terminate");
 91               
 92 kumpf    1.32     _snmpTrapSender->terminate();
 93 yi.zhou  1.30 
 94                   PEG_METHOD_EXIT();
 95               }
 96               
 97               snmpIndicationHandler::~snmpIndicationHandler()
 98               {
 99                   PEG_METHOD_ENTER (TRC_IND_HANDLER,
100                       "snmpIndicationHandler::~snmpIndicationHandler");
101               
102 kumpf    1.32     delete _snmpTrapSender;
103 yi.zhou  1.30 
104                   PEG_METHOD_EXIT();
105 mike     1.2  }
106               
107 chuck    1.14 // l10n - note: ignoring indication language
108 kumpf    1.16 void snmpIndicationHandler::handleIndication(
109                   const OperationContext& context,
110 yi.zhou  1.26     const String nameSpace,
111                   CIMInstance& indication,
112 kumpf    1.16     CIMInstance& handler, 
113 yi.zhou  1.26     CIMInstance& subscription,
114 kumpf    1.28     ContentLanguageList & contentLanguages)
115 mike     1.2  {
116                   Array<String> propOIDs;
117                   Array<String> propTYPEs;
118                   Array<String> propVALUEs;
119               
120                   CIMProperty prop;
121 kumpf    1.3      CIMQualifier trapQualifier;
122               
123                   Uint32 qualifierPos;
124                   
125                   String propValue;
126               
127                   String mapstr1;
128                   String mapstr2;
129 mike     1.2  
130 kumpf    1.20     PEG_METHOD_ENTER (TRC_IND_HANDLER, 
131               	"snmpIndicationHandler::handleIndication");
132 mike     1.2  
133 kumpf    1.20     try
134                   {
135                   	CIMClass indicationClass = _repository->getClass(
136               	    nameSpace, indication.getClassName(), false, true, 
137               	    false, CIMPropertyList());
138               
139                   	Uint32 propertyCount = indication.getPropertyCount();
140 kumpf    1.13 
141 kumpf    1.20     	for (Uint32 i=0; i < propertyCount; i++)
142                   	{
143               	    prop = indication.getProperty(i);
144 mike     1.2  
145 kumpf    1.20 	    if (!prop.isUninitialized())
146 kumpf    1.4              {
147 kumpf    1.20                 CIMName propName = prop.getName();
148                               Uint32 propPos = indicationClass.findProperty(propName);
149                               if (propPos != PEG_NOT_FOUND)
150                               {
151                                   CIMProperty trapProp = indicationClass.getProperty(propPos);
152 mike     1.2  
153 kumpf    1.20                     qualifierPos = trapProp.findQualifier(CIMName ("MappingStrings"));
154                                   if (qualifierPos != PEG_NOT_FOUND)
155                                   {
156               		        trapQualifier = trapProp.getQualifier(qualifierPos);
157 kumpf    1.3  		
158 kumpf    1.20 		        mapstr1.clear();
159               		        mapstr1 = trapQualifier.getValue().toString();
160 kumpf    1.3  
161 kumpf    1.20 		        if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
162               		            (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
163               		        {
164               		            if (mapstr1.subString(0, 8) == "OID.IETF")
165               		            {
166               			        mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
167                                               if (mapstr1.find("|") != PEG_NOT_FOUND)
168                                               {
169               			            mapstr2.clear();
170               			            mapstr2 = mapstr1.subString(0, 
171               				        mapstr1.find("DataType.IETF")-1);
172               			            propOIDs.append(mapstr2);
173 kumpf    1.3                              
174 kumpf    1.20 			            propValue.clear();
175                                                   propValue = prop.getValue().toString();
176               			            propVALUEs.append(propValue);
177 kumpf    1.3                              
178 kumpf    1.20 			            mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
179                                                   mapstr2 = mapstr2.subString(0, mapstr2.size()-1);
180               			            propTYPEs.append(mapstr2);
181                                               }
182               		            }
183               		        }
184               	            }
185                               }
186 kumpf    1.4              }
187 mike     1.2          }
188               
189                       // Collected complete data in arrays and ready to send the trap.
190                       // trap destination and SNMP type are defined in handlerInstance
191                       // and passing this instance as it is to deliverTrap() call
192               
193 kumpf    1.20         Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost"));
194                       Uint32 targetHostFormatPos = handler.findProperty(CIMName ("TargetHostFormat"));
195                       Uint32 otherTargetHostFormatPos = handler.findProperty(CIMName (
196 kumpf    1.13 				      "OtherTargetHostFormat"));
197 kumpf    1.20         Uint32 portNumberPos = handler.findProperty(CIMName ("PortNumber"));
198                       Uint32 snmpVersionPos = handler.findProperty(CIMName ("SNMPVersion"));
199                       Uint32 securityNamePos =  handler.findProperty(CIMName ("SNMPSecurityName"));
200                       Uint32 engineIDPos =  handler.findProperty(CIMName ("SNMPEngineID"));
201               
202                       if ((targetHostPos != PEG_NOT_FOUND) &&
203                           (targetHostFormatPos != PEG_NOT_FOUND) && 
204 yi.zhou  1.31             (snmpVersionPos != PEG_NOT_FOUND))
205 kumpf    1.16         {
206 kumpf    1.20     	    // properties from the handler instance
207                           String targetHost;
208               	    String otherTargetHostFormat = String();
209               	    String securityName = String();
210               	    String engineID = String();
211               	    Uint16 targetHostFormat = 0;
212               	    Uint16 snmpVersion = 0;
213               	    Uint32 portNumber;
214               
215               	    String trapOid;
216               	    //
217                           //  Get snmpTrapOid from context
218                           //
219 kumpf    1.32 	    if (context.contains(SnmpTrapOidContainer::NAME))
220 kumpf    1.16 	    {
221 kumpf    1.20                 SnmpTrapOidContainer trapContainer = context.get
222                                   (SnmpTrapOidContainer::NAME);
223 kumpf    1.16 
224 kumpf    1.20                 trapOid = trapContainer.getSnmpTrapOid();
225               	    }
226 kumpf    1.32 	    else
227 kumpf    1.20             {
228               	        // get trapOid from indication Class
229 kumpf    1.16 
230 kumpf    1.20 	        Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings"));
231               	        if (pos != PEG_NOT_FOUND)
232 kumpf    1.16 	        {
233 kumpf    1.20 	            trapOid = indicationClass.getQualifier(pos).getValue().toString();
234               
235               		    trapOid = trapOid.subString(11, PEG_NOT_FOUND);
236               
237                                   if ((String::compare(trapOid, "SNMP.", 5)) == 0)
238                                   {
239                                       trapOid = trapOid.subString(5, (trapOid.size()-6));
240                                   }
241               	            else
242               	            {
243               			PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
244               			    		 "Invalid MappingStrings Value " + trapOid);
245               			PEG_METHOD_EXIT();
246               		        // l10n
247               	                // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Invalid MappingStrings Value");
248               		        throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
249 humberto 1.18 						   MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_MS_VALUE",
250               								       "Invalid MappingStrings Value")); 
251 kumpf    1.20 	            }
252               	        }
253               	        else
254               	        {
255               		    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
256               		    		 "Qualifier MappingStrings can not be found.");
257               		    PEG_METHOD_EXIT();
258               	    	    //L10N_ TODO DONE
259               	            //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Qualifier MappingStrings can not be found");
260               		    MessageLoaderParms parms("Handler.snmpIndicationHandler.snmpIndicationHandler.QUALIFIER_MAPPINGS_NOT_FOUND",
261               								 "Qualifier MappingStrings can not be found");
262               		    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms);
263 kumpf    1.16 	        }
264               	    }
265 kumpf    1.20 
266               	    handler.getProperty(targetHostPos).getValue().get(targetHost);
267               	    handler.getProperty(targetHostFormatPos).getValue().get(targetHostFormat);
268               	    if (otherTargetHostFormatPos != PEG_NOT_FOUND)
269               	    { 
270               	        handler.getProperty(otherTargetHostFormatPos).getValue().get
271               		    (otherTargetHostFormat);
272               	    }
273               	    if (portNumberPos != PEG_NOT_FOUND)
274               	    {
275               	        handler.getProperty(portNumberPos).getValue().get(portNumber);
276               	    }
277 kumpf    1.16 	    else
278               	    {
279 kumpf    1.20 	        // default port
280               	        portNumber = SNMP_TRAP_DEFAULT_PORT;
281               	    }
282               
283               	    handler.getProperty(snmpVersionPos).getValue().get(snmpVersion);
284               	    if (securityNamePos != PEG_NOT_FOUND)
285               	    {
286               	        handler.getProperty(securityNamePos).getValue().get(securityName);
287               	    }
288               	    if (engineIDPos != PEG_NOT_FOUND)
289               	    {
290               	        handler.getProperty(engineIDPos).getValue().get(engineID);
291 kumpf    1.16 	    }
292 kumpf    1.13 
293 kumpf    1.32 	    _snmpTrapSender->deliverTrap(
294 kumpf    1.20                 trapOid,
295                               securityName,
296                               targetHost,
297                               targetHostFormat,
298               	        otherTargetHostFormat,
299               	        portNumber,
300               	        snmpVersion,
301               	        engineID,
302                               propOIDs,  
303                               propTYPEs, 
304                               propVALUEs);
305                       }
306                       else
307                       {
308               	    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
309               		"Invalid IndicationHandlerSNMPMapper instance.");
310               	    PEG_METHOD_EXIT();
311                         // l10n
312 humberto 1.15 
313 kumpf    1.20           // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, 
314                         // "Invalid IndicationHandlerSNMPMapper instance");
315 humberto 1.15 
316 kumpf    1.20           throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED, 
317 humberto 1.18 				     MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_SNMP_INSTANCE", 
318               							"Invalid IndicationHandlerSNMPMapper instance"));
319 kumpf    1.20         }
320                   } 
321                   catch (CIMException & c)
322                   {
323               	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, c.getMessage()); 
324               	PEG_METHOD_EXIT();
325               
326               	throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, c.getMessage());
327                   }
328                   catch (Exception& e)
329                   {
330               	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, e.getMessage());
331               	PEG_METHOD_EXIT();
332               
333               	throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, e.getMessage());
334                   }
335                   catch (...)
336                   {
337               	PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
338               		"Failed to deliver trap.");
339               	PEG_METHOD_EXIT();
340 kumpf    1.20 
341               	throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
342               		MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.FAILED_TO_DELIVER_TRAP", 
343               				   "Failed to deliver trap."));
344 kumpf    1.13     }
345 yi.zhou  1.30 
346                   PEG_METHOD_EXIT();
347 mike     1.2  }
348               
349 kumpf    1.32 PEGASUS_NAMESPACE_END
350               
351               PEGASUS_USING_PEGASUS;
352               
353 mike     1.2  // This is the dynamic entry point into this dynamic module. The name of
354 kumpf    1.13 // this handler is "snmpIndicationHandler" which is appended to "PegasusCreateHandler_"
355 mike     1.2  // to form a symbol name. This function is called by the HandlerTable
356               // to load this handler.
357               
358 kumpf    1.32 extern "C" PEGASUS_EXPORT
359               CIMHandler* PegasusCreateHandler_snmpIndicationHandler()
360               {
361 mike     1.2      return new snmpIndicationHandler;
362               }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2