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