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