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