Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Indy组件实现SNMP SendTrap_Snmp_Indy_C++builder 2010 - Fatal编程技术网

使用Indy组件实现SNMP SendTrap

使用Indy组件实现SNMP SendTrap,snmp,indy,c++builder-2010,Snmp,Indy,C++builder 2010,我需要通过SNMP在C++Builder上报告应用程序中的错误 我开始使用Indy组件实现SNMP SendTrap void __fastcall TMainForm::btSendTrapClick(TObject *Sender) { UnicodeString myEnterprise = "1.5.5.5.5.5.5.5"; UnicodeString eventType = "1.5.5.5.5.5.5.5.1"; UnicodeString eventDistance

我需要通过SNMP在C++Builder上报告应用程序中的错误

我开始使用Indy组件实现SNMP SendTrap

void __fastcall TMainForm::btSendTrapClick(TObject *Sender)
{
UnicodeString myEnterprise   = "1.5.5.5.5.5.5.5";
UnicodeString eventType      = "1.5.5.5.5.5.5.5.1";
UnicodeString eventDistance  = "1.5.5.5.5.5.5.5.2";

TIdSNMP * idSnmp = 0;
TSNMPInfo * infoSnmp = 0;

idSnmp                 = new TIdSNMP(NULL);
infoSnmp               = new TSNMPInfo(idSnmp);

idSnmp->Host           = edHost->Text;
idSnmp->Community      = "public";

infoSnmp->Host           = edHost->Text;
infoSnmp->Community      = "public";
infoSnmp->Enterprise = myEnterprise;
infoSnmp->GenTrap = 6;                       // I've met such values
infoSnmp->SpecTrap = 1;                      // somewhere in inet
infoSnmp->MIBAdd(eventType,"ftCritical");
infoSnmp->MIBAdd(eventDistance,"2.357");

idSnmp->SendTrap();

delete idSnmp;
}
但当我运行应用程序时,我的系统中并没有udp活动。当我做这样的事情时

idSnmp->QuickSend(sysDescr, "public", edHost->Text, val);
wireshark显示192.168.100.21 192.168.100.19 SNMP 82获取请求1.3.6.1.2.1.1.3.0

但是当
idSnmp->SendTrap()
wireshark什么也看不到时(在这两种情况下,wireshark的过滤器都是UDP端口范围161-162)


我很高兴看到关于我的代码或SendTrap的工作示例的一些评论:)

您没有使用任何值填充
tidsmp::Trap
。这就是为什么
tidsmp::SendTrap()
不发送任何内容的原因。没有什么东西可以送

请尝试以下方法:

void\uu fastcall TMainForm::btSendTrapClick(TObject*Sender)
{
字符串myEnterprise=_D(“1.5.5.5.5.5.5.5.5.5.5.5”);
字符串eventType=myEnterprise+_D(“.1”);
字符串eventDistance=myEnterprise+_D(“.2”);
TIDSMPN*idSnmp=新的TIDSMPN(空);
idSnmp->Trap->Host=edHost->Text;
idSnmp->Trap->Community=\u D(“公共”);
idSnmp->Trap->Enterprise=myEnterprise;
idSnmp->Trap->GenTrap=6;//我遇到过这样的值
idSnmp->Trap->SpecTrap=1;//在inet中的某个地方
idSnmp->Trap->MIBAdd(eventType,_D(“ftCritical”);
idSnmp->Trap->MIBAdd(eventDistance,_D(“2.357”));
idSnmp->SendTrap();
删除idSnmp;
}
或者,您也可以使用
tidsmp::QuickSendTrap()

void\uu fastcall TMainForm::btSendTrapClick(TObject*Sender)
{
字符串myEnterprise=_D(“1.5.5.5.5.5.5.5.5.5.5.5”);
字符串eventType=myEnterprise+_D(“.1”);
字符串eventDistance=myEnterprise+_D(“.2”);
TStringList*names=新的TStringList;
名称->添加(事件类型);
名称->添加(事件距离);
TStringList*值=新的TStringList;
值->添加对象(_D(“ftCritical”),(TObject*)ASN1_OCTSTR);
值->添加对象(_D(“2.357”),(TObject*)ASN1_OCTSTR);
TIDSMPN*idSnmp=新的TIDSMPN(空);
idSnmp->QuickSendTrap(edHost->Text,myEnterprise,_D(“公共”),162,6,1,名称,值);
删除idSnmp;
删除姓名;
删除值;
}
或者,如果您是为移动设备编译:

void\uu fastcall TMainForm::btSendTrapClick(TObject*Sender)
{
字符串myEnterprise=_D(“1.5.5.5.5.5.5.5.5.5.5.5”);
字符串eventType=myEnterprise+_D(“.1”);
字符串eventDistance=myEnterprise+_D(“.2”);
TIdMIBValueList*mibs=新的TIdMIBValueList;
mibs->Add(TIdMIBValue(eventType,_D(“ftCritical”),ASN1_OCTSTR));
mibs->Add(TIdMIBValue(eventDistance,_D(“2.357”),ASN1_OCTSTR));
TIDSMPN*idSnmp=新的TIDSMPN(空);
idSnmp->QuickSendTrap(edHost->Text,myEnterprise,_D(“公共”),162,6,1,MIB);
删除idSnmp;
删除MIB;
}

谢谢您的回答。我不知道为什么,但我认为当我填充snmpInfo时就足够了。显然,我没有分配idSnmp->Trap=snmpInfo,但不幸的是,它并没有解决我的问题。我从字面上复制了你的代码,但还没有网络活动。如果它有效,那么请接受我的答案,这样我就可以获得学分。对于
idSnmp->Trap=snmpInfo
,它将泄漏原始
Trap
对象。使用
TIdSNMP
创建的
TIdSNMPInfo
,如我所示。根本不要创造你自己的。