1 karl 1.3 //%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.3 // 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 <Pegasus/Common/Packer.h>
35 #include <Pegasus/Common/Tracer.h>
36 #include "snmpDeliverTrap_netsnmp.h"
37
38 PEGASUS_NAMESPACE_BEGIN
39
|
40 yi.zhou 1.4 void snmpDeliverTrap_netsnmp::initialize()
41 {
|
42 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER, "snmpDeliverTrap_netsnmp::initialize");
|
43 yi.zhou 1.4
|
44 kumpf 1.10 // Defined default MIB modules (in net-snmp-config.h) do not need to be
|
45 yi.zhou 1.4 // loaded and loading them can cause some stderr;
46 // use environment variable MIBS to override the default MIB modules.
|
47 kumpf 1.10 // If there is no MIBS environment variable, add it in.
48 char* envVar;
|
49 yi.zhou 1.4 envVar = getenv("MIBS");
50
51 if (envVar == NULL)
52 {
53 putenv("MIBS=");
54 }
55
56 // Initialize the mib reader
57 netsnmp_set_mib_directory("");
58 init_mib();
|
59 kumpf 1.10
|
60 yi.zhou 1.4 // Initializes the SNMP library
61 init_snmp("snmpIndicationHandler");
62
63 // windows32 specific initialization (is a NOOP on unix)
64 SOCK_STARTUP;
65
|
66 kumpf 1.10 PEG_METHOD_EXIT();
|
67 yi.zhou 1.4 }
68
69 void snmpDeliverTrap_netsnmp::terminate()
70 {
|
71 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER, "snmpDeliverTrap_netsnmp::terminate");
|
72 yi.zhou 1.4
|
73 yi.zhou 1.13 // Shuts down the application, and appropriate clean up
74 snmp_shutdown("snmpIndicationHandler");
75
|
76 yi.zhou 1.4 SOCK_CLEANUP;
77
|
78 kumpf 1.10 PEG_METHOD_EXIT();
|
79 yi.zhou 1.4 }
80
|
81 yi.zhou 1.1 void snmpDeliverTrap_netsnmp::deliverTrap(
|
82 kumpf 1.10 const String& trapOid,
83 const String& securityName,
84 const String& targetHost,
85 const Uint16& targetHostFormat,
86 const String& otherTargetHostFormat,
87 const Uint32& portNumber,
88 const Uint16& snmpVersion,
89 const String& engineID,
90 const Array<String>& vbOids,
91 const Array<String>& vbTypes,
92 const Array<String>& vbValues)
|
93 yi.zhou 1.1 {
94
|
95 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER, "snmpDeliverTrap_netsnmp::deliverTrap");
|
96 yi.zhou 1.1
|
97 kumpf 1.10 void* sessionHandle;
98 struct snmp_session* sessionPtr;
|
99 yi.zhou 1.1
|
100 kumpf 1.10 struct snmp_pdu* snmpPdu;
|
101 yi.zhou 1.1
102 // Creates a SNMP session
|
103 yi.zhou 1.16 _createSession(targetHost, targetHostFormat, portNumber, securityName,
|
104 yi.zhou 1.1 sessionHandle, sessionPtr);
105
106 try
107 {
108 _createPdu(snmpVersion, trapOid, sessionPtr, snmpPdu);
109 }
110 catch (...)
111 {
112 _destroySession(sessionHandle);
113
|
114 kumpf 1.10 PEG_METHOD_EXIT();
|
115 yi.zhou 1.1 throw;
116 }
117
118 // Pack OIDs into the PDU
119 try
120 {
121 _packOidsIntoPdu(vbOids, vbTypes, vbValues, snmpPdu);
122 }
123 catch (Exception& e)
124 {
|
125 marek 1.15 PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2, e.getMessage());
|
126 kumpf 1.10
|
127 yi.zhou 1.1 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
128 Logger::WARNING,
129 _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED_KEY,
|
130 kumpf 1.10 _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED,
131 e.getMessage());
|
132 yi.zhou 1.1 }
133 catch (...)
134 {
|
135 marek 1.14 PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
|
136 kumpf 1.10 "Snmp Indication Handler failed to pack a CIM "
137 "Property into the SNMP PDU: Unknown exception.");
|
138 yi.zhou 1.1 }
139
140 // Send the trap to the destination
141 if (snmp_sess_send(sessionHandle, snmpPdu) == 0)
142 {
143 Sint32 libErr, sysErr;
|
144 kumpf 1.10 char* errStr;
|
145 yi.zhou 1.1
146 // snmp_sess_send failed
147 // get library, system errno
148 snmp_sess_error(sessionHandle, &libErr, &sysErr, &errStr);
149
150 String exceptionStr = _MSG_SESSION_SEND_FAILED;
|
151 kumpf 1.10 exceptionStr.append(errStr);
|
152 yi.zhou 1.1
153 free(errStr);
154
155 _destroySession(sessionHandle);
156
|
157 kumpf 1.10 PEG_METHOD_EXIT();
|
158 yi.zhou 1.1
|
159 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
160 MessageLoaderParms(_MSG_SESSION_SEND_FAILED_KEY, exceptionStr));
|
161 yi.zhou 1.1 }
162
163 _destroySession(sessionHandle);
164
|
165 kumpf 1.10 PEG_METHOD_EXIT();
|
166 yi.zhou 1.1 }
167
168 // Creates a SNMP session
169 void snmpDeliverTrap_netsnmp::_createSession(
|
170 kumpf 1.10 const String& targetHost,
|
171 yi.zhou 1.16 Uint16 targetHostFormat,
|
172 yi.zhou 1.1 Uint32 portNumber,
|
173 kumpf 1.10 const String& securityName,
174 void*& sessionHandle,
175 snmp_session*& sessionPtr)
|
176 yi.zhou 1.1 {
|
177 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
178 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_createSession");
179
180 Sint32 libErr, sysErr;
|
181 kumpf 1.10 char* errStr;
|
182 yi.zhou 1.1 String exceptionStr;
|
183 kumpf 1.10
|
184 yi.zhou 1.4 struct snmp_session snmpSession;
|
185 yi.zhou 1.1
|
186 yi.zhou 1.2 {
|
187 kumpf 1.10 AutoMutex autoMut(_sessionInitMutex);
188 snmp_sess_init(&snmpSession);
|
189 yi.zhou 1.1
|
190 kumpf 1.10 CString targetHostCStr = targetHost.getCString();
|
191 yi.zhou 1.1
|
192 kumpf 1.10 // peername has format: targetHost:portNumber
193 snmpSession.peername =
194 (char*)malloc((size_t)(strlen(targetHostCStr) + 1 + 32));
|
195 yi.zhou 1.16
196 if (targetHostFormat == _IPV6_ADDRESS)
197 {
198 sprintf(snmpSession.peername, "udp6:[%s]:%u",
199 (const char*)targetHostCStr,
200 portNumber);
201 }
202 else
203 {
204 sprintf(snmpSession.peername, "%s:%u",
205 (const char*)targetHostCStr,
206 portNumber);
207 }
|
208 yi.zhou 1.4
|
209 kumpf 1.10 sessionHandle = snmp_sess_open(&snmpSession);
|
210 yi.zhou 1.4 }
|
211 yi.zhou 1.1
212 if (sessionHandle == NULL)
213 {
214 exceptionStr = _MSG_SESSION_OPEN_FAILED;
215
216 // Get library, system errno
|
217 yi.zhou 1.5 snmp_error(&snmpSession, &libErr, &sysErr, &errStr);
|
218 yi.zhou 1.1
219 exceptionStr.append(errStr);
220
221 free(errStr);
222
|
223 kumpf 1.10 PEG_METHOD_EXIT();
|
224 yi.zhou 1.1
|
225 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
226 MessageLoaderParms(_MSG_SESSION_OPEN_FAILED_KEY, exceptionStr));
|
227 yi.zhou 1.1 }
228
229 try
230 {
231 // get the snmp_session pointer
232 sessionPtr = snmp_sess_session(sessionHandle);
233 if (sessionPtr == NULL)
234 {
235 exceptionStr = _MSG_GET_SESSION_POINT_FAILED;
236
237 // Get library, system errno
238 snmp_sess_error(&snmpSession, &libErr, &sysErr, &errStr);
239
240 exceptionStr.append(errStr);
241
242 free(errStr);
243
|
244 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
245 _MSG_GET_SESSION_POINTER_FAILED_KEY,
246 exceptionStr));
|
247 yi.zhou 1.1 }
248
249 // Community Name, default is public
250 String communityName;
251 if (securityName.size() == 0)
252 {
253 communityName.assign("public");
254 }
255 else
256 {
257 communityName = securityName;
258 }
259
|
260 yi.zhou 1.7 free(snmpSession.peername);
|
261 yi.zhou 1.1
|
262 yi.zhou 1.7 free(sessionPtr->community);
|
263 yi.zhou 1.1
264 CString communityNameCStr = communityName.getCString();
265 size_t communityNameLen = strlen(communityNameCStr);
266
267 sessionPtr->community = (u_char*)malloc(communityNameLen);
268
|
269 kumpf 1.10 memcpy(sessionPtr->community, (const char*)communityNameCStr,
|
270 yi.zhou 1.1 communityNameLen);
271 sessionPtr->community_len = communityNameLen;
272 }
273 catch (...)
274 {
275 _destroySession(sessionHandle);
276
|
277 kumpf 1.10 PEG_METHOD_EXIT();
|
278 yi.zhou 1.1 throw;
279 }
280
|
281 kumpf 1.10 PEG_METHOD_EXIT();
|
282 yi.zhou 1.1 }
283
284 // Creates a SNMP session
285 void snmpDeliverTrap_netsnmp::_destroySession(
|
286 kumpf 1.10 void* sessionHandle)
|
287 yi.zhou 1.1 {
|
288 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
289 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_destroySession");
290
291 snmp_sess_close(sessionHandle);
292
|
293 kumpf 1.10 PEG_METHOD_EXIT();
|
294 yi.zhou 1.1 }
295
|
296 kumpf 1.10 // Creates a SNMP TRAP PDU
|
297 yi.zhou 1.1 void snmpDeliverTrap_netsnmp::_createPdu(
298 Uint16 snmpVersion,
299 const String& trapOid,
|
300 kumpf 1.10 snmp_session*& sessionPtr,
301 snmp_pdu*& snmpPdu)
|
302 yi.zhou 1.1 {
|
303 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER, "snmpDeliverTrap_netsnmp::_createPdu");
|
304 yi.zhou 1.1
305 oid _SYSTEM_UP_TIME_OID [] = {1,3,6,1,2,1,1,3,0};
306 oid _SNMPTRAP_OID [] = {1,3,6,1,6,3,1,1,4,1,0};
307
|
308 kumpf 1.10 in_addr_t* pduInAddr;
|
309 yi.zhou 1.1
310 switch (snmpVersion)
311 {
312 case _SNMPv1_TRAP:
313 {
314
315 sessionPtr->version = SNMP_VERSION_1;
316
317 // Create the PDU
|
318 kumpf 1.10 snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP);
319
|
320 yi.zhou 1.1 // Failed to create pdu
321 if (!snmpPdu)
322 {
|
323 kumpf 1.10 PEG_METHOD_EXIT();
324 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
325 MessageLoaderParms(
326 _MSG_PDU_CREATE_FAILED_KEY,
327 _MSG_PDU_CREATE_FAILED));
|
328 yi.zhou 1.1 }
329
330 // Make sure that the v1 trap PDU includes the local IP address
331 pduInAddr = (in_addr_t*) snmpPdu->agent_addr;
332 *pduInAddr = get_myaddr();
333
334 // get system up time
335 snmpPdu->time = get_uptime();
336
337 // Pack trap information into the PDU
338 try
339 {
340 _packTrapInfoIntoPdu(trapOid, snmpPdu);
341 }
342 catch (CIMException& e)
343 {
|
344 marek 1.15 PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
|
345 kumpf 1.10 e.getMessage());
346 Logger::put_l(
347 Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
348 _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED_KEY,
349 _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED,
350 e.getMessage());
|
351 yi.zhou 1.1 }
352
353 break;
354 }
355 case _SNMPv2C_TRAP:
356 {
357 sessionPtr->version = SNMP_VERSION_2c;
358
359 // Create the PDU
|
360 kumpf 1.10 snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP2);
361
|
362 yi.zhou 1.1 // Failed to create pdu
363 if (!snmpPdu)
364 {
|
365 kumpf 1.10 PEG_METHOD_EXIT();
|
366 yi.zhou 1.1
|
367 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
368 MessageLoaderParms(
369 _MSG_PDU_CREATE_FAILED_KEY,
370 _MSG_PDU_CREATE_FAILED));
|
371 yi.zhou 1.1 }
372
373 // Add sysUpTime to the PDU
374 char sysUpTime[32];
375 sprintf(sysUpTime, "%ld", get_uptime());
|
376 kumpf 1.10
|
377 yi.zhou 1.1 Sint32 retCode;
|
378 kumpf 1.10 retCode = snmp_add_var(
379 snmpPdu,
380 _SYSTEM_UP_TIME_OID,
381 OID_LENGTH(_SYSTEM_UP_TIME_OID),
382 't',
383 sysUpTime);
|
384 yi.zhou 1.1
385 // Failed to add sysUpTime to the pdu
386 if (retCode != 0)
387 {
388 String errMsg = snmp_api_errstring(retCode);
389
|
390 marek 1.15 PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
|
391 kumpf 1.10 "Failed to add sysUpTime to pdu: " + errMsg);
392 Logger::put_l(
393 Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
394 _MSG_ADD_SYSUPTIME_TO_PDU_FAILED_KEY,
395 _MSG_ADD_SYSUPTIME_TO_PDU_FAILED,
396 errMsg);
|
397 yi.zhou 1.1 }
398
399 // Add snmp trap to the PDU
|
400 kumpf 1.10 retCode = snmp_add_var(
401 snmpPdu,
402 _SNMPTRAP_OID,
403 OID_LENGTH(_SNMPTRAP_OID),
404 'o',
405 trapOid.getCString());
|
406 yi.zhou 1.1
407 // Failed to add snmp trap to the pdu
408 if (retCode != 0)
409 {
410 String errMsg = snmp_api_errstring(retCode);
411
|
412 marek 1.15 PEG_TRACE_STRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
|
413 kumpf 1.10 "Failed to add snmp trap to pdu: " + errMsg);
414 Logger::put_l(
415 Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
416 _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED_KEY,
417 _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED,
418 errMsg);
|
419 yi.zhou 1.1 }
420
421 break;
422 }
423 default:
424 {
|
425 kumpf 1.10 PEG_METHOD_EXIT();
|
426 yi.zhou 1.1
427 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,
|
428 kumpf 1.10 MessageLoaderParms(
429 _MSG_VERSION_NOT_SUPPORTED_KEY,
430 _MSG_VERSION_NOT_SUPPORTED));
|
431 yi.zhou 1.1 }
432 }
433
|
434 kumpf 1.10 PEG_METHOD_EXIT();
|
435 yi.zhou 1.1 }
436
437
438 // Pack trap information into the PDU
439 void snmpDeliverTrap_netsnmp::_packTrapInfoIntoPdu(
|
440 kumpf 1.10 const String& trapOid,
441 snmp_pdu* snmpPdu)
|
442 yi.zhou 1.1 {
|
443 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
444 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_packTrapInfoIntoPdu");
445
446 oid enterpriseOid[MAX_OID_LEN];
|
447 kumpf 1.10 size_t enterpriseOidLength;
|
448 yi.zhou 1.1
449 Array<String> standard_traps;
450
451 standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
452 standard_traps.append(String("1.3.6.1.6.3.1.1.5.2"));
453 standard_traps.append(String("1.3.6.1.6.3.1.1.5.3"));
454 standard_traps.append(String("1.3.6.1.6.3.1.1.5.4"));
455 standard_traps.append(String("1.3.6.1.6.3.1.1.5.5"));
456 standard_traps.append(String("1.3.6.1.6.3.1.1.5.6"));
457
|
458 kumpf 1.10 Array<const char*> oidSubIdentifiers;
|
459 yi.zhou 1.1
460 CString trapOidCStr = trapOid.getCString();
461
|
462 kumpf 1.10 char* trapOidCopy = strdup(trapOidCStr);
463 char* numericEntOid = (char*) malloc(strlen(trapOidCStr));
|
464 yi.zhou 1.9
465 try
466 {
|
467 yi.zhou 1.1
|
468 a.dunfey 1.12 #if !defined(PEGASUS_OS_TYPE_WINDOWS) && !defined(PEGASUS_OS_ZOS)
|
469 kumpf 1.10 char* last;
470 for (const char* p = strtok_r(trapOidCopy, ".", &last); p;
|
471 yi.zhou 1.9 p=strtok_r(NULL, ".", &last))
|
472 yi.zhou 1.1 #else
|
473 yi.zhou 1.9 for (const char* p = strtok(trapOidCopy, "."); p; p=strtok(NULL, "."))
|
474 yi.zhou 1.1 #endif
|
475 yi.zhou 1.9 {
476 oidSubIdentifiers.append(p);
477 }
|
478 yi.zhou 1.1
|
479 yi.zhou 1.9 long genTrap = 0;
480 long specTrap = 0;
|
481 yi.zhou 1.1
|
482 yi.zhou 1.9 enterpriseOidLength = MAX_OID_LEN;
|
483 yi.zhou 1.1
|
484 yi.zhou 1.9 if (Contains(standard_traps, trapOid))
485 {
486 //
487 // if the trapOid is one of the standard traps,
488 // then the SNMPV1 enterprise parameter must be set
489 // to the value of the trapOid, the generic-trap
490 // parameter must be set to one of (0 - 5), and the
491 // specific-trap parameter must be set to 0
492 //
493
494 // Convert trapOid from numeric form to a list of subidentifiers
|
495 kumpf 1.10 if (read_objid((const char*)trapOidCStr, enterpriseOid,
|
496 yi.zhou 1.9 &enterpriseOidLength) == 0)
497 {
|
498 kumpf 1.10 // Failed to parse trapOid
|
499 yi.zhou 1.9
|
500 kumpf 1.10 PEG_METHOD_EXIT();
501 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
502 yi.zhou 1.9 MessageLoaderParms(_MSG_READ_OBJID_FAILED_KEY,
503 _MSG_READ_OBJID_FAILED,
504 trapOid));
505 }
506
507 // the generic trap is last sub-identifier of the
508 // trapOid minus 1
|
509 kumpf 1.10 snmpPdu->trap_type =
|
510 yi.zhou 1.9 atoi(oidSubIdentifiers[oidSubIdentifiers.size() - 1]) - 1;
511 snmpPdu->specific_type = 0;
|
512 yi.zhou 1.1 }
|
513 yi.zhou 1.9 else
|
514 yi.zhou 1.1 {
|
515 yi.zhou 1.9 //
516 // if the trapOid is not one of the standard traps:
517 // then 1) the generic-trap parameter must be set to 6,
518 // 2) if the next-to-last sub-identifier of the
519 // trapOid is zero, then the SNMPV1 enterprise
520 // parameter is the trapOid with the last 2
521 // sub-identifiers removed, otherwise, the
522 // SNMPV1 enterprise parameter is the trapOid
523 // with the last sub-identifier removed;
524 // 3) the SNMPv1 specific-trap parameter is the last
525 // sub-identifier of the trapOid;
526 //
527
528 snmpPdu->trap_type = 6;
529
|
530 kumpf 1.10 snmpPdu->specific_type =
|
531 yi.zhou 1.9 atoi(oidSubIdentifiers[oidSubIdentifiers.size()-1]);
532
533 strcpy(numericEntOid, oidSubIdentifiers[0]);
534 for (Uint32 i = 1; i < oidSubIdentifiers.size()-2; i++)
535 {
536 strcat(numericEntOid, ".");
537 strcat(numericEntOid, oidSubIdentifiers[i]);
538 }
539
540 if (strcmp(oidSubIdentifiers[oidSubIdentifiers.size()-2], "0") != 0)
541 {
542 strcat(numericEntOid, ".");
|
543 kumpf 1.10 strcat(numericEntOid,
|
544 yi.zhou 1.9 oidSubIdentifiers[oidSubIdentifiers.size()-2]);
545 }
|
546 yi.zhou 1.1
|
547 kumpf 1.10 // Convert ent from numeric form to a list of subidentifiers
548 if (read_objid(numericEntOid, enterpriseOid,
|
549 yi.zhou 1.9 &enterpriseOidLength) == 0)
550 {
551 // Failed to parse numericEntOid
|
552 yi.zhou 1.1
|
553 kumpf 1.10 PEG_METHOD_EXIT();
|
554 yi.zhou 1.1
|
555 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
556 yi.zhou 1.9 MessageLoaderParms(_MSG_READ_ENTOID_FAILED_KEY,
557 _MSG_READ_ENTOID_FAILED,
558 String(numericEntOid)));
559 }
|
560 yi.zhou 1.1
561 }
562
|
563 yi.zhou 1.9 snmpPdu->enterprise = (oid*) malloc(enterpriseOidLength * sizeof(oid));
|
564 kumpf 1.10 memcpy(snmpPdu->enterprise, enterpriseOid,
565 enterpriseOidLength * sizeof(oid));
|
566 yi.zhou 1.9
567 snmpPdu->enterprise_length = enterpriseOidLength;
|
568 yi.zhou 1.1 }
|
569 yi.zhou 1.9 catch (...)
570 {
571 free(trapOidCopy);
572 free(numericEntOid);
|
573 yi.zhou 1.1
|
574 yi.zhou 1.9 PEG_METHOD_EXIT();
575 throw;
576 }
|
577 yi.zhou 1.1
578 free(trapOidCopy);
579 free(numericEntOid);
580
|
581 kumpf 1.10 PEG_METHOD_EXIT();
|
582 yi.zhou 1.1 }
583
584 // Pack oids into the PDU
585 void snmpDeliverTrap_netsnmp::_packOidsIntoPdu(
586 const Array<String>& vbOids,
587 const Array<String>& vbTypes,
588 const Array<String>& vbValues,
|
589 kumpf 1.10 snmp_pdu* snmpPdu)
|
590 yi.zhou 1.1 {
591
|
592 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
593 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_packOidsIntoPdu");
594
595 char dataType;
596 oid vbOid[MAX_OID_LEN];
597 size_t vbOidLength = MAX_OID_LEN;
598
599 for (Uint32 i=0; i < vbOids.size(); i++)
600 {
601 if (vbTypes[i] == "OctetString")
602 {
603 dataType = 's';
604 }
605 else if (vbTypes[i] == "Integer")
606 {
607 dataType = 'i';
|
608 kumpf 1.10 }
|
609 yi.zhou 1.1 else if (vbTypes[i] == "OID")
610 {
611 dataType = 'o';
612 }
613 else
614 {
|
615 kumpf 1.10 // Integer, OctetString, and OID are supported SNMP Data Types
|
616 yi.zhou 1.1 // for the CIM Property
617
|
618 kumpf 1.10 PEG_METHOD_EXIT();
|
619 yi.zhou 1.1
|
620 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
621 yi.zhou 1.1 MessageLoaderParms(_MSG_UNSUPPORTED_SNMP_DATA_TYPE_KEY,
622 _MSG_UNSUPPORTED_SNMP_DATA_TYPE,
623 vbTypes[i]));
624
625 }
626
|
627 kumpf 1.10 // Convert oid of a CIM property from numeric form to a list of
628 // subidentifiers
629 if (read_objid((const char*)vbOids[i].getCString(), vbOid,
|
630 yi.zhou 1.1 &vbOidLength) == 0)
631 {
632 // Failed to parse vbOids
633
|
634 kumpf 1.10 PEG_METHOD_EXIT();
|
635 yi.zhou 1.1
|
636 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
637 yi.zhou 1.1 MessageLoaderParms(_MSG_PARSE_CIM_PROPERTY_OID_FAILED_KEY,
638 _MSG_PARSE_CIM_PROPERTY_OID_FAILED,
639 vbOids[i]));
640 }
641
642 Sint32 retCode;
|
643 kumpf 1.10 retCode = snmp_add_var(snmpPdu, vbOid, vbOidLength, dataType,
|
644 yi.zhou 1.1 vbValues[i].getCString());
645
646 // Failed to add vbOid to the pdu
647 if (retCode != 0)
648 {
|
649 kumpf 1.10 PEG_METHOD_EXIT();
|
650 yi.zhou 1.1
|
651 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
652 yi.zhou 1.1 MessageLoaderParms(_MSG_ADD_VAR_TO_PDU_FAILED_KEY,
653 _MSG_ADD_VAR_TO_PDU_FAILED,
654 vbOids[i],
|
655 kumpf 1.10 String(snmp_api_errstring(retCode))));
|
656 yi.zhou 1.1
657 }
658 }
659
|
660 kumpf 1.10 PEG_METHOD_EXIT();
|
661 yi.zhou 1.1 }
662
663 PEGASUS_NAMESPACE_END
|