1 mike 1.2 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.10 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.2 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 kumpf 1.10 // 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 mike 1.2 // 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 kumpf 1.10 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 mike 1.2 // 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 kumpf 1.10 // 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 mike 1.2 // 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 //==============================================================================
23 //
24 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
25 //
|
26 mday 1.11.12.1 // Modified By: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
|
27 mike 1.2 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
|
30 kumpf 1.3 #include <Pegasus/Common/System.h>
|
31 mday 1.11.12.1 #include <Pegasus/Common/ArrayInternal.h>
|
32 kumpf 1.8 #include <Pegasus/Common/Destroyer.h>
|
33 mday 1.11.12.1 #include <Pegasus/Common/InternalException.h>
|
34 mike 1.2 #include "snmpDeliverTrap_emanate.h"
|
35 mday 1.11.12.1
|
36 mday 1.11.12.2 // l10n
37 #include <Pegasus/Common/MessageLoader.h>
38
|
39 mday 1.11.12.1 // EMANATE specific declarations and entry points - MUST be in begining
40 // and outside NAMESPACE.
41
42 // master agent needs these two declarations for communication with sub-agent.
43 // Following two declarations must be in the CODE.
44
45 #include <prnt_lib.h> // MUST be at the end in include list.
|
46 mike 1.2
|
47 kumpf 1.3 static char *sr_filename = __FILE__;
48
49 IPCFunctionP IPCfp; /* IPC functions pointer */
50
|
51 mday 1.11.12.1 // This code would normally be generated by Emanate from defined MIB objects.
52 // Since we do not have MIB objects defined, just defined here to load
53 // subagent as library. OidList[] provides objects for entry point to master agent.
|
54 kumpf 1.3
55 // The objects internal to the agent
56 ObjectInfo OidList[] =
57 {
58 { { 0, NULL },
59 #ifndef LIGHT
60 NULL,
61 #endif /* LIGHT */
62 0, 0, 0, 0,
63 NULL, NULL }
64 };
65
|
66 mday 1.11.12.1 // This code would normally be generated by Emanate in k_* routine from defined MIB objects.
67 // Since we do not have MIB objects defined, just define here to pass compile and
68 // enable entry point for master agent to start communication with library.
|
69 kumpf 1.3
70 // Called by the master agent during initialization */
71 int k_initialize()
72 {
73 return 1;
74 }
|
75 kumpf 1.9
|
76 mday 1.11.12.1 // END EMANATE specific declarations.
77
|
78 kumpf 1.9 PEGASUS_NAMESPACE_BEGIN
79
80 PEGASUS_USING_STD;
|
81 kumpf 1.3
82 snmpDeliverTrap_emanate::snmpDeliverTrap_emanate()
83 {
84
85 }
86
87 snmpDeliverTrap_emanate::~snmpDeliverTrap_emanate()
88 {
89
90 }
91
|
92 mday 1.11.12.1
93 // initialize sub-agent
94
95 // This also defines the communication protocol to be used between master
96 // and sub-agent.
97
|
98 kumpf 1.3 void snmpDeliverTrap_emanate::initialize()
99 {
100 #ifndef SR_UDS_IPC
101 InitIPCArrayTCP(&IPCfp);
102 #else /* SR_UDS_IPC */
103 InitIPCArrayUDS(&IPCfp);
104 #endif /* SR_UDS_IPC */
105
106 if(InitSubagent() == -1)
107 {
|
108 mday 1.11.12.2
109 // l10n
110
111 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
112 // _MSG_INITSUBAGENT_FAILED);
113
114 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
115 MessageLoaderParms(_MSG_INITSUBAGENT_FAILED_KEY,
116 _MSG_INITSUBAGENT_FAILED,
117 _MSG_INITSUBAGENT));
118
|
119 kumpf 1.3 }
120 }
121
|
122 mday 1.11.12.2
|
123 kumpf 1.3 void snmpDeliverTrap_emanate::deliverTrap(
|
124 mday 1.11.12.1 const String& trapOid,
125 const String& securityName,
126 const String& targetHost,
127 const Uint16& targetHostFormat,
128 const String& otherTargetHostFormat,
129 const Uint32& portNumber,
130 const Uint16& snmpVersion,
131 const String& engineID,
132 Array<String>& vbOids,
133 Array<String>& vbTypes,
134 Array<String>& vbValues)
|
135 mike 1.2 {
|
136 mday 1.11.12.1 VarBind *vbhead = NULL;
|
137 kumpf 1.3 VarBind *vb = NULL;
|
138 mday 1.11.12.1 VarBind *vblast = NULL;
|
139 kumpf 1.3
140 OID *object = NULL;
141
|
142 mday 1.11.12.1 // Initialize with Master agent
143
144 initialize();
145
146 // Translate a string into an OID
147 OID *sendtrapOid = MakeOIDFromDot(trapOid.getCString());
148
149 if (sendtrapOid == NULL)
150 {
|
151 mday 1.11.12.2
152 // l10n
153
154 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
155 // _MSG_INVALID_TRAPOID);
156
157 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
158 MessageLoaderParms(_MSG_INVALID_KEY,
159 _MSG_INVALID_TRAPOID,
160 _MSG_TRAPOID));
|
161 mday 1.11.12.1 }
162
163 // Destination : convert targetHost into Transport
|
164 kumpf 1.5
|
165 mday 1.11.12.1 CString trap_dest = targetHost.getCString();
|
166 kumpf 1.5
167 TransportInfo global_ti;
168 global_ti.type = SR_IP_TRANSPORT;
169
|
170 mday 1.11.12.3 switch (targetHostFormat)
171 {
172 case _HOST_NAME:
173 {
174 char * ipAddr = _getIPAddress(trap_dest);
175
176 if (ipAddr == NULL)
177 {
178
179 // l10n
180
181 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
182 // _MSG_DESTINATION_NOT_FOUND);
183
184 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
185 MessageLoaderParms(_MSG_DESTINATION_NOT_FOUND_KEY,
186 _MSG_DESTINATION_NOT_FOUND));
187
188 }
189 global_ti.t_ipAddr = inet_addr(trap_dest);
190 break;
191 mday 1.11.12.3 }
192 case _IPV4_ADDRESS:
193 {
194 global_ti.t_ipAddr = inet_addr(trap_dest);
195 break;
196 }
197 default:
198 {
199
200 // l10n
201
202 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
203 // _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED);
204
205 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_NOT_SUPPORTED,
206 MessageLoaderParms(_MSG_TARGETHOSTFORMAT_NOT_SUPPORTED_KEY,
207 _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED,
208 _MSG_HOSTNAME,
209 _MSG_IPV4,
210 _MSG_TARGETHOSTFORMAT));
211
212 mday 1.11.12.3 break;
213 }
214 }
215
216 global_ti.t_ipPort = htons((unsigned short)portNumber);
217
218 // Community Name, default is public
219 CString _community;
220 if (securityName.size() == 0)
221 {
222 String community;
223 community.assign("public");
224 _community = community.getCString();
225 }
226 else
227 {
228 _community = securityName.getCString();
229 }
230
231 OctetString* community_name = MakeOctetStringFromText(_community);
232
233 mday 1.11.12.3 if (community_name == NULL)
234 {
235
236 // l10n
237
238 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
239 // _MSG_INVALID_SECURITY_NAME);
240
241 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
242 MessageLoaderParms(_MSG_INVALID_SECURITY_NAME_KEY,
243 _MSG_INVALID_SECURITY_NAME,
244 _MSG_SECURITY_NAME));
245
246 }
|
247 mday 1.11.12.2
|
248 mday 1.11.12.1 switch (targetHostFormat)
249 {
250 case _HOST_NAME:
251 {
252 char * ipAddr = _getIPAddress(trap_dest);
253
254 if (ipAddr == NULL)
255 {
|
256 mday 1.11.12.2
257 // l10n
258
259 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
260 // _MSG_DESTINATION_NOT_FOUND);
261
262 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_FAILED,
263 MessageLoaderParms(_MSG_DESTINATION_NOT_FOUND_KEY,
264 _MSG_DESTINATION_NOT_FOUND));
265
|
266 mday 1.11.12.1 }
267 global_ti.t_ipAddr = inet_addr(trap_dest);
268 break;
269 }
270 case _IPV4_ADDRESS:
271 {
272 global_ti.t_ipAddr = inet_addr(trap_dest);
273 break;
274 }
275 default:
276 {
|
277 mday 1.11.12.2
278 // l10n
279
280 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
281 // _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED);
282
283 throw PEGASUS_CIM_EXCEPTION_L (CIM_ERR_NOT_SUPPORTED,
284 MessageLoaderParms(_MSG_TARGETHOSTFORMAT_NOT_SUPPORTED_KEY,
285 _MSG_TARGETHOSTFORMAT_NOT_SUPPORTED,
286 _MSG_HOSTNAME,
287 _MSG_IPV4,
288 _MSG_TARGETHOSTFORMAT));
289
|
290 mday 1.11.12.1 break;
291 }
292 }
293
294 global_ti.t_ipPort = htons((unsigned short)portNumber);
295
296 // Community Name, default is public
297 CString _community;
298 if (securityName.size() == 0)
299 {
300 String community;
301 community.assign("public");
302 _community = community.getCString();
303 }
304 else
305 {
306 _community = securityName.getCString();
307 }
308
309 OctetString* community_name = MakeOctetStringFromText(_community);
310
311 mday 1.11.12.1 if (community_name == NULL)
312 {
|
313 kumpf 1.5
|
314 mday 1.11.12.2 // l10n
315
316 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
317 // _MSG_INVALID_SECURITY_NAME);
318
319 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
320 MessageLoaderParms(_MSG_INVALID_SECURITY_NAME_KEY,
321 _MSG_INVALID_SECURITY_NAME,
322 _MSG_SECURITY_NAME));
323
324 }
|
325 kumpf 1.3 // getting IP address of the host
|
326 mday 1.11.12.1
327 CString hostname = System::getHostName().getCString();
328 char* IP_string = _getIPAddress(hostname);
329
|
330 kumpf 1.3 // formatting agent(host) address into OctetString format
|
331 mday 1.11.12.1
|
332 kumpf 1.3 OctetString* agent_addr;
333
334 SR_INT32 s1, s2, s3, s4;
335 SR_UINT32 ipaddr;
336
337 // pull out each of the 4 octet values from IP address
|
338 mday 1.11.12.1
|
339 kumpf 1.3 sscanf(IP_string,"%d.%d.%d.%d", &s1, &s2, &s3, &s4);
340
|
341 mday 1.11.12.1 // validate the values for s1, s2, s3, and s4 to make sure values are
|
342 kumpf 1.3 // between 0 and 255
|
343 mday 1.11.12.1 if (!_isValidOctet(s1) || !_isValidOctet(s2) ||
344 !_isValidOctet(s3) || !_isValidOctet(s4))
345 {
|
346 mday 1.11.12.2
347 // l10n
348
349 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
350 // _MSG_INVALID_OCTET_VALUE);
351
352 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
353 MessageLoaderParms(_MSG_INVALID_OCTET_VALUE_KEY,
354 _MSG_INVALID_OCTET_VALUE));
|
355 mday 1.11.12.1 }
|
356 mday 1.11.12.3
|
357 kumpf 1.3 // create an empty 4 length OctetString
|
358 mday 1.11.12.1
|
359 kumpf 1.3 agent_addr = MakeOctetString(NULL,4);
|
360 mday 1.11.12.1
361 if (agent_addr == NULL)
362 {
|
363 mday 1.11.12.2
364 // l10n
365
366 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
367 // _MSG_CREATE_OCTET_FAILED);
368
369 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
370 MessageLoaderParms(_MSG_CREATE_OCTET_FAILED_KEY,
371 _MSG_CREATE_OCTET_FAILED,
372 _MSG_OCTETSTRING));
373
|
374 mday 1.11.12.1 }
|
375 kumpf 1.3
376 // fill in values for OctetString
|
377 mday 1.11.12.1
|
378 kumpf 1.3 agent_addr->octet_ptr[0] = (unsigned char)s1;
379 agent_addr->octet_ptr[1] = (unsigned char)s2;
380 agent_addr->octet_ptr[2] = (unsigned char)s3;
381 agent_addr->octet_ptr[3] = (unsigned char)s4;
382
|
383 kumpf 1.4 // specTrap from trapOid.
|
384 mday 1.11.12.1
|
385 kumpf 1.5 SR_INT32 genTrap = 0;
386 SR_INT32 specTrap = 0;
|
387 kumpf 1.3
|
388 kumpf 1.5 OID* enterpriseOid ;
389
390 Array<String> standard_traps;
391
392 standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
393 standard_traps.append(String("1.3.6.1.6.3.1.1.5.2"));
394 standard_traps.append(String("1.3.6.1.6.3.1.1.5.3"));
395 standard_traps.append(String("1.3.6.1.6.3.1.1.5.4"));
396 standard_traps.append(String("1.3.6.1.6.3.1.1.5.5"));
397 standard_traps.append(String("1.3.6.1.6.3.1.1.5.6"));
398
399 Array<String> oids;
400 String tmpoid = trapOid;
401
402 while(tmpoid.find(".") != PEG_NOT_FOUND)
403 {
404 oids.append(tmpoid.subString(0, tmpoid.find(".")));
405 tmpoid = tmpoid.subString(tmpoid.find(".") + 1);
406 }
|
407 mday 1.11.12.1
|
408 kumpf 1.5 oids.append(tmpoid);
409
410 String ent;
411 if (Contains(standard_traps, trapOid))
412 {
|
413 mday 1.11.12.1 //
414 // if the trapOid is one of the standard traps,
415 // then the SNMPV1 enterprise parameter must be set
416 // to the value of the trapOid, the generic-trap
417 // parameter must be set to one of (0 - 5), and the
418 // specific-trap parameter must be set to 0
419 //
|
420 kumpf 1.5
421 enterpriseOid = sendtrapOid;
|
422 mday 1.11.12.1
423 // the generic trap is last sub-identifier of the
424 // trapOid minus 1
425 genTrap = atoi(oids[oids.size() - 1].getCString()) - 1;
426 specTrap = 0;
|
427 kumpf 1.5 }
428 else
429 {
|
430 mday 1.11.12.1 //
431 // if the trapOid is not one of the standard traps:
432 // then 1) the generic-trap parameter must be set to 6,
433 // 2) if the next-to-last sub-identifier of the
434 // trapOid is zero, then the SNMPV1 enterprise
435 // parameter is the trapOid with the last 2
436 // sub-identifiers removed, otherwise, the
437 // SNMPV1 enterprise parameter is the trapOid
438 // with the last sub-identifier removed;
439 // 3) the SNMPv1 specific-trap parameter is the last
440 // sub-identifier of the trapOid;
441 //
442
|
443 kumpf 1.5 genTrap = 6;
|
444 mike 1.2
|
445 kumpf 1.11 specTrap = atoi(oids[oids.size()-1].getCString());
|
446 mike 1.2
|
447 mday 1.11.12.1 ent = oids[0];
448 for (Uint8 i = 1; i < oids.size()-2; i++)
449 {
450 ent = ent + "." + oids[i];
451 }
452
453 if (oids[oids.size()-2] != "0")
454 {
455 ent = ent + "." + oids[oids.size()-2];
456 }
457
458 enterpriseOid = MakeOIDFromDot(ent.getCString());
459
460 if (enterpriseOid == NULL)
461 {
|
462 mday 1.11.12.2
463 // l10n
464
465 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
466 // _MSG_INVALID_ENTERPRISEOID);
467
468 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
469 MessageLoaderParms(_MSG_INVALID_ENTERPRISEOID_KEY,
470 _MSG_INVALID_ENTERPRISEOID,
471 _MSG_ENTERPRISEOID));
|
472 mday 1.11.12.1 }
|
473 kumpf 1.5 }
474
|
475 mday 1.11.12.1 // creates VarBind
|
476 kumpf 1.4 for(Uint32 i = 0; i < vbOids.size(); i++)
|
477 mike 1.2 {
|
478 mday 1.11.12.1 CString _vbOid = vbOids[i].getCString();
479 CString _vbValue = vbValues[i].getCString();
480
481 if ((object = MakeOIDFromDot(_vbOid)) == NULL)
|
482 kumpf 1.3 {
|
483 mday 1.11.12.2
484 // l10n
485
486 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
487 // _MSG_INVALID_PROPERTYOID);
488
489 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
490 MessageLoaderParms(_MSG_INVALID_PROPERTYOID_KEY,
491 _MSG_INVALID_PROPERTYOID,
492 _MSG_OID,
493 _MSG_CIM));
|
494 kumpf 1.3 }
495
|
496 mday 1.11.12.1 if (String::equalNoCase(vbTypes[i], "OctetString"))
497 {
498 OctetString* value;
499
500 value = CloneOctetString(MakeOctetStringFromText(_vbValue));
501 if (value == NULL)
502 {
|
503 mday 1.11.12.2
504 // l10n
505
506 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
507 // _MSG_INVALID_PROPERTYVALUE);
508
509 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
510 MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
511 _MSG_INVALID_PROPERTYVALUE,
512 _MSG_CIM));
|
513 mday 1.11.12.1 }
514
515 if ((vb = MakeVarBindWithValue(object,
516 (OID *) NULL,
517 OCTET_PRIM_TYPE,
518 value)) == NULL)
|
519 kumpf 1.4 {
|
520 mday 1.11.12.2
521 // l10n
522
523 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
524 // _MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE);
525
526 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
527 MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_KEY,
528 _MSG_MAKE_VARBIND_FAILED,
529 _MSG_VARBIND,
530 _MSG_OCTET_PRIM_TYPE));
|
531 kumpf 1.4 }
|
532 mday 1.11.12.1 }
533 else if (String::equalNoCase(vbTypes[i], "OID"))
534 {
535 void* value = MakeOIDFromDot(_vbValue);
536 if (value == NULL)
|
537 kumpf 1.3 {
|
538 mday 1.11.12.2 // l10n
539
540 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
541 // _MSG_INVALID_PROPERTYVALUE);
542
543 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
544 MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
545 _MSG_INVALID_PROPERTYVALUE,
546 _MSG_CIM));
547
|
548 kumpf 1.3 }
|
549 mday 1.11.12.1
550 if ((vb = MakeVarBindWithValue(object,
551 (OID *) NULL,
552 OBJECT_ID_TYPE,
553 value)) == NULL)
554 {
|
555 mday 1.11.12.2
556 // l10n
557
558 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
559 // _MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE);
560
561 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
562 MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_KEY,
563 _MSG_MAKE_VARBIND_FAILED,
564 _MSG_VARBIND,
565 _MSG_OBJECT_ID_TYPE));
|
566 mday 1.11.12.1 }
567 }
568 else
569 {
570 int vbvalue = atoi(_vbValue);
|
571 kumpf 1.6 void* value = &vbvalue;
|
572 kumpf 1.3
|
573 mday 1.11.12.1 if (value == NULL)
|
574 kumpf 1.4 {
|
575 mday 1.11.12.3
|
576 mday 1.11.12.2 // l10n
577
578 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
579 // _MSG_INVALID_PROPERTYVALUE);
580
581 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
582 MessageLoaderParms(_MSG_INVALID_PROPERTYVALUE_KEY,
583 _MSG_INVALID_PROPERTYVALUE,
584 _MSG_CIM));
|
585 kumpf 1.4 }
|
586 mday 1.11.12.1
587 if ((vb = MakeVarBindWithValue(object,
588 (OID *) NULL,
589 INTEGER_TYPE,
590 value)) == NULL)
|
591 mike 1.2 {
|
592 mday 1.11.12.3
|
593 mday 1.11.12.2 // l10n
594
595 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED,
596 // _MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE);
597
598 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
599 MessageLoaderParms(_MSG_MAKE_VARBIND_FAILED_KEY,
600 _MSG_MAKE_VARBIND_FAILED,
601 _MSG_VARBIND,
602 _MSG_INTEGER_TYPE));
|
603 mike 1.2 }
|
604 mday 1.11.12.1 }
605
|
606 kumpf 1.4 if (i == 0)
607 {
|
608 mday 1.11.12.1 vbhead = vb;
609 vblast = vb;
|
610 kumpf 1.4 }
611 else
612 {
|
613 mday 1.11.12.1 vblast->next_var = vb;
614 vblast = vblast->next_var;
|
615 kumpf 1.4 }
616
|
617 kumpf 1.3 }
|
618 kumpf 1.5
|
619 mday 1.11.12.1 vblast->next_var = NULL;
|
620 kumpf 1.3
|
621 mday 1.11.12.1 // Now send the trap
622 switch (snmpVersion)
|
623 kumpf 1.3 {
|
624 mday 1.11.12.1 case _SNMPv1_TRAP:
625 {
626 SendNotificationToDestSMIv1Params(
627 1, // notifyType - TRAP
|
628 kumpf 1.5 genTrap, // genTrap
629 specTrap, // specTrap
|
630 kumpf 1.3 enterpriseOid, // enterprise
631 agent_addr, // agent_addr
|
632 mday 1.11.12.1 vbhead, // vb
|
633 kumpf 1.3 NULL, // contextName
634 1, // retryCount
635 1, // timeout
|
636 kumpf 1.5 community_name, // securityName,
|
637 kumpf 1.3 SR_SECURITY_LEVEL_NOAUTH, // securityLevel
638 SR_SECURITY_MODEL_V1, // securityModel
639 &global_ti, // Transport Info
|
640 mday 1.11.12.1 0); // cfg_chk
641 break;
642 }
643 case _SNMPv2C_TRAP:
644 {
645 SendNotificationToDestSMIv2Params(
646 (SR_INT32)SNMPv2_TRAP_TYPE, // notifyType - NOTIFICATION
|
647 kumpf 1.3 sendtrapOid, // snmpTrapOID
648 agent_addr, // agent_addr
|
649 mday 1.11.12.1 vbhead, // vb
|
650 kumpf 1.3 NULL, // contextName
651 1, // retryCount
652 100, // timeout
|
653 kumpf 1.5 community_name, // securityName or community
|
654 kumpf 1.3 SR_SECURITY_LEVEL_NOAUTH, // securityLevel
|
655 mday 1.11.12.1 SR_SECURITY_MODEL_V2C, // securityModel
|
656 kumpf 1.3 &global_ti, // TransportInfo
657 0); // cfg_chk
|
658 mday 1.11.12.1 break;
659 }
660 default:
661 {
|
662 mday 1.11.12.2 // l10n
663
664 // throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED,
665 // _MSG_VERSION_NOT_SUPPORTED);
666
667 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,
668 MessageLoaderParms(_MSG_VERSION_NOT_SUPPORTED_KEY,
669 _MSG_VERSION_NOT_SUPPORTED,
670 _MSG_SNMPv1,
671 _MSG_SNMPv2C,
672 _MSG_SNMPVersion));
673
674 break;
|
675 mday 1.11.12.1 }
|
676 kumpf 1.3 }
|
677 mday 1.11.12.1
678 // Free OID built by calls MakeOIDFromDot()
679 FreeOID(sendtrapOid);
680 FreeOID(enterpriseOid);
681 FreeOID(object);
682
683 // Free the data structures allocated and built by calls
684 // MakeOctetString() and MakeOctetStringFrom Text()
685 FreeOctetString(community_name);
686 FreeOctetString(agent_addr);
687
688 // Free the VarBind data structures allocated and built
689 // by calls MakeVarBindWithValue()
690 FreeVarBindList(vbhead);
691 FreeVarBindList(vb);
692 FreeVarBindList(vblast);
693 }
694
695 // get the IP address of a host
696 char * snmpDeliverTrap_emanate::_getIPAddress(const CString& hostName)
697 {
698 mday 1.11.12.1 struct hostent *targetHostInfo;
699 struct in_addr in;
700
|
701 mday 1.11.12.2 #ifdef PEGASUS_OS_SOLARIS
702 #define HOSTENT_BUFF_SIZE 8192
703 char buf[HOSTENT_BUFF_SIZE];
704 struct hostent h_result;
705 int h_errorp;
706 targetHostInfo=gethostbyname_r(hostName, &h_result, buff,
707 HOSTENT_BUFF_SIZE, &h_errorp);
708 #else
|
709 mday 1.11.12.1 targetHostInfo = gethostbyname(hostName);
|
710 mday 1.11.12.2 #endif
|
711 mday 1.11.12.1
712 if (targetHostInfo == NULL)
|
713 kumpf 1.3 {
|
714 mday 1.11.12.1 return(NULL);
|
715 mike 1.2 }
|
716 mday 1.11.12.1
717 char ** networkAddr;
718 networkAddr = targetHostInfo->h_addr_list;
719 (void)memcpy(&in.s_addr, *networkAddr, sizeof(in.s_addr));
720 char * ipAddr = inet_ntoa(in);
721 return(ipAddr);
722 }
|
723 kumpf 1.6
|
724 mday 1.11.12.1 // check the value of each part of an IP address which should be
725 // between 0 and 255
726 Boolean snmpDeliverTrap_emanate::_isValidOctet(const Uint32& octetValue)
727 {
728 if (octetValue > 0 && octetValue < 255)
729 {
730 return true;
731 }
732 else
733 {
734 return false;
735 }
|
736 mike 1.2 }
737
738 PEGASUS_NAMESPACE_END
|