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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2