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

  1 mike  1.2 //%/////////////////////////////////////////////////////////////////////////////
  2           //
  3           // Copyright (c) 2000, 2001 BMC Software, Hewlett Packard, IBM, The Open Group,
  4           // Tivoli Systems
  5           //
  6           // Permission is hereby granted, free of charge, to any person obtaining a copy
  7           // of this software and associated documentation files (the "Software"), to 
  8           // deal in the Software without restriction, including without limitation the 
  9           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 
 10           // sell copies of the Software, and to permit persons to whom the Software is
 11           // furnished to do so, subject to the following conditions:
 12           // 
 13           // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN 
 14           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 15           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 16           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
 17           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
 18           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
 19           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 20           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 21           //
 22 mike  1.2 //==============================================================================
 23           //
 24           // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
 25           //
 26           // Modified By:
 27           //
 28           //%/////////////////////////////////////////////////////////////////////////////
 29           
 30           #include <Pegasus/Common/Config.h>
 31 kumpf 1.3 #include <Pegasus/Common/System.h>
 32 mike  1.2 #include <fcntl.h>
 33           #include <unistd.h>
 34 kumpf 1.3 #include <ctype.h>
 35 mike  1.2 #include <sys/stat.h>
 36           #include "snmpDeliverTrap_emanate.h"
 37           
 38           PEGASUS_NAMESPACE_BEGIN
 39           
 40           PEGASUS_USING_STD;
 41           
 42 kumpf 1.3 static char *sr_filename = __FILE__;
 43           
 44           IPCFunctionP IPCfp;  /* IPC functions pointer  */
 45           
 46           // This code should be generated by Emanate 
 47           // Since we do not have MIB objects defined,
 48           // just defined here to load subagent as library
 49           
 50           // The objects internal to the agent 
 51           ObjectInfo OidList[] = 
 52           {
 53           { { 0, NULL },
 54           #ifndef LIGHT
 55               NULL,
 56           #endif /* LIGHT */
 57               0, 0, 0, 0,
 58               NULL, NULL }
 59           };
 60           
 61           // This code should be generated by Emanate in k_* routine
 62           // Since we do not have MIB objects defined,
 63 kumpf 1.3 // just defined here to pass compile 
 64           
 65           // Called by the master agent during initialization */
 66           int k_initialize()
 67           {
 68              return 1;
 69           }
 70           
 71           snmpDeliverTrap_emanate::snmpDeliverTrap_emanate()
 72           {
 73           
 74           }
 75           
 76           snmpDeliverTrap_emanate::~snmpDeliverTrap_emanate()
 77           {
 78           
 79           }
 80           
 81           void snmpDeliverTrap_emanate::initialize()
 82           {
 83           #ifndef SR_UDS_IPC
 84 kumpf 1.3     InitIPCArrayTCP(&IPCfp);
 85           #else /* SR_UDS_IPC */
 86               InitIPCArrayUDS(&IPCfp);
 87           #endif /* SR_UDS_IPC */
 88           
 89               if(InitSubagent() == -1) 
 90               {
 91           	cout << "InitSubagent Failed to initialize" << endl;
 92           	exit(1);
 93               }
 94           }
 95           
 96           void snmpDeliverTrap_emanate::deliverTrap(
 97               const String& trapOid,
 98               const String& community,
 99 mike  1.2     const String& destination,
100               const String& trapType,
101               Array<String>& vbOids,
102               Array<String>& vbTypes,
103               Array<String>& vbValues)
104           {
105 kumpf 1.3     initialize();
106 mike  1.2 
107 kumpf 1.3     void*   newValue;
108               char*   entV2Trap;
109               int	    vb_link_flag = 0;
110           
111               VarBind *vb = NULL;
112               VarBind *vb2 = NULL;
113               
114               OID	    *object = NULL;
115           
116               // getting IP address of the host
117               char* hostname = System::getHostName().allocateCString();
118               char **p;
119               struct hostent *hp;
120               struct in_addr in;
121               hp=gethostbyname(hostname);
122               p = hp->h_addr_list;
123               (void)memcpy(&in.s_addr, *p, sizeof(in.s_addr));
124               char* IP_string = inet_ntoa(in);
125               
126               // converting destination into Transport
127               TransportInfo   global_ti;
128 kumpf 1.3     global_ti.type = SR_IP_TRANSPORT;
129               // address to which to send trap
130               global_ti.t_ipAddr = inet_addr(destination.allocateCString());
131               // port to which to send trap
132               global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort());  
133           
134               // formatting agent(host) address into OctetString format
135               OctetString* agent_addr;
136           
137               SR_INT32 s1, s2, s3, s4;
138               SR_UINT32 ipaddr;
139           
140               // pull out each of the 4 octet values from IP address
141               sscanf(IP_string,"%d.%d.%d.%d", &s1, &s2, &s3, &s4);
142            
143               // Probably should perform some checks on values for
144               // s1, s2, s3, and s4 here to make sure values are
145               // between 0 and 255
146            
147               // create an empty 4 length OctetString
148               agent_addr = MakeOctetString(NULL,4);
149 kumpf 1.3  
150               // fill in values for OctetString
151               agent_addr->octet_ptr[0] = (unsigned char)s1;
152               agent_addr->octet_ptr[1] = (unsigned char)s2;
153               agent_addr->octet_ptr[2] = (unsigned char)s3;
154               agent_addr->octet_ptr[3] = (unsigned char)s4;
155           
156               // ATTN : Write code to get enterprise, genTrap and specTrap
157               // from trapOid. 
158           
159               // << 03-12-2002 : NU (HP)
160           
161               String enterprise;
162               
163               OID* enterpriseOid = MakeOIDFromDot(enterprise.allocateCString());
164               
165               // getting trap data for do_trap()
166               entV2Trap = trapOid.allocateCString();
167 mike  1.2 
168 kumpf 1.3     // getting trapOid
169               OID *sendtrapOid = MakeOIDFromDot(trapOid.allocateCString());
170 mike  1.2 
171 kumpf 1.3     for(Uint8 i = 0; i < vbOids.size(); i++)
172 mike  1.2     {
173 kumpf 1.3 	if ((object = MakeOIDFromDot(vbOids[i].allocateCString())) == NULL)
174                   {
175                       cout << "Invalid OID received: " << vbOids[i] << endl;
176                       return;
177                   } 
178           
179                   if (strcmp(vbTypes[i].allocateCString(),"OctetString") == 0)
180                   {
181                       newValue = MakeOctetStringFromText(vbValues[i].allocateCString());
182                       if ((vb = MakeVarBindWithValue(object, 
183           		(OID *) NULL, 
184           		OCTET_PRIM_TYPE, 
185           		newValue)) == NULL)
186                       {
187                           cout << "Invalid OctetString value: " << vbValues[i] << endl;
188                           return;
189                       }
190                   }
191 mike  1.2         else
192                   {
193 kumpf 1.3             newValue = MakeOctetString(
194           		(unsigned char *) vbValues[i].allocateCString(),
195           		strlen(vbValues[i].allocateCString()));
196           
197                       if ((vb = MakeVarBindWithValue(object, 
198           		(OID *) NULL, 
199           		INTEGER_TYPE, 
200           		newValue)) == NULL)
201 mike  1.2             {
202 kumpf 1.3                 cout << "Invalid Integer Value: " << vbValues[i] << endl;
203                           return;
204 mike  1.2             }
205                   }
206 kumpf 1.3          
207           	if (!vb_link_flag)
208           	{
209           	    vb_link_flag = 1;
210           	    vb2 = vb;
211           	    FreeOID(object);
212           	}
213           	else
214           	{
215           	    vb2->next_var = vb;
216           	    vb2 = vb;
217           	    FreeOID(object);
218           	}
219               }
220               
221               vb_link_flag = 0;
222               vb2->next_var = NULL;
223               vb->next_var = NULL;
224           
225               // Now sending the trap
226               if (trapType == String("SNMPGeneric"))
227 kumpf 1.3     {
228           	do_trap(6, 4, vb2, enterpriseOid, entV2Trap);
229                   FreeVarBindList(vb);
230                   FreeVarBindList(vb2);
231               }
232               else if (trapType == String("SNMPv1"))
233               {
234                   SendNotificationToDestSMIv1Params(
235                       1,					// notifyType
236                       6,					// genTrap
237                       1,					// specTrap
238                       enterpriseOid,			// enterprise
239                       agent_addr,				// agent_addr
240                       vb2,				// vb
241                       NULL,				// contextName
242                       1,					// retryCount
243                       1,					// timeout
244                       MakeOctetStringFromText(community.allocateCString()),	// securityName,
245                       SR_SECURITY_LEVEL_NOAUTH,		// securityLevel
246                       SR_SECURITY_MODEL_V1,		// securityModel
247                       &global_ti,				// Transport Info
248 kumpf 1.3             0);					// cfg_chk
249           
250                   FreeVarBindList(vb);
251                   FreeVarBindList(vb2);
252               }
253               else if (trapType == String("SNMPv2"))
254               {
255                   SendNotificationToDestSMIv2Params(
256                       1,					// notifyType
257                       sendtrapOid,			// snmpTrapOID
258                       agent_addr,				// agent_addr
259                       vb2,				// vb
260                       NULL,				// contextName
261                       1,					// retryCount
262                       100,				// timeout
263                       MakeOctetStringFromText(community.allocateCString()),	// securityName or community
264                       SR_SECURITY_LEVEL_NOAUTH,		// securityLevel
265                       SR_SECURITY_MODEL_V1,		// securityModel
266                       &global_ti,				// TransportInfo
267                       0);					// cfg_chk
268                   FreeVarBindList(vb);
269 kumpf 1.3         FreeVarBindList(vb2);
270               }
271               else
272               {
273                   cout << "Trap type not supported : " << trapType << endl;
274                   exit(2);
275 mike  1.2     }
276           }
277           
278           PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2