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