📄 snmpdelivertrap_emanate.cpp
字号:
oids.append(tmpoid); String ent; if (Contains(standard_traps, trapOid)) { // // if the trapOid is one of the standard traps, // then the SNMPV1 enterprise parameter must be set // to the value of the trapOid, the generic-trap // parameter must be set to one of (0 - 5), and the // specific-trap parameter must be set to 0 // enterpriseOid = sendtrapOid; // the generic trap is last sub-identifier of the // trapOid minus 1 genTrap = atoi(oids[oids.size() - 1].getCString()) - 1; specTrap = 0; } else { // // if the trapOid is not one of the standard traps: // then 1) the generic-trap parameter must be set to 6, // 2) if the next-to-last sub-identifier of the // trapOid is zero, then the SNMPV1 enterprise // parameter is the trapOid with the last 2 // sub-identifiers removed, otherwise, the // SNMPV1 enterprise parameter is the trapOid // with the last sub-identifier removed; // 3) the SNMPv1 specific-trap parameter is the last // sub-identifier of the trapOid; // genTrap = 6; specTrap = atoi(oids[oids.size()-1].getCString()); ent = oids[0]; for (Uint8 i = 1; i < oids.size()-2; i++) { ent = ent + "." + oids[i]; } if (oids[oids.size()-2] != "0") { ent = ent + "." + oids[oids.size()-2]; } enterpriseOid = MakeOIDFromDot(ent.getCString()); if (enterpriseOid == NULL) { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( _MSG_INVALID_ENTERPRISEOID_KEY, _MSG_INVALID_ENTERPRISEOID)); } } // creates VarBind for (Uint32 i = 0; i < vbOids.size(); i++) { CString _vbOid = vbOids[i].getCString(); CString _vbValue = vbValues[i].getCString(); if ((object = MakeOIDFromDot(_vbOid)) == NULL) { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( _MSG_INVALID_PROPERTYOID_KEY, _MSG_INVALID_PROPERTYOID)); } if (String::equalNoCase(vbTypes[i], "OctetString")) { OctetString* value; value = CloneOctetString(MakeOctetStringFromText(_vbValue)); if (value == NULL) { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( _MSG_INVALID_PROPERTYVALUE_KEY, _MSG_INVALID_PROPERTYVALUE)); } if ((vb = MakeVarBindWithValue( object, (OID*) NULL, OCTET_PRIM_TYPE, value)) == NULL) { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( _MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE_KEY, _MSG_MAKE_VARBIND_FAILED_FOR_OCTET_PRIM_TYPE)); } } else if (String::equalNoCase(vbTypes[i], "OID")) { void* value = MakeOIDFromDot(_vbValue); if (value == NULL) { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( _MSG_INVALID_PROPERTYVALUE_KEY, _MSG_INVALID_PROPERTYVALUE)); } if ((vb = MakeVarBindWithValue( object, (OID*) NULL, OBJECT_ID_TYPE, value)) == NULL) { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( _MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE_KEY, _MSG_MAKE_VARBIND_FAILED_FOR_OBJECT_ID_TYPE)); } } else { int vbvalue = atoi(_vbValue); void* value = &vbvalue; if (value == NULL) { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( _MSG_INVALID_PROPERTYVALUE_KEY, _MSG_INVALID_PROPERTYVALUE)); } if ((vb = MakeVarBindWithValue( object, (OID*) NULL, INTEGER_TYPE, value)) == NULL) { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms( _MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE_KEY, _MSG_MAKE_VARBIND_FAILED_FOR_INTEGER_TYPE)); } } if (i == 0) { vbhead = vb; vblast = vb; } else { vblast->next_var = vb; vblast = vblast->next_var; } } vblast->next_var = NULL; // Now send the trap switch (snmpVersion) { case _SNMPv1_TRAP: { SendNotificationToDestSMIv1Params( 1, // notifyType - TRAP genTrap, // genTrap specTrap, // specTrap enterpriseOid, // enterprise agent_addr, // agent_addr vbhead, // vb NULL, // contextName 1, // retryCount 1, // timeout community_name, // securityName, SR_SECURITY_LEVEL_NOAUTH, // securityLevel SR_SECURITY_MODEL_V1, // securityModel &global_ti, // Transport Info 0); // cfg_chk break; } case _SNMPv2C_TRAP: { SendNotificationToDestSMIv2Params( (SR_INT32)SNMPv2_TRAP_TYPE, // notifyType - NOTIFICATION sendtrapOid, // snmpTrapOID agent_addr, // agent_addr vbhead, // vb NULL, // contextName 1, // retryCount 100, // timeout community_name, // securityName or community SR_SECURITY_LEVEL_NOAUTH, // securityLevel SR_SECURITY_MODEL_V2C, // securityModel &global_ti, // TransportInfo 0); // cfg_chk break; } default: { throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED, MessageLoaderParms( _MSG_VERSION_NOT_SUPPORTED_KEY, _MSG_VERSION_NOT_SUPPORTED)); break; } } // Free OID built by calls MakeOIDFromDot() FreeOID(sendtrapOid); FreeOID(enterpriseOid); FreeOID(object); // Free the data structures allocated and built by calls // MakeOctetString() and MakeOctetStringFrom Text() FreeOctetString(community_name); FreeOctetString(agent_addr); // Free the VarBind data structures allocated and built // by calls MakeVarBindWithValue() FreeVarBindList(vbhead); FreeVarBindList(vb); FreeVarBindList(vblast);}// get the IP address of a hostchar* snmpDeliverTrap_emanate::_getIPAddress(const CString& hostName){ struct hostent* targetHostInfo; struct in_addr in;#if defined(PEGASUS_OS_LINUX) char hostEntryBuffer[8192]; struct hostent hostEntryStruct; int hostEntryErrno; gethostbyname_r( hostName, &hostEntryStruct, hostEntryBuffer, sizeof(hostEntryBuffer), &targetHostInfo, &hostEntryErrno);#elif defined(PEGASUS_OS_SOLARIS) char hostEntryBuffer[8192]; struct hostent hostEntryStruct; int hostEntryErrno; targetHostInfo = gethostbyname_r( (char*)hostName, &hostEntryStruct, hostEntryBuffer, sizeof(hostEntryBuffer), &hostEntryErrno);#else targetHostInfo = gethostbyname(hostName);#endif if (targetHostInfo == NULL) { return NULL; } char** networkAddr; networkAddr = targetHostInfo->h_addr_list; (void)memcpy(&in.s_addr, *networkAddr, sizeof(in.s_addr)); char* ipAddr = inet_ntoa(in); return(ipAddr);}// check the value of each part of an IP address which should be// between 0 and 255Boolean snmpDeliverTrap_emanate::_isValidOctet(const Uint32& octetValue){ if (octetValue > 0 && octetValue < 255) { return true; } else { return false; }}PEGASUS_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -