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 // Author: Yi Zhou, Hewlett-Packard Company (yi.zhou@hp.com)
33 //
34 yi.zhou 1.1 // Modified By:
35 //
36 //%/////////////////////////////////////////////////////////////////////////////
37
38 #include <iostream>
39
40 #include <net-snmp/net-snmp-config.h>
41 #include <net-snmp/net-snmp-includes.h>
42 #include "snmpDeliverTrap.h"
43
44 PEGASUS_NAMESPACE_BEGIN
45
46 static const char _MSG_SESSION_OPEN_FAILED [] =
47 "Snmp Indication Handler failed to open the SNMP session: ";
48 static const char _MSG_SESSION_OPEN_FAILED_KEY [] =
49 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_SESSION_OPEN_FAILED";
50
51 static const char _MSG_GET_SESSION_POINT_FAILED [] =
52 "Snmp Indication Handler failed to get the SNMP session pointer: ";
53 static const char _MSG_GET_SESSION_POINTER_FAILED_KEY [] =
54 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_GET_SESSION_POINT_FAILED";
55 yi.zhou 1.1
56 static const char _MSG_PDU_CREATE_FAILED [] =
57 "Snmp Indication Handler failed to create the SNMP PDU.";
58 static const char _MSG_PDU_CREATE_FAILED_KEY [] =
59 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_PDU_CREATE_FAILED";
60
61 static const char _MSG_VERSION_NOT_SUPPORTED [] =
62 "SNMPv1 Trap and SNMPv2C Trap are the only supported SNMPVersion values.";
63 static const char _MSG_VERSION_NOT_SUPPORTED_KEY [] =
64 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_VERSION_NOT_SUPPORTED";
65
66 static const char _MSG_SESSION_SEND_FAILED [] =
67 "Snmp Indication Handler failed to send the trap: ";
68 static const char _MSG_SESSION_SEND_FAILED_KEY [] =
69 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_SESSION_SEND_FAILED";
70
71 static const char _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED [] =
72 "Snmp Indication Handler failed to pack trap information into the SNMP PDU: \"$0\".";
73 static const char _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED_KEY [] =
74 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_PACK_TRAP_INFO_INTO_PDU_FAILED";
75
76 yi.zhou 1.1 static const char _MSG_ADD_SYSUPTIME_TO_PDU_FAILED [] =
77 "Snmp Indication Handler failed to add sysUpTime to the SNMP PDU: \"$0\".";
78 static const char _MSG_ADD_SYSUPTIME_TO_PDU_FAILED_KEY [] =
79 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_ADD_SYSUPTIME_TO_PDU_FAILED";
80
81 static const char _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED [] =
82 "Snmp Indication Handler failed to add SNMP Trap to the SNMP PDU: \"$0\".";
83 static const char _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED_KEY [] =
84 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_ADD_SNMP_TRAP_TO_PDU_FAILED";
85
86 static const char _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED [] =
87 "Snmp Indication Handler failed to pack a CIM Property into the SNMP PDU: \"$0\".";
88 static const char _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED_KEY [] =
89 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED";
90
91 static const char _MSG_READ_OBJID_FAILED [] =
92 "Snmp Indication Handler failed to convert trapOid \"$0\" from a "
93 "numeric form to a list of subidentifiers.";
94 static const char _MSG_READ_OBJID_FAILED_KEY [] =
95 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_READ_OBJID_FAILED";
96
97 yi.zhou 1.1 static const char _MSG_PARSE_CIM_PROPERTY_OID_FAILED [] =
98 "Snmp Indication Handler failed to convert a CIM property OID \"$0\" from "
99 "a numeric form to a list of subidentifiers.";
100 static const char _MSG_PARSE_CIM_PROPERTY_OID_FAILED_KEY [] =
101 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp.__MSG_PARSE_CIM_PROPERTY_OID_FAILED";
102
103 static const char _MSG_READ_ENTOID_FAILED [] =
104 "Snmp Indication Handler failed to convert SNMPV1 enterprise OID \"$0\" "
105 "from a numeric form to a list of subidentifiers.";
106 static const char _MSG_READ_ENTOID_FAILED_KEY [] =
107 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_READ_ENTOID_FAILED";
108
109 static const char _MSG_UNSUPPORTED_SNMP_DATA_TYPE [] =
110 "Type \"$0\" is an unsupported SNMP Data Type for the CIM property.";
111 static const char _MSG_UNSUPPORTED_SNMP_DATA_TYPE_KEY [] =
112 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_UNSUPPORTED_SNMP_DATA_TYPE";
113
114 static const char _MSG_ADD_VAR_TO_PDU_FAILED [] =
115 "Snmp Indication Handler failed to add a CIM property \"$0\" to the SNMP PDU: \"$1\".";
116 static const char _MSG_ADD_VAR_TO_PDU_FAILED_KEY [] =
117 "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp._MSG_ADD_VAR_TO_PDU_FAILED";
118 yi.zhou 1.1
119 class snmpDeliverTrap_netsnmp : public snmpDeliverTrap
120 {
121 public:
122
|
123 yi.zhou 1.3 void initialize();
124
125 void terminate();
126
|
127 yi.zhou 1.1 void deliverTrap(
128 const String& trapOid,
129 const String& securityName,
130 const String& targetHost,
131 const Uint16& targetHostFormat,
132 const String& otherTargetHostFormat,
133 const Uint32& portNumber,
134 const Uint16& snmpVersion,
135 const String& engineID,
136 const Array<String>& vbOids,
137 const Array<String>& vbTypes,
138 const Array<String>& vbValues);
139
140 private:
141
|
142 yi.zhou 1.3 // Mutex is needed before a session is created. Sessions created
143 // using the Single API do not interact with other SNMP sessions.
144 Mutex _sessionInitMutex;
145
|
146 yi.zhou 1.1 /**
147 Creates a SNMP session.
148
149 @param targetHost the target system of a hostname or an IPv4
150 address
151 to receive a trap
152 @param portNumber the port number to receive a trap
153 @param securityName the human readable community name
154 @param sessionHandle an opaque pointer of the SNMP session
155 @param sessionPtr the SNMP session pointer to its associated
156 struct snmp_session
157
158 */
159
160 void _createSession(const String & targetHost,
161 Uint32 portNumber,
162 const String & securityName,
163 void *&sessionHandle,
164 struct snmp_session *&sessionPtr);
165
166 /**
167 yi.zhou 1.1 Creates a SNMP session.
168
169 @param sessionHandle an opaque pointer of the SNMP session
170 */
171 void _destroySession(void *sessionHandle);
172
173 /**
174 Creates a SNMP PDU.
175
176 @param snmpVersion the SNMP version
177 @param trapOid the trap OID
178 @param sessionPtr the SNMP session pointer
179 @param snmpPdu the SNMP PDU
180
181 */
182
183 void _createPdu(Uint16 snmpVersion,
184 const String& trapOid,
185 struct snmp_session *&sessionPtr,
186 struct snmp_pdu *& snmpPdu);
187
188 yi.zhou 1.1 /**
189 Pack the trap information into the PDU.
190
191 @param trapOid the trap OID
192 @param snmpPdu the SNMP PDU
193 */
194 void _packTrapInfoIntoPdu(const String & trapOid,
195 snmp_pdu * snmpPdu);
196
197 /**
198 Pack CIM properties into PDU.
199
200 @param vbOids the array of CIM property OIDs
201 @param vbTypes the array of CIM property data types
202 @param vbValues the array of CIM property values
203 @param snmpPdu the SNMP PDU
204 */
205 void _packOidsIntoPdu(const Array<String>& vbOids,
206 const Array<String>& vbTypes,
207 const Array<String>& vbValues,
208 snmp_pdu * snmpPdu);
209 yi.zhou 1.1
210 enum SNMPVersion {_SNMPv1_TRAP = 2, _SNMPv2C_TRAP = 3,
211 _SNMPv2C_INFORM = 4, _SNMPv3_TRAP = 5, _SNMPv3_INFORM = 6};
212
213 };
214
215 PEGASUS_NAMESPACE_END
|