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 kumpf 1.7 #include <Pegasus/Common/PegasusVersion.h>
32
|
33 mike 1.2 #include <iostream>
34 #include <Pegasus/Handler/CIMHandler.h>
35 #include <Pegasus/Repository/CIMRepository.h>
36
37 #include "snmpIndicationHandler.h"
38
39 #ifdef HPUX_EMANATE
40 #include "snmpDeliverTrap_emanate.h"
41 #else
42 #include "snmpDeliverTrap_stub.h"
43 #endif
44
45 PEGASUS_NAMESPACE_BEGIN
46
47 PEGASUS_USING_STD;
48
49 //#define DDD(X) X
50 #define DDD(X) // X
51
52 DDD(static const char* _SNMPINDICATIONHANDLER = "snmpIndicationHandler::";)
53
54 mike 1.2 void snmpIndicationHandler::initialize(CIMRepository* repository)
55 {
56 _repository = repository;
57 DDD(cout << _SNMPINDICATIONHANDLER << "initialize()" << endl;)
58 }
59
|
60 kumpf 1.3 void snmpIndicationHandler::handleIndication(CIMInstance& handler,
61 CIMInstance& indication, String nameSpace)
|
62 mike 1.2 {
63 Array<String> propOIDs;
64 Array<String> propTYPEs;
65 Array<String> propVALUEs;
66
67 CIMProperty prop;
|
68 kumpf 1.3 CIMQualifier trapQualifier;
69
70 Uint32 qualifierPos;
71
72 String propValue;
73
74 String mapstr1;
75 String mapstr2;
|
76 mike 1.2
77 CIMClass indicationClass = _repository->getClass(
|
78 kumpf 1.3 nameSpace, indication.getClassName(), false);
|
79 mike 1.2
|
80 kumpf 1.3 for (Uint32 i=0; i<indication.getPropertyCount();i++)
|
81 mike 1.2 {
|
82 kumpf 1.3 prop = indication.getProperty(i);
|
83 mike 1.2
|
84 kumpf 1.8 if (!prop.isNull())
|
85 mike 1.2 {
|
86 kumpf 1.3 String propName = prop.getName();
87 Uint32 propPos = indicationClass.findProperty(propName);
|
88 kumpf 1.4 if (propPos != PEG_NOT_FOUND)
89 {
|
90 kumpf 1.3 CIMProperty trapProp = indicationClass.getProperty(propPos);
|
91 mike 1.2
|
92 kumpf 1.3 if (trapProp.existsQualifier("MappingStrings"))
|
93 mike 1.2 {
|
94 kumpf 1.3 qualifierPos = trapProp.findQualifier("MappingStrings");
95 trapQualifier = trapProp.getQualifier(qualifierPos);
96
97 mapstr1.clear();
98 mapstr1 = trapQualifier.getValue().toString();
99
100 if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
101 (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
102 {
103 if (mapstr1.subString(0, 8) == "OID.IETF")
104 {
105 mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
106 if (mapstr1.find("|") != PEG_NOT_FOUND)
107 {
108 mapstr2.clear();
109 mapstr2 = mapstr1.subString(0,
110 mapstr1.find("DataType.IETF")-1);
111 propOIDs.append(mapstr2);
112
113 propValue.clear();
114 propValue = prop.getValue().toString();
115 kumpf 1.3 propVALUEs.append(propValue);
116
117 mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
|
118 kumpf 1.6 mapstr2 = mapstr2.subString(0, mapstr2.size()-1);
|
119 kumpf 1.4 propTYPEs.append(mapstr2);
|
120 kumpf 1.3 }
|
121 mike 1.2 }
|
122 kumpf 1.3 }
123 }
|
124 kumpf 1.4 }
|
125 mike 1.2 }
|
126 kumpf 1.3 }
|
127 mike 1.2
128 // Collected complete data in arrays and ready to send the trap.
129 // trap destination and SNMP type are defined in handlerInstance
130 // and passing this instance as it is to deliverTrap() call
131
132 #ifdef HPUX_EMANATE
133 snmpDeliverTrap_emanate emanateTrap;
134 #else
135 snmpDeliverTrap_stub emanateTrap;
136 #endif
137
|
138 kumpf 1.3 if ((handler.findProperty("TrapDestination") != PEG_NOT_FOUND) &&
139 (handler.findProperty("SNMPVersion") != PEG_NOT_FOUND) &&
|
140 kumpf 1.5 (indicationClass.findQualifier("MappingStrings") != PEG_NOT_FOUND))
|
141 kumpf 1.3 {
142 String community, trapType, destination; // from handler instance
|
143 kumpf 1.5 String trapOid; // from indication Class
|
144 kumpf 1.3
|
145 kumpf 1.5 trapOid = indicationClass.getQualifier(
146 indicationClass.findQualifier("MappingStrings")).getValue().toString();
147
148 trapOid = trapOid.subString(trapOid.find("OID.IETF | SNMP.")+16);
|
149 kumpf 1.3
150 community = handler.getProperty(
151 handler.findProperty("SNMPCommunityName")).getValue().toString();
152
153 destination = handler.getProperty(
154 handler.findProperty("TrapDestination")).getValue().toString();
155
156 trapType = handler.getProperty(
157 handler.findProperty("SNMPVersion")).getValue().toString();
158
159 emanateTrap.deliverTrap(
160 trapOid,
161 community,
162 destination,
163 trapType,
164 propOIDs,
165 propTYPEs,
166 propVALUEs);
|
167 mike 1.2 }
|
168 kumpf 1.5 else
169 cout << "Invalid Indication" << endl;
|
170 mike 1.2 }
171
172 // This is the dynamic entry point into this dynamic module. The name of
173 // this handler is "snmpIndicationHandler" which is appened to "PegasusCreateHandler_"
174 // to form a symbol name. This function is called by the HandlerTable
175 // to load this handler.
176
177 extern "C" PEGASUS_EXPORT CIMHandler*
178 PegasusCreateHandler_snmpIndicationHandler() {
179 DDD(cout << "Called PegasusCreateHandler_snmpIndicationHandler" << endl;)
180 return new snmpIndicationHandler;
181 }
182
183 PEGASUS_NAMESPACE_END
|