(file) Return to snmpDeliverTrap_netsnmp.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / snmpIndicationHandler

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2