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 CIMClass indicationClass = _repository->getClass(
|
81 kumpf 1.19 nameSpace, indication.getClassName(), false, true, false, CIMPropertyList());
|
82 mike 1.2
|
83 kumpf 1.13 Uint32 propertyCount = indication.getPropertyCount();
84
85 for (Uint32 i=0; i < propertyCount; i++)
|
86 mike 1.2 {
|
87 kumpf 1.3 prop = indication.getProperty(i);
|
88 mike 1.2
|
89 kumpf 1.11 if (!prop.isUninitialized())
|
90 mike 1.2 {
|
91 kumpf 1.12 CIMName propName = prop.getName();
|
92 kumpf 1.3 Uint32 propPos = indicationClass.findProperty(propName);
|
93 kumpf 1.4 if (propPos != PEG_NOT_FOUND)
94 {
|
95 kumpf 1.3 CIMProperty trapProp = indicationClass.getProperty(propPos);
|
96 mike 1.2
|
97 kumpf 1.12 qualifierPos = trapProp.findQualifier(CIMName ("MappingStrings"));
|
98 kumpf 1.10 if (qualifierPos != PEG_NOT_FOUND)
|
99 mike 1.2 {
|
100 kumpf 1.3 trapQualifier = trapProp.getQualifier(qualifierPos);
101
102 mapstr1.clear();
103 mapstr1 = trapQualifier.getValue().toString();
104
105 if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
106 (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
107 {
108 if (mapstr1.subString(0, 8) == "OID.IETF")
109 {
110 mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
111 if (mapstr1.find("|") != PEG_NOT_FOUND)
112 {
113 mapstr2.clear();
114 mapstr2 = mapstr1.subString(0,
115 mapstr1.find("DataType.IETF")-1);
116 propOIDs.append(mapstr2);
117
118 propValue.clear();
119 propValue = prop.getValue().toString();
120 propVALUEs.append(propValue);
121 kumpf 1.3
122 mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
|
123 kumpf 1.6 mapstr2 = mapstr2.subString(0, mapstr2.size()-1);
|
124 kumpf 1.4 propTYPEs.append(mapstr2);
|
125 kumpf 1.3 }
|
126 mike 1.2 }
|
127 kumpf 1.3 }
128 }
|
129 kumpf 1.4 }
|
130 mike 1.2 }
|
131 kumpf 1.3 }
|
132 mike 1.2
133 // Collected complete data in arrays and ready to send the trap.
134 // trap destination and SNMP type are defined in handlerInstance
135 // and passing this instance as it is to deliverTrap() call
136
137 #ifdef HPUX_EMANATE
138 snmpDeliverTrap_emanate emanateTrap;
139 #else
140 snmpDeliverTrap_stub emanateTrap;
141 #endif
142
|
143 kumpf 1.13 Uint32 targetHostPos = handler.findProperty(CIMName ("TargetHost"));
144 Uint32 targetHostFormatPos = handler.findProperty(CIMName ("TargetHostFormat"));
145 Uint32 otherTargetHostFormatPos = handler.findProperty(CIMName (
146 "OtherTargetHostFormat"));
147 Uint32 portNumberPos = handler.findProperty(CIMName ("PortNumber"));
148 Uint32 snmpVersionPos = handler.findProperty(CIMName ("SNMPVersion"));
149 Uint32 securityNamePos = handler.findProperty(CIMName ("SNMPSecurityName"));
150 Uint32 engineIDPos = handler.findProperty(CIMName ("SNMPEngineID"));
151
152 if ((targetHostPos != PEG_NOT_FOUND) &&
153 (targetHostFormatPos != PEG_NOT_FOUND) &&
154 (snmpVersionPos != PEG_NOT_FOUND) &&
|
155 kumpf 1.12 (indicationClass.findQualifier(CIMName ("MappingStrings")) !=
156 PEG_NOT_FOUND))
|
157 kumpf 1.3 {
|
158 kumpf 1.13 // properties from the handler instance
|
159 kumpf 1.19 String targetHost;
160 String otherTargetHostFormat = String();
161 String securityName = String();
162 String engineID = String();
163 Uint16 targetHostFormat = 0;
164 Uint16 snmpVersion = 0;
|
165 kumpf 1.13 Uint32 portNumber;
|
166 kumpf 1.3
|
167 kumpf 1.16 String trapOid;
168 //
169 // Get snmpTrapOid from context
170 //
171 try
172 {
173 SnmpTrapOidContainer trapContainer = context.get
174 (SnmpTrapOidContainer::NAME);
|
175 kumpf 1.3
|
176 kumpf 1.16 trapOid = trapContainer.getSnmpTrapOid();
|
177 kumpf 1.13 }
|
178 kumpf 1.16 catch (Exception& e)
179 {
180 // get trapOid from indication Class
|
181 humberto 1.15
|
182 kumpf 1.16 Uint32 pos = indicationClass.findQualifier(CIMName ("MappingStrings"));
183 if (pos != PEG_NOT_FOUND)
184 {
185 trapOid = indicationClass.getQualifier(pos).getValue().toString();
186
187 trapOid = trapOid.subString(11, PEG_NOT_FOUND);
188
189 if ((String::compare(trapOid, "SNMP.", 5)) == 0)
190 {
191 trapOid = trapOid.subString(5, (trapOid.size()-6));
192 }
193 else
194 {
195 // l10n
196 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Invalid MappingStrings Value");
197 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
|
198 humberto 1.18 MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_MS_VALUE",
199 "Invalid MappingStrings Value"));
|
200 kumpf 1.16 }
201 }
202 else
203 {
|
204 humberto 1.17 //L10N_ TODO DONE
205 //throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Qualifier MappingStrings can not be found");
206 MessageLoaderParms parms("Handler.snmpIndicationHandler.snmpIndicationHandler.QUALIFIER_MAPPINGS_NOT_FOUND",
207 "Qualifier MappingStrings can not be found");
208 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, parms);
|
209 kumpf 1.16 }
|
210 kumpf 1.13 }
211
212 handler.getProperty(targetHostPos).getValue().get(targetHost);
213 handler.getProperty(targetHostFormatPos).getValue().get(targetHostFormat);
|
214 kumpf 1.19 if (otherTargetHostFormatPos != PEG_NOT_FOUND)
215 {
216 handler.getProperty(otherTargetHostFormatPos).getValue().get
|
217 kumpf 1.13 (otherTargetHostFormat);
|
218 kumpf 1.19 }
219 if (portNumberPos != PEG_NOT_FOUND)
220 {
221 handler.getProperty(portNumberPos).getValue().get(portNumber);
222 }
|
223 kumpf 1.13 handler.getProperty(snmpVersionPos).getValue().get(snmpVersion);
|
224 kumpf 1.19 if (securityNamePos != PEG_NOT_FOUND)
225 {
226 handler.getProperty(securityNamePos).getValue().get(securityName);
227 }
228 if (engineIDPos != PEG_NOT_FOUND)
229 {
230 handler.getProperty(engineIDPos).getValue().get(engineID);
231 }
|
232 kumpf 1.3
233 emanateTrap.deliverTrap(
234 trapOid,
|
235 kumpf 1.13 securityName,
236 targetHost,
237 targetHostFormat,
238 otherTargetHostFormat,
239 portNumber,
240 snmpVersion,
241 engineID,
|
242 kumpf 1.3 propOIDs,
243 propTYPEs,
244 propVALUEs);
|
245 mike 1.2 }
|
246 kumpf 1.5 else
|
247 kumpf 1.13 {
|
248 humberto 1.15 // l10n
249
250 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
251 // "Invalid IndicationHandlerSNMPMapper instance");
252
253 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
|
254 humberto 1.18 MessageLoaderParms("Handler.snmpIndicationHandler.snmpIndicationHandler.INVALID_SNMP_INSTANCE",
255 "Invalid IndicationHandlerSNMPMapper instance"));
|
256 kumpf 1.13 }
|
257 mike 1.2 }
258
259 // This is the dynamic entry point into this dynamic module. The name of
|
260 kumpf 1.13 // this handler is "snmpIndicationHandler" which is appended to "PegasusCreateHandler_"
|
261 mike 1.2 // to form a symbol name. This function is called by the HandlerTable
262 // to load this handler.
263
264 extern "C" PEGASUS_EXPORT CIMHandler*
265 PegasusCreateHandler_snmpIndicationHandler() {
266 return new snmpIndicationHandler;
267 }
268
269 PEGASUS_NAMESPACE_END
|