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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2