(file) Return to snmpDeliverTrap_netsnmp.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / snmpIndicationHandler

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2