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