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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2