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