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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2