1 karl 1.2 //%2006////////////////////////////////////////////////////////////////////////
|
2 yi.zhou 1.1 //
3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
9 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.2 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 yi.zhou 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
20 //
21 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 yi.zhou 1.1 #include <iostream>
35
36 #include <net-snmp/net-snmp-config.h>
37 #include <net-snmp/net-snmp-includes.h>
|
38 kumpf 1.5 #include <Pegasus/Common/Mutex.h>
|
39 yi.zhou 1.1 #include "snmpDeliverTrap.h"
40
41 PEGASUS_NAMESPACE_BEGIN
42
|
43 kumpf 1.6 static const char _MSG_SESSION_OPEN_FAILED[] =
|
44 yi.zhou 1.1 "Snmp Indication Handler failed to open the SNMP session: ";
|
45 kumpf 1.6 static const char _MSG_SESSION_OPEN_FAILED_KEY[] =
46 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
47 "_MSG_SESSION_OPEN_FAILED";
|
48 yi.zhou 1.1
|
49 kumpf 1.6 static const char _MSG_GET_SESSION_POINT_FAILED[] =
|
50 yi.zhou 1.1 "Snmp Indication Handler failed to get the SNMP session pointer: ";
|
51 kumpf 1.6 static const char _MSG_GET_SESSION_POINTER_FAILED_KEY[] =
52 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
53 "_MSG_GET_SESSION_POINT_FAILED";
|
54 yi.zhou 1.1
|
55 kumpf 1.6 static const char _MSG_PDU_CREATE_FAILED[] =
|
56 yi.zhou 1.1 "Snmp Indication Handler failed to create the SNMP PDU.";
|
57 kumpf 1.6 static const char _MSG_PDU_CREATE_FAILED_KEY[] =
58 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
59 "_MSG_PDU_CREATE_FAILED";
|
60 yi.zhou 1.1
|
61 kumpf 1.6 static const char _MSG_VERSION_NOT_SUPPORTED[] =
|
62 yi.zhou 1.1 "SNMPv1 Trap and SNMPv2C Trap are the only supported SNMPVersion values.";
|
63 kumpf 1.6 static const char _MSG_VERSION_NOT_SUPPORTED_KEY[] =
64 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
65 "_MSG_VERSION_NOT_SUPPORTED";
|
66 yi.zhou 1.1
|
67 kumpf 1.6 static const char _MSG_SESSION_SEND_FAILED[] =
|
68 yi.zhou 1.1 "Snmp Indication Handler failed to send the trap: ";
|
69 kumpf 1.6 static const char _MSG_SESSION_SEND_FAILED_KEY[] =
70 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
71 "_MSG_SESSION_SEND_FAILED";
72
73 static const char _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED[] =
74 "Snmp Indication Handler failed to pack trap information into the "
75 "SNMP PDU: \"$0\".";
76 static const char _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED_KEY[] =
77 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
78 "_MSG_PACK_TRAP_INFO_INTO_PDU_FAILED";
|
79 yi.zhou 1.1
|
80 kumpf 1.6 static const char _MSG_ADD_SYSUPTIME_TO_PDU_FAILED[] =
|
81 yi.zhou 1.1 "Snmp Indication Handler failed to add sysUpTime to the SNMP PDU: \"$0\".";
|
82 kumpf 1.6 static const char _MSG_ADD_SYSUPTIME_TO_PDU_FAILED_KEY[] =
83 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
84 "_MSG_ADD_SYSUPTIME_TO_PDU_FAILED";
|
85 yi.zhou 1.1
|
86 kumpf 1.6 static const char _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED[] =
|
87 yi.zhou 1.1 "Snmp Indication Handler failed to add SNMP Trap to the SNMP PDU: \"$0\".";
|
88 kumpf 1.6 static const char _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED_KEY[] =
89 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
90 "_MSG_ADD_SNMP_TRAP_TO_PDU_FAILED";
91
92 static const char _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED[] =
93 "Snmp Indication Handler failed to pack a CIM Property into the "
94 "SNMP PDU: \"$0\".";
95 static const char _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED_KEY[] =
96 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
97 "_MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED";
|
98 yi.zhou 1.1
|
99 kumpf 1.6 static const char _MSG_READ_OBJID_FAILED[] =
|
100 yi.zhou 1.1 "Snmp Indication Handler failed to convert trapOid \"$0\" from a "
|
101 kumpf 1.6 "numeric form to a list of subidentifiers.";
102 static const char _MSG_READ_OBJID_FAILED_KEY[] =
103 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
104 "_MSG_READ_OBJID_FAILED";
|
105 yi.zhou 1.1
|
106 kumpf 1.6 static const char _MSG_PARSE_CIM_PROPERTY_OID_FAILED[] =
|
107 yi.zhou 1.1 "Snmp Indication Handler failed to convert a CIM property OID \"$0\" from "
|
108 kumpf 1.6 "a numeric form to a list of subidentifiers.";
109 static const char _MSG_PARSE_CIM_PROPERTY_OID_FAILED_KEY[] =
110 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
111 "__MSG_PARSE_CIM_PROPERTY_OID_FAILED";
|
112 yi.zhou 1.1
|
113 kumpf 1.6 static const char _MSG_READ_ENTOID_FAILED[] =
|
114 yi.zhou 1.1 "Snmp Indication Handler failed to convert SNMPV1 enterprise OID \"$0\" "
|
115 kumpf 1.6 "from a numeric form to a list of subidentifiers.";
116 static const char _MSG_READ_ENTOID_FAILED_KEY[] =
117 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
118 "_MSG_READ_ENTOID_FAILED";
|
119 yi.zhou 1.1
|
120 kumpf 1.6 static const char _MSG_UNSUPPORTED_SNMP_DATA_TYPE[] =
|
121 yi.zhou 1.1 "Type \"$0\" is an unsupported SNMP Data Type for the CIM property.";
|
122 kumpf 1.6 static const char _MSG_UNSUPPORTED_SNMP_DATA_TYPE_KEY[] =
123 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
124 "_MSG_UNSUPPORTED_SNMP_DATA_TYPE";
125
126 static const char _MSG_ADD_VAR_TO_PDU_FAILED[] =
127 "Snmp Indication Handler failed to add a CIM property \"$0\" to the "
128 "SNMP PDU: \"$1\".";
129 static const char _MSG_ADD_VAR_TO_PDU_FAILED_KEY[] =
130 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
131 "_MSG_ADD_VAR_TO_PDU_FAILED";
|
132 yi.zhou 1.1
133 class snmpDeliverTrap_netsnmp : public snmpDeliverTrap
134 {
135 public:
136
|
137 yi.zhou 1.3 void initialize();
138
139 void terminate();
140
|
141 yi.zhou 1.1 void deliverTrap(
142 const String& trapOid,
143 const String& securityName,
144 const String& targetHost,
145 const Uint16& targetHostFormat,
146 const String& otherTargetHostFormat,
147 const Uint32& portNumber,
148 const Uint16& snmpVersion,
149 const String& engineID,
150 const Array<String>& vbOids,
151 const Array<String>& vbTypes,
152 const Array<String>& vbValues);
153
154 private:
155
|
156 yi.zhou 1.3 // Mutex is needed before a session is created. Sessions created
157 // using the Single API do not interact with other SNMP sessions.
158 Mutex _sessionInitMutex;
159
|
160 yi.zhou 1.1 /**
161 Creates a SNMP session.
162
|
163 yi.zhou 1.7 @param targetHost the target system of a hostname or an IPv4
164 address or an IPv6 address to receive a trap
165 @param targetHostFormat the format of the targetHost
166 @param portNumber the port number to receive a trap
167 @param securityName the human readable community name
168 @param sessionHandle an opaque pointer of the SNMP session
169 @param sessionPtr the SNMP session pointer to its associated
170 struct snmp_session
|
171 yi.zhou 1.1 */
|
172 kumpf 1.6 void _createSession(
173 const String& targetHost,
|
174 yi.zhou 1.7 Uint16 targetHostFormat,
|
175 kumpf 1.6 Uint32 portNumber,
176 const String& securityName,
177 void*& sessionHandle,
178 struct snmp_session*& sessionPtr);
|
179 yi.zhou 1.1
180 /**
181 Creates a SNMP session.
182
183 @param sessionHandle an opaque pointer of the SNMP session
184 */
|
185 kumpf 1.6 void _destroySession(void* sessionHandle);
|
186 yi.zhou 1.1
187 /**
188 Creates a SNMP PDU.
189
190 @param snmpVersion the SNMP version
191 @param trapOid the trap OID
192 @param sessionPtr the SNMP session pointer
193 @param snmpPdu the SNMP PDU
194 */
|
195 kumpf 1.6 void _createPdu(
196 Uint16 snmpVersion,
197 const String& trapOid,
198 struct snmp_session*& sessionPtr,
199 struct snmp_pdu*& snmpPdu);
|
200 yi.zhou 1.1
201 /**
202 Pack the trap information into the PDU.
203
204 @param trapOid the trap OID
205 @param snmpPdu the SNMP PDU
206 */
|
207 kumpf 1.6 void _packTrapInfoIntoPdu(
208 const String& trapOid,
209 snmp_pdu* snmpPdu);
|
210 yi.zhou 1.1
211 /**
212 Pack CIM properties into PDU.
213
214 @param vbOids the array of CIM property OIDs
215 @param vbTypes the array of CIM property data types
216 @param vbValues the array of CIM property values
217 @param snmpPdu the SNMP PDU
218 */
|
219 kumpf 1.6 void _packOidsIntoPdu(
220 const Array<String>& vbOids,
221 const Array<String>& vbTypes,
222 const Array<String>& vbValues,
223 snmp_pdu* snmpPdu);
|
224 yi.zhou 1.1
|
225 kumpf 1.6 enum SNMPVersion
226 {
227 _SNMPv1_TRAP = 2,
228 _SNMPv2C_TRAP = 3,
229 _SNMPv2C_INFORM = 4,
230 _SNMPv3_TRAP = 5,
231 _SNMPv3_INFORM = 6
232 };
|
233 yi.zhou 1.7
234 /**
235 Values for the TargetHostFormat property of the
236 PG_IndicationHandlerSNMPMapper class.
237 */
238 enum TargetHostFormat
239 {
240 _OTHER = 1,
241 _HOST_NAME = 2,
242 _IPV4_ADDRESS = 3,
243 _IPV6_ADDRESS = 4
244 };
|
245 yi.zhou 1.1 };
246
247 PEGASUS_NAMESPACE_END
|