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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2