I need to report errors from my application on C++Builder via SNMP.
I started implementing SNMP SendTrap using Indy components.
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;
}
But when I run application there is no udp activity in my system. When I run something like this
idSnmp->QuickSend(sysDescr, "public", edHost->Text, val);
wireshark shows 192.168.100.21 192.168.100.19 SNMP 82 get-request 1.3.6.1.2.1.1.3.0
but when idSnmp->SendTrap()
wireshark sees nothing (filter for wireshark is UDP portrange 161-162 in both cases)
I'll be glad to see some remarks about my code or maybe working example of SendTrap :)
You are not populating
TIdSNMP::Trap
with any values. That is whyTIdSNMP::SendTrap()
is not sending anything. There is nothing for it to send.Try this instead:
Alternatively, you can use
TIdSNMP::QuickSendTrap()
instead:Or, if you are compiling for mobile: