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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2