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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2