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 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER,
126 Logger::WARNING,
127 _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED_KEY,
|
128 kumpf 1.10 _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED,
129 e.getMessage());
|
130 yi.zhou 1.1 }
131 catch (...)
132 {
|
133 marek 1.14 PEG_TRACE_CSTRING(TRC_DISCARDED_DATA, Tracer::LEVEL2,
|
134 kumpf 1.10 "Snmp Indication Handler failed to pack a CIM "
135 "Property into the SNMP PDU: Unknown exception.");
|
136 yi.zhou 1.1 }
137
138 // Send the trap to the destination
139 if (snmp_sess_send(sessionHandle, snmpPdu) == 0)
140 {
141 Sint32 libErr, sysErr;
|
142 kumpf 1.10 char* errStr;
|
143 yi.zhou 1.1
144 // snmp_sess_send failed
145 // get library, system errno
146 snmp_sess_error(sessionHandle, &libErr, &sysErr, &errStr);
147
148 String exceptionStr = _MSG_SESSION_SEND_FAILED;
|
149 kumpf 1.10 exceptionStr.append(errStr);
|
150 yi.zhou 1.1
151 free(errStr);
152
|
153 yi.zhou 1.17.4.1 snmp_free_pdu(snmpPdu);
154
|
155 yi.zhou 1.1 _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 yi.zhou 1.17.4.1 free(snmpSession.peername);
224
|
225 kumpf 1.10 PEG_METHOD_EXIT();
|
226 yi.zhou 1.1
|
227 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
228 MessageLoaderParms(_MSG_SESSION_OPEN_FAILED_KEY, exceptionStr));
|
229 yi.zhou 1.1 }
230
231 try
232 {
233 // get the snmp_session pointer
234 sessionPtr = snmp_sess_session(sessionHandle);
235 if (sessionPtr == NULL)
236 {
237 exceptionStr = _MSG_GET_SESSION_POINT_FAILED;
238
239 // Get library, system errno
240 snmp_sess_error(&snmpSession, &libErr, &sysErr, &errStr);
241
242 exceptionStr.append(errStr);
243
244 free(errStr);
245
|
246 yi.zhou 1.17.4.1 free(snmpSession.peername);
247
|
248 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
249 _MSG_GET_SESSION_POINTER_FAILED_KEY,
250 exceptionStr));
|
251 yi.zhou 1.1 }
252
253 // Community Name, default is public
254 String communityName;
255 if (securityName.size() == 0)
256 {
257 communityName.assign("public");
258 }
259 else
260 {
261 communityName = securityName;
262 }
263
|
264 yi.zhou 1.7 free(snmpSession.peername);
|
265 yi.zhou 1.1
|
266 yi.zhou 1.7 free(sessionPtr->community);
|
267 yi.zhou 1.1
268 CString communityNameCStr = communityName.getCString();
269 size_t communityNameLen = strlen(communityNameCStr);
270
271 sessionPtr->community = (u_char*)malloc(communityNameLen);
272
|
273 kumpf 1.10 memcpy(sessionPtr->community, (const char*)communityNameCStr,
|
274 yi.zhou 1.1 communityNameLen);
275 sessionPtr->community_len = communityNameLen;
276 }
277 catch (...)
278 {
279 _destroySession(sessionHandle);
280
|
281 kumpf 1.10 PEG_METHOD_EXIT();
|
282 yi.zhou 1.1 throw;
283 }
284
|
285 kumpf 1.10 PEG_METHOD_EXIT();
|
286 yi.zhou 1.1 }
287
288 // Creates a SNMP session
289 void snmpDeliverTrap_netsnmp::_destroySession(
|
290 kumpf 1.10 void* sessionHandle)
|
291 yi.zhou 1.1 {
|
292 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
293 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_destroySession");
294
295 snmp_sess_close(sessionHandle);
296
|
297 kumpf 1.10 PEG_METHOD_EXIT();
|
298 yi.zhou 1.1 }
299
|
300 kumpf 1.10 // Creates a SNMP TRAP PDU
|
301 yi.zhou 1.1 void snmpDeliverTrap_netsnmp::_createPdu(
302 Uint16 snmpVersion,
303 const String& trapOid,
|
304 kumpf 1.10 snmp_session*& sessionPtr,
305 snmp_pdu*& snmpPdu)
|
306 yi.zhou 1.1 {
|
307 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER, "snmpDeliverTrap_netsnmp::_createPdu");
|
308 yi.zhou 1.1
309 oid _SYSTEM_UP_TIME_OID [] = {1,3,6,1,2,1,1,3,0};
310 oid _SNMPTRAP_OID [] = {1,3,6,1,6,3,1,1,4,1,0};
311
|
312 kumpf 1.10 in_addr_t* pduInAddr;
|
313 yi.zhou 1.1
314 switch (snmpVersion)
315 {
316 case _SNMPv1_TRAP:
317 {
318
319 sessionPtr->version = SNMP_VERSION_1;
320
321 // Create the PDU
|
322 kumpf 1.10 snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP);
323
|
324 yi.zhou 1.1 // Failed to create pdu
325 if (!snmpPdu)
326 {
|
327 kumpf 1.10 PEG_METHOD_EXIT();
328 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
329 MessageLoaderParms(
330 _MSG_PDU_CREATE_FAILED_KEY,
331 _MSG_PDU_CREATE_FAILED));
|
332 yi.zhou 1.1 }
333
334 // Make sure that the v1 trap PDU includes the local IP address
335 pduInAddr = (in_addr_t*) snmpPdu->agent_addr;
336 *pduInAddr = get_myaddr();
337
338 // get system up time
339 snmpPdu->time = get_uptime();
340
341 // Pack trap information into the PDU
342 try
343 {
344 _packTrapInfoIntoPdu(trapOid, snmpPdu);
345 }
346 catch (CIMException& e)
347 {
|
348 kumpf 1.10 Logger::put_l(
349 Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
350 _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED_KEY,
351 _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED,
352 e.getMessage());
|
353 yi.zhou 1.1 }
354
355 break;
356 }
357 case _SNMPv2C_TRAP:
358 {
359 sessionPtr->version = SNMP_VERSION_2c;
360
361 // Create the PDU
|
362 kumpf 1.10 snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP2);
363
|
364 yi.zhou 1.1 // Failed to create pdu
365 if (!snmpPdu)
366 {
|
367 kumpf 1.10 PEG_METHOD_EXIT();
|
368 yi.zhou 1.1
|
369 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
370 MessageLoaderParms(
371 _MSG_PDU_CREATE_FAILED_KEY,
372 _MSG_PDU_CREATE_FAILED));
|
373 yi.zhou 1.1 }
374
375 // Add sysUpTime to the PDU
376 char sysUpTime[32];
377 sprintf(sysUpTime, "%ld", get_uptime());
|
378 kumpf 1.10
|
379 yi.zhou 1.1 Sint32 retCode;
|
380 kumpf 1.10 retCode = snmp_add_var(
381 snmpPdu,
382 _SYSTEM_UP_TIME_OID,
383 OID_LENGTH(_SYSTEM_UP_TIME_OID),
384 't',
385 sysUpTime);
|
386 yi.zhou 1.1
387 // Failed to add sysUpTime to the pdu
388 if (retCode != 0)
389 {
390 String errMsg = snmp_api_errstring(retCode);
391
|
392 kumpf 1.10 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 kumpf 1.10 Logger::put_l(
413 Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
414 _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED_KEY,
415 _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED,
416 errMsg);
|
417 yi.zhou 1.1 }
418
419 break;
420 }
421 default:
422 {
|
423 kumpf 1.10 PEG_METHOD_EXIT();
|
424 yi.zhou 1.1
425 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,
|
426 kumpf 1.10 MessageLoaderParms(
427 _MSG_VERSION_NOT_SUPPORTED_KEY,
428 _MSG_VERSION_NOT_SUPPORTED));
|
429 yi.zhou 1.1 }
430 }
431
|
432 kumpf 1.10 PEG_METHOD_EXIT();
|
433 yi.zhou 1.1 }
434
435
436 // Pack trap information into the PDU
437 void snmpDeliverTrap_netsnmp::_packTrapInfoIntoPdu(
|
438 kumpf 1.10 const String& trapOid,
439 snmp_pdu* snmpPdu)
|
440 yi.zhou 1.1 {
|
441 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
442 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_packTrapInfoIntoPdu");
443
444 oid enterpriseOid[MAX_OID_LEN];
|
445 kumpf 1.10 size_t enterpriseOidLength;
|
446 yi.zhou 1.1
447 Array<String> standard_traps;
448
449 standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
450 standard_traps.append(String("1.3.6.1.6.3.1.1.5.2"));
451 standard_traps.append(String("1.3.6.1.6.3.1.1.5.3"));
452 standard_traps.append(String("1.3.6.1.6.3.1.1.5.4"));
453 standard_traps.append(String("1.3.6.1.6.3.1.1.5.5"));
454 standard_traps.append(String("1.3.6.1.6.3.1.1.5.6"));
455
|
456 kumpf 1.10 Array<const char*> oidSubIdentifiers;
|
457 yi.zhou 1.1
458 CString trapOidCStr = trapOid.getCString();
459
|
460 kumpf 1.10 char* trapOidCopy = strdup(trapOidCStr);
461 char* numericEntOid = (char*) malloc(strlen(trapOidCStr));
|
462 yi.zhou 1.9
463 try
464 {
|
465 yi.zhou 1.1
|
466 a.dunfey 1.12 #if !defined(PEGASUS_OS_TYPE_WINDOWS) && !defined(PEGASUS_OS_ZOS)
|
467 kumpf 1.10 char* last;
468 for (const char* p = strtok_r(trapOidCopy, ".", &last); p;
|
469 yi.zhou 1.9 p=strtok_r(NULL, ".", &last))
|
470 yi.zhou 1.1 #else
|
471 yi.zhou 1.9 for (const char* p = strtok(trapOidCopy, "."); p; p=strtok(NULL, "."))
|
472 yi.zhou 1.1 #endif
|
473 yi.zhou 1.9 {
474 oidSubIdentifiers.append(p);
475 }
|
476 yi.zhou 1.1
|
477 yi.zhou 1.9 long genTrap = 0;
478 long specTrap = 0;
|
479 yi.zhou 1.1
|
480 yi.zhou 1.9 enterpriseOidLength = MAX_OID_LEN;
|
481 yi.zhou 1.1
|
482 yi.zhou 1.9 if (Contains(standard_traps, trapOid))
483 {
484 //
485 // if the trapOid is one of the standard traps,
486 // then the SNMPV1 enterprise parameter must be set
487 // to the value of the trapOid, the generic-trap
488 // parameter must be set to one of (0 - 5), and the
489 // specific-trap parameter must be set to 0
490 //
491
492 // Convert trapOid from numeric form to a list of subidentifiers
|
493 kumpf 1.10 if (read_objid((const char*)trapOidCStr, enterpriseOid,
|
494 yi.zhou 1.9 &enterpriseOidLength) == 0)
495 {
|
496 kumpf 1.10 // Failed to parse trapOid
|
497 yi.zhou 1.9
|
498 kumpf 1.10 PEG_METHOD_EXIT();
499 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
500 yi.zhou 1.9 MessageLoaderParms(_MSG_READ_OBJID_FAILED_KEY,
501 _MSG_READ_OBJID_FAILED,
502 trapOid));
503 }
504
505 // the generic trap is last sub-identifier of the
506 // trapOid minus 1
|
507 kumpf 1.10 snmpPdu->trap_type =
|
508 yi.zhou 1.9 atoi(oidSubIdentifiers[oidSubIdentifiers.size() - 1]) - 1;
509 snmpPdu->specific_type = 0;
|
510 yi.zhou 1.1 }
|
511 yi.zhou 1.9 else
|
512 yi.zhou 1.1 {
|
513 yi.zhou 1.9 //
514 // if the trapOid is not one of the standard traps:
515 // then 1) the generic-trap parameter must be set to 6,
516 // 2) if the next-to-last sub-identifier of the
517 // trapOid is zero, then the SNMPV1 enterprise
518 // parameter is the trapOid with the last 2
519 // sub-identifiers removed, otherwise, the
520 // SNMPV1 enterprise parameter is the trapOid
521 // with the last sub-identifier removed;
522 // 3) the SNMPv1 specific-trap parameter is the last
523 // sub-identifier of the trapOid;
524 //
525
526 snmpPdu->trap_type = 6;
527
|
528 kumpf 1.10 snmpPdu->specific_type =
|
529 yi.zhou 1.9 atoi(oidSubIdentifiers[oidSubIdentifiers.size()-1]);
530
531 strcpy(numericEntOid, oidSubIdentifiers[0]);
532 for (Uint32 i = 1; i < oidSubIdentifiers.size()-2; i++)
533 {
534 strcat(numericEntOid, ".");
535 strcat(numericEntOid, oidSubIdentifiers[i]);
536 }
537
538 if (strcmp(oidSubIdentifiers[oidSubIdentifiers.size()-2], "0") != 0)
539 {
540 strcat(numericEntOid, ".");
|
541 kumpf 1.10 strcat(numericEntOid,
|
542 yi.zhou 1.9 oidSubIdentifiers[oidSubIdentifiers.size()-2]);
543 }
|
544 yi.zhou 1.1
|
545 kumpf 1.10 // Convert ent from numeric form to a list of subidentifiers
546 if (read_objid(numericEntOid, enterpriseOid,
|
547 yi.zhou 1.9 &enterpriseOidLength) == 0)
548 {
549 // Failed to parse numericEntOid
|
550 yi.zhou 1.1
|
551 kumpf 1.10 PEG_METHOD_EXIT();
|
552 yi.zhou 1.1
|
553 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
554 yi.zhou 1.9 MessageLoaderParms(_MSG_READ_ENTOID_FAILED_KEY,
555 _MSG_READ_ENTOID_FAILED,
556 String(numericEntOid)));
557 }
|
558 yi.zhou 1.1
559 }
560
|
561 yi.zhou 1.9 snmpPdu->enterprise = (oid*) malloc(enterpriseOidLength * sizeof(oid));
|
562 kumpf 1.10 memcpy(snmpPdu->enterprise, enterpriseOid,
563 enterpriseOidLength * sizeof(oid));
|
564 yi.zhou 1.9
565 snmpPdu->enterprise_length = enterpriseOidLength;
|
566 yi.zhou 1.1 }
|
567 yi.zhou 1.9 catch (...)
568 {
569 free(trapOidCopy);
570 free(numericEntOid);
|
571 yi.zhou 1.1
|
572 yi.zhou 1.9 PEG_METHOD_EXIT();
573 throw;
574 }
|
575 yi.zhou 1.1
576 free(trapOidCopy);
577 free(numericEntOid);
578
|
579 kumpf 1.10 PEG_METHOD_EXIT();
|
580 yi.zhou 1.1 }
581
582 // Pack oids into the PDU
583 void snmpDeliverTrap_netsnmp::_packOidsIntoPdu(
584 const Array<String>& vbOids,
585 const Array<String>& vbTypes,
586 const Array<String>& vbValues,
|
587 kumpf 1.10 snmp_pdu* snmpPdu)
|
588 yi.zhou 1.1 {
589
|
590 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
591 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_packOidsIntoPdu");
592
593 char dataType;
594 oid vbOid[MAX_OID_LEN];
595 size_t vbOidLength = MAX_OID_LEN;
596
597 for (Uint32 i=0; i < vbOids.size(); i++)
598 {
599 if (vbTypes[i] == "OctetString")
600 {
601 dataType = 's';
602 }
603 else if (vbTypes[i] == "Integer")
604 {
605 dataType = 'i';
|
606 kumpf 1.10 }
|
607 yi.zhou 1.1 else if (vbTypes[i] == "OID")
608 {
609 dataType = 'o';
610 }
611 else
612 {
|
613 kumpf 1.10 // Integer, OctetString, and OID are supported SNMP Data Types
|
614 yi.zhou 1.1 // for the CIM Property
615
|
616 kumpf 1.10 PEG_METHOD_EXIT();
|
617 yi.zhou 1.1
|
618 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
619 yi.zhou 1.1 MessageLoaderParms(_MSG_UNSUPPORTED_SNMP_DATA_TYPE_KEY,
620 _MSG_UNSUPPORTED_SNMP_DATA_TYPE,
621 vbTypes[i]));
622
623 }
624
|
625 kumpf 1.10 // Convert oid of a CIM property from numeric form to a list of
626 // subidentifiers
627 if (read_objid((const char*)vbOids[i].getCString(), vbOid,
|
628 yi.zhou 1.1 &vbOidLength) == 0)
629 {
630 // Failed to parse vbOids
631
|
632 kumpf 1.10 PEG_METHOD_EXIT();
|
633 yi.zhou 1.1
|
634 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
635 yi.zhou 1.1 MessageLoaderParms(_MSG_PARSE_CIM_PROPERTY_OID_FAILED_KEY,
636 _MSG_PARSE_CIM_PROPERTY_OID_FAILED,
637 vbOids[i]));
638 }
639
640 Sint32 retCode;
|
641 kumpf 1.10 retCode = snmp_add_var(snmpPdu, vbOid, vbOidLength, dataType,
|
642 yi.zhou 1.1 vbValues[i].getCString());
643
644 // Failed to add vbOid to the pdu
645 if (retCode != 0)
646 {
|
647 kumpf 1.10 PEG_METHOD_EXIT();
|
648 yi.zhou 1.1
|
649 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
650 yi.zhou 1.1 MessageLoaderParms(_MSG_ADD_VAR_TO_PDU_FAILED_KEY,
651 _MSG_ADD_VAR_TO_PDU_FAILED,
652 vbOids[i],
|
653 kumpf 1.10 String(snmp_api_errstring(retCode))));
|
654 yi.zhou 1.1
655 }
656 }
657
|
658 kumpf 1.10 PEG_METHOD_EXIT();
|
659 yi.zhou 1.1 }
660
661 PEGASUS_NAMESPACE_END
|