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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2