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 kumpf 1.4 if (propPos != PEG_NOT_FOUND)
87 {
|
88 kumpf 1.3 CIMProperty trapProp = indicationClass.getProperty(propPos);
|
89 mike 1.2
|
90 kumpf 1.3 if (trapProp.existsQualifier("MappingStrings"))
|
91 mike 1.2 {
|
92 kumpf 1.3 qualifierPos = trapProp.findQualifier("MappingStrings");
93 trapQualifier = trapProp.getQualifier(qualifierPos);
94
95 mapstr1.clear();
96 mapstr1 = trapQualifier.getValue().toString();
97
98 if ((mapstr1.find("OID.IETF") != PEG_NOT_FOUND) &&
99 (mapstr1.find("DataType.IETF") != PEG_NOT_FOUND))
100 {
101 if (mapstr1.subString(0, 8) == "OID.IETF")
102 {
103 mapstr1 = mapstr1.subString(mapstr1.find("SNMP.")+5);
104 if (mapstr1.find("|") != PEG_NOT_FOUND)
105 {
106 mapstr2.clear();
107 mapstr2 = mapstr1.subString(0,
108 mapstr1.find("DataType.IETF")-1);
109 propOIDs.append(mapstr2);
110
111 propValue.clear();
112 propValue = prop.getValue().toString();
113 kumpf 1.3 propVALUEs.append(propValue);
114
115 mapstr2 = mapstr1.subString(mapstr1.find("|")+2);
|
116 kumpf 1.6 mapstr2 = mapstr2.subString(0, mapstr2.size()-1);
|
117 kumpf 1.4 propTYPEs.append(mapstr2);
|
118 kumpf 1.3 }
|
119 mike 1.2 }
|
120 kumpf 1.3 }
121 }
|
122 kumpf 1.4 }
|
123 mike 1.2 }
|
124 kumpf 1.3 }
|
125 mike 1.2
126 // Collected complete data in arrays and ready to send the trap.
127 // trap destination and SNMP type are defined in handlerInstance
128 // and passing this instance as it is to deliverTrap() call
129
130 #ifdef HPUX_EMANATE
131 snmpDeliverTrap_emanate emanateTrap;
132 #else
133 snmpDeliverTrap_stub emanateTrap;
134 #endif
135
|
136 kumpf 1.3 if ((handler.findProperty("TrapDestination") != PEG_NOT_FOUND) &&
137 (handler.findProperty("SNMPVersion") != PEG_NOT_FOUND) &&
|
138 kumpf 1.5 (indicationClass.findQualifier("MappingStrings") != PEG_NOT_FOUND))
|
139 kumpf 1.3 {
140 String community, trapType, destination; // from handler instance
|
141 kumpf 1.5 String trapOid; // from indication Class
|
142 kumpf 1.3
|
143 kumpf 1.5 trapOid = indicationClass.getQualifier(
144 indicationClass.findQualifier("MappingStrings")).getValue().toString();
145
146 trapOid = trapOid.subString(trapOid.find("OID.IETF | SNMP.")+16);
|
147 kumpf 1.3
148 community = handler.getProperty(
149 handler.findProperty("SNMPCommunityName")).getValue().toString();
150
151 destination = handler.getProperty(
152 handler.findProperty("TrapDestination")).getValue().toString();
153
154 trapType = handler.getProperty(
155 handler.findProperty("SNMPVersion")).getValue().toString();
156
157 emanateTrap.deliverTrap(
158 trapOid,
159 community,
160 destination,
161 trapType,
162 propOIDs,
163 propTYPEs,
164 propVALUEs);
|
165 mike 1.2 }
|
166 kumpf 1.5 else
167 cout << "Invalid Indication" << endl;
|
168 mike 1.2 }
169
170 // This is the dynamic entry point into this dynamic module. The name of
171 // this handler is "snmpIndicationHandler" which is appened to "PegasusCreateHandler_"
172 // to form a symbol name. This function is called by the HandlerTable
173 // to load this handler.
174
175 extern "C" PEGASUS_EXPORT CIMHandler*
176 PegasusCreateHandler_snmpIndicationHandler() {
177 DDD(cout << "Called PegasusCreateHandler_snmpIndicationHandler" << endl;)
178 return new snmpIndicationHandler;
179 }
180
181 PEGASUS_NAMESPACE_END
|