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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2