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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2