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 @param targetHost the target system of a hostname or an IPv4
164 address
165 to receive a trap
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 */
|
172 kumpf 1.6 void _createSession(
173 const String& targetHost,
174 Uint32 portNumber,
175 const String& securityName,
176 void*& sessionHandle,
177 struct snmp_session*& sessionPtr);
|
178 yi.zhou 1.1
179 /**
180 Creates a SNMP session.
181
182 @param sessionHandle an opaque pointer of the SNMP session
183 */
|
184 kumpf 1.6 void _destroySession(void* sessionHandle);
|
185 yi.zhou 1.1
186 /**
187 Creates a SNMP PDU.
188
189 @param snmpVersion the SNMP version
190 @param trapOid the trap OID
191 @param sessionPtr the SNMP session pointer
192 @param snmpPdu the SNMP PDU
193 */
|
194 kumpf 1.6 void _createPdu(
195 Uint16 snmpVersion,
196 const String& trapOid,
197 struct snmp_session*& sessionPtr,
198 struct snmp_pdu*& snmpPdu);
|
199 yi.zhou 1.1
200 /**
201 Pack the trap information into the PDU.
202
203 @param trapOid the trap OID
204 @param snmpPdu the SNMP PDU
205 */
|
206 kumpf 1.6 void _packTrapInfoIntoPdu(
207 const String& trapOid,
208 snmp_pdu* snmpPdu);
|
209 yi.zhou 1.1
210 /**
211 Pack CIM properties into PDU.
212
213 @param vbOids the array of CIM property OIDs
214 @param vbTypes the array of CIM property data types
215 @param vbValues the array of CIM property values
216 @param snmpPdu the SNMP PDU
217 */
|
218 kumpf 1.6 void _packOidsIntoPdu(
219 const Array<String>& vbOids,
220 const Array<String>& vbTypes,
221 const Array<String>& vbValues,
222 snmp_pdu* snmpPdu);
|
223 yi.zhou 1.1
|
224 kumpf 1.6 enum SNMPVersion
225 {
226 _SNMPv1_TRAP = 2,
227 _SNMPv2C_TRAP = 3,
228 _SNMPv2C_INFORM = 4,
229 _SNMPv3_TRAP = 5,
230 _SNMPv3_INFORM = 6
231 };
|
232 yi.zhou 1.1 };
233
234 PEGASUS_NAMESPACE_END
|