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.4 propTYPEs.append(mapstr2);
|
117 kumpf 1.3 }
|
118 mike 1.2 }
|
119 kumpf 1.3 }
120 }
|
121 kumpf 1.4 }
|
122 mike 1.2 }
|
123 kumpf 1.3 }
|
124 mike 1.2
125 // Collected complete data in arrays and ready to send the trap.
126 // trap destination and SNMP type are defined in handlerInstance
127 // and passing this instance as it is to deliverTrap() call
128
129 #ifdef HPUX_EMANATE
130 snmpDeliverTrap_emanate emanateTrap;
131 #else
132 snmpDeliverTrap_stub emanateTrap;
133 #endif
134
|
135 kumpf 1.3 if ((handler.findProperty("TrapDestination") != PEG_NOT_FOUND) &&
136 (handler.findProperty("SNMPVersion") != PEG_NOT_FOUND) &&
|
137 kumpf 1.5 (indicationClass.findQualifier("MappingStrings") != PEG_NOT_FOUND))
|
138 kumpf 1.3 {
139 String community, trapType, destination; // from handler instance
|
140 kumpf 1.5 String trapOid; // from indication Class
|
141 kumpf 1.3
|
142 kumpf 1.5 trapOid = indicationClass.getQualifier(
143 indicationClass.findQualifier("MappingStrings")).getValue().toString();
144
145 trapOid = trapOid.subString(trapOid.find("OID.IETF | SNMP.")+16);
|
146 kumpf 1.3
147 community = handler.getProperty(
148 handler.findProperty("SNMPCommunityName")).getValue().toString();
149
150 destination = handler.getProperty(
151 handler.findProperty("TrapDestination")).getValue().toString();
152
153 trapType = handler.getProperty(
154 handler.findProperty("SNMPVersion")).getValue().toString();
155
156 emanateTrap.deliverTrap(
157 trapOid,
158 community,
159 destination,
160 trapType,
161 propOIDs,
162 propTYPEs,
163 propVALUEs);
|
164 mike 1.2 }
|
165 kumpf 1.5 else
166 cout << "Invalid Indication" << endl;
|
167 mike 1.2 }
168
169 // This is the dynamic entry point into this dynamic module. The name of
170 // this handler is "snmpIndicationHandler" which is appened to "PegasusCreateHandler_"
171 // to form a symbol name. This function is called by the HandlerTable
172 // to load this handler.
173
174 extern "C" PEGASUS_EXPORT CIMHandler*
175 PegasusCreateHandler_snmpIndicationHandler() {
176 DDD(cout << "Called PegasusCreateHandler_snmpIndicationHandler" << endl;)
177 return new snmpIndicationHandler;
178 }
179
180 PEGASUS_NAMESPACE_END
|