1 mike 1.2 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 BMC Software, Hewlett Packard, IBM, The Open Group,
4 // Tivoli Systems
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // 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 // 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 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
14 // 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 // 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 // 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 mike 1.2 //==============================================================================
23 //
24 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
25 //
26 // Modified By:
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #include <Pegasus/Common/Config.h>
31 #include <iostream>
32 #include <Pegasus/Handler/CIMHandler.h>
33 #include <Pegasus/Repository/CIMRepository.h>
34
35 #include "snmpIndicationHandler.h"
36
37 #ifdef HPUX_EMANATE
38 #include "snmpDeliverTrap_emanate.h"
39 #else
40 #include "snmpDeliverTrap_stub.h"
41 #endif
42
43 mike 1.2 PEGASUS_NAMESPACE_BEGIN
44
45 PEGASUS_USING_STD;
46
47 //#define DDD(X) X
48 #define DDD(X) // X
49
50 DDD(static const char* _SNMPINDICATIONHANDLER = "snmpIndicationHandler::";)
51
52 void snmpIndicationHandler::initialize(CIMRepository* repository)
53 {
54 _repository = repository;
55 DDD(cout << _SNMPINDICATIONHANDLER << "initialize()" << endl;)
56 }
57
|
58 kumpf 1.3 void snmpIndicationHandler::handleIndication(CIMInstance& handler,
59 CIMInstance& indication, String nameSpace)
|
60 mike 1.2 {
61 Array<String> propOIDs;
62 Array<String> propTYPEs;
63 Array<String> propVALUEs;
64
65 CIMProperty prop;
|
66 kumpf 1.3 CIMQualifier trapQualifier;
67
68 Uint32 qualifierPos;
69
70 String propValue;
71
72 String mapstr1;
73 String mapstr2;
|
74 mike 1.2
75 CIMClass indicationClass = _repository->getClass(
|
76 kumpf 1.3 nameSpace, indication.getClassName(), false);
|
77 mike 1.2
|
78 kumpf 1.3 for (Uint32 i=0; i<indication.getPropertyCount();i++)
|
79 mike 1.2 {
|
80 kumpf 1.3 prop = indication.getProperty(i);
|
81 mike 1.2
|
82 kumpf 1.3 if (prop)
|
83 mike 1.2 {
|
84 kumpf 1.3 String propName = prop.getName();
85 Uint32 propPos = indicationClass.findProperty(propName);
86 CIMProperty trapProp = indicationClass.getProperty(propPos);
|
87 mike 1.2
|
88 kumpf 1.3 if (trapProp.existsQualifier("MappingStrings"))
|
89 mike 1.2 {
|
90 kumpf 1.3 qualifierPos = trapProp.findQualifier("MappingStrings");
91 trapQualifier = trapProp.getQualifier(qualifierPos);
92
93 mapstr1.clear();
94 mapstr1 = trapQualifier.getValue().toString();
95
96 if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
97 (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
98 {
99 if (mapstr1.subString(0, 8) == "OID.IETF")
100 {
101 mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
102 if (mapstr1.find("|") != PEG_NOT_FOUND)
103 {
104 mapstr2.clear();
105 mapstr2 = mapstr1.subString(0,
106 mapstr1.find("DataType.IETF")-1);
107
108 propOIDs.append(mapstr2);
109
110 propValue.clear();
111 kumpf 1.3 propValue = prop.getValue().toString();
112 propVALUEs.append(propValue);
113
114 mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
|
115 mike 1.2
|
116 kumpf 1.3 // ATTN: There is a problem with mof compiler in
117 // loading mof with MappingString
118
119 // << 12-03-2002 : NU (HP) >>
120
121 // MappingString{}. It loads if one additional
122 // array is specified as follows:
123
124 // [MappingStrings {
125 // "OID.IETF | SNMP.1.3.6.1.4.1.11.2.3.1.6.3.1.1.4.1.1.2",
126 // "DataType.IETF | OctetString",
127 // "Junk"}]
128
129 // where "Junk" is not required in actual definition.
130
131 propTYPEs.append(mapstr2.subString(0, mapstr2.find("Junk")-1));
132 }
|
133 mike 1.2 }
|
134 kumpf 1.3 }
135 }
|
136 mike 1.2 }
|
137 kumpf 1.3 }
|
138 mike 1.2
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.3 if ((handler.findProperty("TrapDestination") != PEG_NOT_FOUND) &&
150 (handler.findProperty("SNMPVersion") != PEG_NOT_FOUND) &&
151 (indication.findQualifier("TrapOid") != PEG_NOT_FOUND))
152 {
153 String community, trapType, destination; // from handler instance
154 String trapOid; // from indication instance
155
156 trapOid = indication.getQualifier(
157 indication.findQualifier("TrapOid")).getValue().toString();
158
159 community = handler.getProperty(
160 handler.findProperty("SNMPCommunityName")).getValue().toString();
161
162 destination = handler.getProperty(
163 handler.findProperty("TrapDestination")).getValue().toString();
164
165 trapType = handler.getProperty(
166 handler.findProperty("SNMPVersion")).getValue().toString();
167
168 emanateTrap.deliverTrap(
169 trapOid,
170 kumpf 1.3 community,
171 destination,
172 trapType,
173 propOIDs,
174 propTYPEs,
175 propVALUEs);
|
176 mike 1.2 }
177 }
178
179 // This is the dynamic entry point into this dynamic module. The name of
180 // this handler is "snmpIndicationHandler" which is appened to "PegasusCreateHandler_"
181 // to form a symbol name. This function is called by the HandlerTable
182 // to load this handler.
183
184 extern "C" PEGASUS_EXPORT CIMHandler*
185 PegasusCreateHandler_snmpIndicationHandler() {
186 DDD(cout << "Called PegasusCreateHandler_snmpIndicationHandler" << endl;)
187 return new snmpIndicationHandler;
188 }
189
190 PEGASUS_NAMESPACE_END
|