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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2