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