1 kumpf 1.1.2.1 //%/////////////////////////////////////////////////////////////////////////////
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 kumpf 1.1.2.1 //==============================================================================
23 //
24 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
25 //
26 // Modified By:
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30 #include <iostream>
31 #include <Pegasus/Common/Config.h>
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 kumpf 1.1.2.1 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 void snmpIndicationHandler::handleIndication(CIMInstance& handlerInstance,
59 CIMInstance& indicationInstance,
60 String nameSpace)
61 {
62 String enterprise, trapOid, destination, trapType;
63
64 kumpf 1.1.2.1 Array<String> propOIDs;
65 Array<String> propTYPEs;
66 Array<String> propVALUEs;
67
68 String propName;
69
70 Uint32 propPos;
71 Uint32 qualifierPos;
72 Uint32 typePos;
73 CIMValue propValue;
74 CIMProperty trapProp;
75 CIMQualifier trapQualifier;
76
77 CIMClass indicationClass = _repository->getClass(
78 nameSpace,
79 indicationInstance.getClassName(),
80 false);
81
82 //filling the array with enterprise first
83 propPos = indicationClass.findProperty("enterprise");
84 if (propPos != PEG_NOT_FOUND)
85 kumpf 1.1.2.1 {
86 trapProp = indicationClass.getProperty(propPos);
87 qualifierPos = trapProp.findQualifier("OID");
88 trapQualifier = trapProp.getQualifier(qualifierPos);
89 enterprise = trapQualifier.getValue().toString();
90
91 int i;
92 for (i=0; i<indicationInstance.getPropertyCount();i++)
93 {
94 propValue = indicationInstance.getProperty(i).getValue();
95
96 if (!propValue.isNull())
97 {
98 propName = indicationInstance.getProperty(i).getName();
99 propPos = indicationClass.findProperty(propName);
100 trapProp = indicationClass.getProperty(propPos);
101
102 if (trapProp.existsQualifier("OID"))
103 {
104 if (propName == "trapOid")
105 {
106 kumpf 1.1.2.1 trapOid = propValue.toString();
107 }
108 else
109 {
110 qualifierPos = trapProp.findQualifier("OID");
111 trapQualifier = trapProp.getQualifier(qualifierPos);
112 propOIDs.append(trapQualifier.getValue().toString());
113 propVALUEs.append(propValue.toString());
114 if (trapProp.existsQualifier("SNMPTYPE"))
115 {
116 typePos = trapProp.findQualifier("SNMPTYPE");
117 trapQualifier = trapProp.getQualifier(typePos);
118 propTYPEs.append(trapQualifier.getValue().toString());
119 }
120 else
121 propTYPEs.append(TypeToString(trapProp.getType()));
122 }
123 }
124 }
125 }
126
127 kumpf 1.1.2.1 destination = handlerInstance.getProperty(
128 handlerInstance.findProperty("destination")).getValue().toString();
129
130 trapType = handlerInstance.getProperty(
131 handlerInstance.findProperty("trapType")).getValue().toString();
132
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 #ifdef HPUX_EMANATE
137 snmpDeliverTrap_emanate emanateTrap;
138 #else
139 snmpDeliverTrap_stub emanateTrap;
140 #endif
141
142 cout << "Trap to deliver " << endl;
143
144 emanateTrap.deliverTrap(trapOid,
145 enterprise,
146 destination,
147 trapType,
148 kumpf 1.1.2.1 propOIDs,
149 propTYPEs,
150 propVALUEs);
151
152 cout << "Trap Delivered " << endl;
153 }
154 else
155 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
156 "Indication is without enterprise OID");
157 }
158
159 // This is the dynamic entry point into this dynamic module. The name of
160 // this handler is "snmpIndicationHandler" which is appened to "PegasusCreateHandler_"
161 // to form a symbol name. This function is called by the HandlerTable
162 // to load this handler.
163
164 extern "C" PEGASUS_EXPORT CIMHandler*
165 PegasusCreateHandler_snmpIndicationHandler() {
166 DDD(cout << "Called PegasusCreateHandler_snmpIndicationHandler" << endl;)
167 return new snmpIndicationHandler;
168 }
169 kumpf 1.1.2.1
170 PEGASUS_NAMESPACE_END
|