我需要通过 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 portrange 161-162)
我很高兴看到一些关于我的代码的评论,或者可能是 SendTrap 的工作示例 :)