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

  1 martin 1.9 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.10 //
  3 martin 1.9  // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.10 //
 10 martin 1.9  // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.10 //
 17 martin 1.9  // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.10 //
 20 martin 1.9  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.10 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.9  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.10 //
 28 martin 1.9  //////////////////////////////////////////////////////////////////////////
 29 yi.zhou 1.1  //
 30              //%/////////////////////////////////////////////////////////////////////////////
 31              
 32              #include <iostream>
 33              
 34              #include <net-snmp/net-snmp-config.h>
 35              #include <net-snmp/net-snmp-includes.h>
 36 yi.zhou 1.8  #include <net-snmp/config_api.h>
 37 kumpf   1.5  #include <Pegasus/Common/Mutex.h>
 38 yi.zhou 1.1  #include "snmpDeliverTrap.h"
 39              
 40              PEGASUS_NAMESPACE_BEGIN
 41              
 42 kumpf   1.11 static const char _MSG_SESSION_OPEN_FAILED[] =
 43                  "Snmp Indication Handler failed to open the SNMP session: ";
 44              static const char _MSG_SESSION_OPEN_FAILED_KEY[] =
 45 kumpf   1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 46                      "_MSG_SESSION_OPEN_FAILED";
 47 yi.zhou 1.1  
 48 kumpf   1.11 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 kumpf   1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 52                      "_MSG_GET_SESSION_POINT_FAILED";
 53 yi.zhou 1.1  
 54 kumpf   1.11 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 kumpf   1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 58                      "_MSG_PDU_CREATE_FAILED";
 59 yi.zhou 1.1  
 60 kumpf   1.11 static const char _MSG_VERSION_NOT_SUPPORTED[] =
 61 sahana.prabhakar 1.12     "SNMPv1 Trap, SNMPv2C Trap and SNMPV3 are the only supported SNMPVersion "
 62                                "values.";
 63 kumpf            1.11 static const char _MSG_VERSION_NOT_SUPPORTED_KEY[] =
 64 kumpf            1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 65                               "_MSG_VERSION_NOT_SUPPORTED";
 66 yi.zhou          1.1  
 67 kumpf            1.11 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 kumpf            1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 71                               "_MSG_SESSION_SEND_FAILED";
 72                       
 73 kumpf            1.11 static const char _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED[] =
 74 kumpf            1.6      "Snmp Indication Handler failed to pack trap information into the "
 75                               "SNMP PDU: \"$0\".";
 76 kumpf            1.11 static const char _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED_KEY[] =
 77 kumpf            1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 78                               "_MSG_PACK_TRAP_INFO_INTO_PDU_FAILED";
 79 yi.zhou          1.1  
 80 kumpf            1.11 static const char _MSG_ADD_SYSUPTIME_TO_PDU_FAILED[] =
 81 yi.zhou          1.1      "Snmp Indication Handler failed to add sysUpTime to the SNMP PDU: \"$0\".";
 82 kumpf            1.11 static const char _MSG_ADD_SYSUPTIME_TO_PDU_FAILED_KEY[] =
 83 kumpf            1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 84                               "_MSG_ADD_SYSUPTIME_TO_PDU_FAILED";
 85 yi.zhou          1.1  
 86 kumpf            1.11 static const char _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED[] =
 87 yi.zhou          1.1      "Snmp Indication Handler failed to add SNMP Trap to the SNMP PDU: \"$0\".";
 88 kumpf            1.11 static const char _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED_KEY[] =
 89 kumpf            1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 90                               "_MSG_ADD_SNMP_TRAP_TO_PDU_FAILED";
 91                       
 92 kumpf            1.11 static const char _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED[] =
 93 kumpf            1.6      "Snmp Indication Handler failed to pack a CIM Property into the "
 94                               "SNMP PDU: \"$0\".";
 95 kumpf            1.11 static const char _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED_KEY[] =
 96 kumpf            1.6      "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
 97                               "_MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED";
 98 yi.zhou          1.1  
 99 kumpf            1.6  static const char _MSG_READ_OBJID_FAILED[] =
100 yi.zhou          1.1      "Snmp Indication Handler failed to convert trapOid \"$0\" from a "
101 kumpf            1.6          "numeric form to a list of subidentifiers.";
102                       static const char _MSG_READ_OBJID_FAILED_KEY[] =
103                           "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
104                               "_MSG_READ_OBJID_FAILED";
105 yi.zhou          1.1  
106 kumpf            1.6  static const char _MSG_PARSE_CIM_PROPERTY_OID_FAILED[] =
107 yi.zhou          1.1      "Snmp Indication Handler failed to convert a CIM property OID \"$0\" from "
108 kumpf            1.6          "a numeric form to a list of subidentifiers.";
109                       static const char _MSG_PARSE_CIM_PROPERTY_OID_FAILED_KEY[] =
110                           "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
111                               "__MSG_PARSE_CIM_PROPERTY_OID_FAILED";
112 yi.zhou          1.1  
113 kumpf            1.6  static const char _MSG_READ_ENTOID_FAILED[] =
114 yi.zhou          1.1      "Snmp Indication Handler failed to convert SNMPV1 enterprise OID \"$0\" "
115 kumpf            1.6          "from a numeric form to a list of subidentifiers.";
116                       static const char _MSG_READ_ENTOID_FAILED_KEY[] =
117                           "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
118                               "_MSG_READ_ENTOID_FAILED";
119 yi.zhou          1.1  
120 kumpf            1.6  static const char _MSG_UNSUPPORTED_SNMP_DATA_TYPE[] =
121 yi.zhou          1.1      "Type \"$0\" is an unsupported SNMP Data Type for the CIM property.";
122 kumpf            1.6  static const char _MSG_UNSUPPORTED_SNMP_DATA_TYPE_KEY[] =
123                           "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
124                               "_MSG_UNSUPPORTED_SNMP_DATA_TYPE";
125                       
126                       static const char _MSG_ADD_VAR_TO_PDU_FAILED[] =
127                           "Snmp Indication Handler failed to add a CIM property \"$0\" to the "
128                               "SNMP PDU: \"$1\".";
129                       static const char _MSG_ADD_VAR_TO_PDU_FAILED_KEY[] =
130                           "Handler.snmpIndicationHandler.snmpDeliverTrap_netsnmp."
131                               "_MSG_ADD_VAR_TO_PDU_FAILED";
132 yi.zhou          1.1  
133                       class snmpDeliverTrap_netsnmp : public snmpDeliverTrap
134                       {
135                       public:
136                       
137 yi.zhou          1.3      void initialize();
138                       
139                           void terminate();
140                       
141 yi.zhou          1.1      void deliverTrap(
142                               const String& trapOid,
143 kumpf            1.11         const String& securityName,
144                               const String& targetHost,
145                               const Uint16& targetHostFormat,
146                               const String& otherTargetHostFormat,
147 yi.zhou          1.1          const Uint32& portNumber,
148 kumpf            1.11         const Uint16& snmpVersion,
149 yi.zhou          1.1          const String& engineID,
150 sahana.prabhakar 1.12         const Uint8& snmpSecLevel,
151                               const Uint8& snmpSecAuthProto,
152                               const Array<Uint8>& snmpSecAuthKey,
153                               const Uint8& snmpSecPrivProto,
154                               const Array<Uint8>& snmpSecPrivKey,
155 yi.zhou          1.1          const Array<String>& vbOids,
156                               const Array<String>& vbTypes,
157                               const Array<String>& vbValues);
158                       
159                       private:
160                       
161 kumpf            1.11     // Mutex is needed before a session is created. Sessions created
162 yi.zhou          1.3      // using the Single API do not interact with other SNMP sessions.
163                           Mutex _sessionInitMutex;
164                       
165 yi.zhou          1.1      /**
166                               Creates a SNMP session.
167 kumpf            1.11 
168                               @param targetHost       the target system of a hostname or an IPv4
169 yi.zhou          1.7                                  address or an IPv6 address to receive a trap
170                               @param targetHostFormat the format of the targetHost
171                               @param portNumber       the port number to receive a trap
172                               @param securityName     the human readable community name
173 sahana.prabhakar 1.12         @param snmpVersion      the snmp version
174                               @param engineID         the engine ID
175                               @param snmpSecLevel     the security level
176                                                       (authNoPriv,authPriv,noAuthNoPriv)
177                               @param snmpSecAuthProto MD5 or SHA
178                               @param snmpSecAuthKey   encoded authentication key
179                               @param snmpSecPrivProto AES or DES
180                               @param snmpSecPrivKey   encoded privacy key
181 yi.zhou          1.7          @param sessionHandle    an opaque pointer of the SNMP session
182 kumpf            1.11         @param sessionPtr       the SNMP session pointer to its associated
183 yi.zhou          1.7                                  struct snmp_session
184 yi.zhou          1.1      */
185 kumpf            1.6      void _createSession(
186                               const String& targetHost,
187 yi.zhou          1.7          Uint16 targetHostFormat,
188 kumpf            1.6          Uint32 portNumber,
189                               const String& securityName,
190 sahana.prabhakar 1.12         Uint16 snmpVersion,
191                               const String& engineID,
192                               const Uint8& snmpSecLevel,
193                               const Uint8& snmpSecAuthProto,
194                               const Array<Uint8>& snmpSecAuthKey,
195                               const Uint8& snmpSecPrivProto,
196                               const Array<Uint8>& snmpSecPrivKey,
197 kumpf            1.6          void*& sessionHandle,
198                               struct snmp_session*& sessionPtr);
199 yi.zhou          1.1  
200                           /**
201 sahana.prabhakar 1.12         Add the community string to the snmp session for V1 and V2C
202                       
203                               @param sessionPtr    the SNMP session pointer to its associated
204                                                    struct snmp_session
205                               @param securityName     the human readable community name
206                           */
207                           void _addCommunity(
208                               struct snmp_session*& sessionPtr,
209                               const String& securityName);
210                       
211                           /**
212 yi.zhou          1.1          Creates a SNMP session.
213 kumpf            1.11 
214 yi.zhou          1.1          @param sessionHandle  an opaque pointer of the SNMP session
215                           */
216 kumpf            1.6      void _destroySession(void* sessionHandle);
217 yi.zhou          1.1  
218                           /**
219                               Creates a SNMP PDU.
220                       
221                               @param snmpVersion  the SNMP version
222                               @param trapOid      the trap OID
223                               @param sessionPtr   the SNMP session pointer
224                               @param snmpPdu      the SNMP PDU
225                           */
226 kumpf            1.6      void _createPdu(
227                               Uint16 snmpVersion,
228                               const String& trapOid,
229                               struct snmp_session*& sessionPtr,
230                               struct snmp_pdu*& snmpPdu);
231 yi.zhou          1.1  
232                           /**
233                               Pack the trap information into the PDU.
234                       
235                               @param trapOid  the trap OID
236                               @param snmpPdu  the SNMP PDU
237                           */
238 kumpf            1.6      void _packTrapInfoIntoPdu(
239                               const String& trapOid,
240                               snmp_pdu* snmpPdu);
241 yi.zhou          1.1  
242                           /**
243                               Pack CIM properties into PDU.
244                       
245                               @param vbOids    the array of CIM property OIDs
246                               @param vbTypes   the array of CIM property data types
247                               @param vbValues  the array of CIM property values
248                               @param snmpPdu   the SNMP PDU
249                           */
250 kumpf            1.6      void _packOidsIntoPdu(
251                               const Array<String>& vbOids,
252                               const Array<String>& vbTypes,
253                               const Array<String>& vbValues,
254                               snmp_pdu* snmpPdu);
255 yi.zhou          1.1  
256 kumpf            1.6      enum SNMPVersion
257                           {
258                               _SNMPv1_TRAP = 2,
259                               _SNMPv2C_TRAP = 3,
260                               _SNMPv2C_INFORM = 4,
261                               _SNMPv3_TRAP = 5,
262                               _SNMPv3_INFORM = 6
263                           };
264 yi.zhou          1.7  
265                           /**
266 kumpf            1.11         Values for the TargetHostFormat property of the
267 yi.zhou          1.7          PG_IndicationHandlerSNMPMapper class.
268                           */
269                           enum TargetHostFormat
270                           {
271                               _OTHER = 1,
272                               _HOST_NAME = 2,
273                               _IPV4_ADDRESS = 3,
274                               _IPV6_ADDRESS = 4
275                           };
276 yi.zhou          1.1  };
277                       
278                       PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2