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 kumpf 1.18 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
126 MessageLoaderParms(
127 _MSG_PACK_CIM_PROPERTY_TO_PDU_FAILED_KEY,
128 _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.19 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.19 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.19 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 kumpf 1.18 MessageLoaderParms(
351 _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED_KEY,
352 _MSG_PACK_TRAP_INFO_INTO_PDU_FAILED,
353 e.getMessage()));
|
354 yi.zhou 1.1 }
355
356 break;
357 }
358 case _SNMPv2C_TRAP:
359 {
360 sessionPtr->version = SNMP_VERSION_2c;
361
362 // Create the PDU
|
363 kumpf 1.10 snmpPdu = snmp_pdu_create(SNMP_MSG_TRAP2);
364
|
365 yi.zhou 1.1 // Failed to create pdu
366 if (!snmpPdu)
367 {
|
368 kumpf 1.10 PEG_METHOD_EXIT();
|
369 yi.zhou 1.1
|
370 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
371 MessageLoaderParms(
372 _MSG_PDU_CREATE_FAILED_KEY,
373 _MSG_PDU_CREATE_FAILED));
|
374 yi.zhou 1.1 }
375
376 // Add sysUpTime to the PDU
377 char sysUpTime[32];
378 sprintf(sysUpTime, "%ld", get_uptime());
|
379 kumpf 1.10
|
380 yi.zhou 1.1 Sint32 retCode;
|
381 kumpf 1.10 retCode = snmp_add_var(
382 snmpPdu,
383 _SYSTEM_UP_TIME_OID,
384 OID_LENGTH(_SYSTEM_UP_TIME_OID),
385 't',
386 sysUpTime);
|
387 yi.zhou 1.1
388 // Failed to add sysUpTime to the pdu
389 if (retCode != 0)
390 {
391 String errMsg = snmp_api_errstring(retCode);
392
|
393 kumpf 1.10 Logger::put_l(
394 Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
|
395 kumpf 1.18 MessageLoaderParms(
396 _MSG_ADD_SYSUPTIME_TO_PDU_FAILED_KEY,
397 _MSG_ADD_SYSUPTIME_TO_PDU_FAILED,
398 errMsg));
|
399 yi.zhou 1.1 }
400
401 // Add snmp trap to the PDU
|
402 kumpf 1.10 retCode = snmp_add_var(
403 snmpPdu,
404 _SNMPTRAP_OID,
405 OID_LENGTH(_SNMPTRAP_OID),
406 'o',
407 trapOid.getCString());
|
408 yi.zhou 1.1
409 // Failed to add snmp trap to the pdu
410 if (retCode != 0)
411 {
412 String errMsg = snmp_api_errstring(retCode);
413
|
414 kumpf 1.10 Logger::put_l(
415 Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
|
416 kumpf 1.18 MessageLoaderParms(
417 _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED_KEY,
418 _MSG_ADD_SNMP_TRAP_TO_PDU_FAILED,
419 errMsg));
|
420 yi.zhou 1.1 }
421
422 break;
423 }
424 default:
425 {
|
426 kumpf 1.10 PEG_METHOD_EXIT();
|
427 yi.zhou 1.1
428 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED,
|
429 kumpf 1.10 MessageLoaderParms(
430 _MSG_VERSION_NOT_SUPPORTED_KEY,
431 _MSG_VERSION_NOT_SUPPORTED));
|
432 yi.zhou 1.1 }
433 }
434
|
435 kumpf 1.10 PEG_METHOD_EXIT();
|
436 yi.zhou 1.1 }
437
438
439 // Pack trap information into the PDU
440 void snmpDeliverTrap_netsnmp::_packTrapInfoIntoPdu(
|
441 kumpf 1.10 const String& trapOid,
442 snmp_pdu* snmpPdu)
|
443 yi.zhou 1.1 {
|
444 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
445 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_packTrapInfoIntoPdu");
446
447 oid enterpriseOid[MAX_OID_LEN];
|
448 kumpf 1.10 size_t enterpriseOidLength;
|
449 yi.zhou 1.1
450 Array<String> standard_traps;
451
452 standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
453 standard_traps.append(String("1.3.6.1.6.3.1.1.5.2"));
454 standard_traps.append(String("1.3.6.1.6.3.1.1.5.3"));
455 standard_traps.append(String("1.3.6.1.6.3.1.1.5.4"));
456 standard_traps.append(String("1.3.6.1.6.3.1.1.5.5"));
457 standard_traps.append(String("1.3.6.1.6.3.1.1.5.6"));
458
|
459 kumpf 1.10 Array<const char*> oidSubIdentifiers;
|
460 yi.zhou 1.1
461 CString trapOidCStr = trapOid.getCString();
462
|
463 kumpf 1.10 char* trapOidCopy = strdup(trapOidCStr);
464 char* numericEntOid = (char*) malloc(strlen(trapOidCStr));
|
465 yi.zhou 1.9
466 try
467 {
|
468 yi.zhou 1.1
|
469 a.dunfey 1.12 #if !defined(PEGASUS_OS_TYPE_WINDOWS) && !defined(PEGASUS_OS_ZOS)
|
470 kumpf 1.10 char* last;
471 for (const char* p = strtok_r(trapOidCopy, ".", &last); p;
|
472 yi.zhou 1.9 p=strtok_r(NULL, ".", &last))
|
473 yi.zhou 1.1 #else
|
474 yi.zhou 1.9 for (const char* p = strtok(trapOidCopy, "."); p; p=strtok(NULL, "."))
|
475 yi.zhou 1.1 #endif
|
476 yi.zhou 1.9 {
477 oidSubIdentifiers.append(p);
478 }
|
479 yi.zhou 1.1
|
480 yi.zhou 1.9 long genTrap = 0;
481 long specTrap = 0;
|
482 yi.zhou 1.1
|
483 yi.zhou 1.9 enterpriseOidLength = MAX_OID_LEN;
|
484 yi.zhou 1.1
|
485 yi.zhou 1.9 if (Contains(standard_traps, trapOid))
486 {
487 //
488 // if the trapOid is one of the standard traps,
489 // then the SNMPV1 enterprise parameter must be set
490 // to the value of the trapOid, the generic-trap
491 // parameter must be set to one of (0 - 5), and the
492 // specific-trap parameter must be set to 0
493 //
494
495 // Convert trapOid from numeric form to a list of subidentifiers
|
496 kumpf 1.10 if (read_objid((const char*)trapOidCStr, enterpriseOid,
|
497 yi.zhou 1.9 &enterpriseOidLength) == 0)
498 {
|
499 kumpf 1.10 // Failed to parse trapOid
|
500 yi.zhou 1.9
|
501 kumpf 1.10 PEG_METHOD_EXIT();
502 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
503 yi.zhou 1.9 MessageLoaderParms(_MSG_READ_OBJID_FAILED_KEY,
504 _MSG_READ_OBJID_FAILED,
505 trapOid));
506 }
507
508 // the generic trap is last sub-identifier of the
509 // trapOid minus 1
|
510 kumpf 1.10 snmpPdu->trap_type =
|
511 yi.zhou 1.9 atoi(oidSubIdentifiers[oidSubIdentifiers.size() - 1]) - 1;
512 snmpPdu->specific_type = 0;
|
513 yi.zhou 1.1 }
|
514 yi.zhou 1.9 else
|
515 yi.zhou 1.1 {
|
516 yi.zhou 1.9 //
517 // if the trapOid is not one of the standard traps:
518 // then 1) the generic-trap parameter must be set to 6,
519 // 2) if the next-to-last sub-identifier of the
520 // trapOid is zero, then the SNMPV1 enterprise
521 // parameter is the trapOid with the last 2
522 // sub-identifiers removed, otherwise, the
523 // SNMPV1 enterprise parameter is the trapOid
524 // with the last sub-identifier removed;
525 // 3) the SNMPv1 specific-trap parameter is the last
526 // sub-identifier of the trapOid;
527 //
528
529 snmpPdu->trap_type = 6;
530
|
531 kumpf 1.10 snmpPdu->specific_type =
|
532 yi.zhou 1.9 atoi(oidSubIdentifiers[oidSubIdentifiers.size()-1]);
533
534 strcpy(numericEntOid, oidSubIdentifiers[0]);
535 for (Uint32 i = 1; i < oidSubIdentifiers.size()-2; i++)
536 {
537 strcat(numericEntOid, ".");
538 strcat(numericEntOid, oidSubIdentifiers[i]);
539 }
540
541 if (strcmp(oidSubIdentifiers[oidSubIdentifiers.size()-2], "0") != 0)
542 {
543 strcat(numericEntOid, ".");
|
544 kumpf 1.10 strcat(numericEntOid,
|
545 yi.zhou 1.9 oidSubIdentifiers[oidSubIdentifiers.size()-2]);
546 }
|
547 yi.zhou 1.1
|
548 kumpf 1.10 // Convert ent from numeric form to a list of subidentifiers
549 if (read_objid(numericEntOid, enterpriseOid,
|
550 yi.zhou 1.9 &enterpriseOidLength) == 0)
551 {
552 // Failed to parse numericEntOid
|
553 yi.zhou 1.1
|
554 kumpf 1.10 PEG_METHOD_EXIT();
|
555 yi.zhou 1.1
|
556 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
557 yi.zhou 1.9 MessageLoaderParms(_MSG_READ_ENTOID_FAILED_KEY,
558 _MSG_READ_ENTOID_FAILED,
559 String(numericEntOid)));
560 }
|
561 yi.zhou 1.1
562 }
563
|
564 yi.zhou 1.9 snmpPdu->enterprise = (oid*) malloc(enterpriseOidLength * sizeof(oid));
|
565 kumpf 1.10 memcpy(snmpPdu->enterprise, enterpriseOid,
566 enterpriseOidLength * sizeof(oid));
|
567 yi.zhou 1.9
568 snmpPdu->enterprise_length = enterpriseOidLength;
|
569 yi.zhou 1.1 }
|
570 yi.zhou 1.9 catch (...)
571 {
572 free(trapOidCopy);
573 free(numericEntOid);
|
574 yi.zhou 1.1
|
575 yi.zhou 1.9 PEG_METHOD_EXIT();
576 throw;
577 }
|
578 yi.zhou 1.1
579 free(trapOidCopy);
580 free(numericEntOid);
581
|
582 kumpf 1.10 PEG_METHOD_EXIT();
|
583 yi.zhou 1.1 }
584
585 // Pack oids into the PDU
586 void snmpDeliverTrap_netsnmp::_packOidsIntoPdu(
587 const Array<String>& vbOids,
588 const Array<String>& vbTypes,
589 const Array<String>& vbValues,
|
590 kumpf 1.10 snmp_pdu* snmpPdu)
|
591 yi.zhou 1.1 {
592
|
593 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
|
594 yi.zhou 1.1 "snmpDeliverTrap_netsnmp::_packOidsIntoPdu");
595
596 char dataType;
597 oid vbOid[MAX_OID_LEN];
598 size_t vbOidLength = MAX_OID_LEN;
599
600 for (Uint32 i=0; i < vbOids.size(); i++)
601 {
602 if (vbTypes[i] == "OctetString")
603 {
604 dataType = 's';
605 }
606 else if (vbTypes[i] == "Integer")
607 {
608 dataType = 'i';
|
609 kumpf 1.10 }
|
610 yi.zhou 1.1 else if (vbTypes[i] == "OID")
611 {
612 dataType = 'o';
613 }
614 else
615 {
|
616 kumpf 1.10 // Integer, OctetString, and OID are supported SNMP Data Types
|
617 yi.zhou 1.1 // for the CIM Property
618
|
619 kumpf 1.10 PEG_METHOD_EXIT();
|
620 yi.zhou 1.1
|
621 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
622 yi.zhou 1.1 MessageLoaderParms(_MSG_UNSUPPORTED_SNMP_DATA_TYPE_KEY,
623 _MSG_UNSUPPORTED_SNMP_DATA_TYPE,
624 vbTypes[i]));
625
626 }
627
|
628 kumpf 1.10 // Convert oid of a CIM property from numeric form to a list of
629 // subidentifiers
630 if (read_objid((const char*)vbOids[i].getCString(), vbOid,
|
631 yi.zhou 1.1 &vbOidLength) == 0)
632 {
633 // Failed to parse vbOids
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_PARSE_CIM_PROPERTY_OID_FAILED_KEY,
639 _MSG_PARSE_CIM_PROPERTY_OID_FAILED,
640 vbOids[i]));
641 }
642
643 Sint32 retCode;
|
644 kumpf 1.10 retCode = snmp_add_var(snmpPdu, vbOid, vbOidLength, dataType,
|
645 yi.zhou 1.1 vbValues[i].getCString());
646
647 // Failed to add vbOid to the pdu
648 if (retCode != 0)
649 {
|
650 kumpf 1.10 PEG_METHOD_EXIT();
|
651 yi.zhou 1.1
|
652 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
653 yi.zhou 1.1 MessageLoaderParms(_MSG_ADD_VAR_TO_PDU_FAILED_KEY,
654 _MSG_ADD_VAR_TO_PDU_FAILED,
655 vbOids[i],
|
656 kumpf 1.10 String(snmp_api_errstring(retCode))));
|
657 yi.zhou 1.1
658 }
659 }
660
|
661 kumpf 1.10 PEG_METHOD_EXIT();
|
662 yi.zhou 1.1 }
663
664 PEGASUS_NAMESPACE_END
|