Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SNMP Traps with Indy

774 views
Skip to first unread message

Bradley Plett

unread,
Dec 17, 2002, 6:56:48 PM12/17/02
to
Can anyone provide even the simplest sample code to receive a trap
using Indy's SNMP component? I've looked pretty much everywhere I can
think of, and have not found sufficient documentation nor any examples
that have me to the point of being able to use this component.

Any help would be appreciated.

Thanks!
Brad.

Eyal Matzlavi

unread,
Dec 18, 2002, 7:06:41 AM12/18/02
to
Hi,

I'm not sure you can recieve traps with the snmp component, but here's a
code example for sending a trap:

with SNMP.Tram do begin
Clear;
Host := m_szHost;
GenTrap := snmptrapEnterpriseSpecific;
Community := m_szCommunityName;
SpecTrap := cTrapTypeNumArray[AlarmType];
Enterprise := CTrapProcessControlOID; //for example :
'1.3.6.1.4.1.5271.2.1.1.2'
MIBAdd('ProcessId', '110', ASN1_INT);
MIBAdd('ProcessName', 'test');
MIBAdd('ProcessType', '');
MIBAdd('ApplicationName', 'AppName');
MIBAdd('ProcessDescription', 'AppName');
MIBAdd('StateID', IntToStr(cTrapTypeNumArray[AlarmType]));
Trap.MIBAdd('StateDescription', Alarm.AlarmText);
MIBAdd('StatePropableCause', cTrapStrStatePropableCause[AlarmType]);
MIBAdd('EventTime', DateTimeToStr(Now));
MIBAdd('PercievedSeverity', 'Cleared');
MIBAdd('CpuUsages', '', ASN1_INT);
MIBAdd('MemoryUsages', IntToStr(ProcessData.LastMemCount), ASN1_INT);
MIBAdd('AdditionalText', '');
end;
AgentOrange.SendTrap;


"Bradley Plett" <ple...@elegantlogic.com> wrote in message
news:eaevvukaqc9ca5sh9...@4ax.com...

Colin Wilson

unread,
Dec 18, 2002, 12:30:38 PM12/18/02
to
Eyal Matzlavi wrote:

>
> I'm not sure you can recieve traps with the snmp component, but
> here's a code example for sending a trap:

You can receive traps with the Indy SNMP component - but you probably
don't want to.

The problem is that you can only have one thing looking out for SNMP
traps - and by default that's the Microsoft SNMP Trap Service. there
are APIs that you can use to attach your application to this service so
that it sends you the traps. The advantage of doing it this way is
that other trap-detecting applications will still work!

If you really want to use Indy to do it, here's a very simple example.
first disable the Microsoft SNMP Trap service - then start a new app,
and drop a TidSNMP component and a Button and a Listbox on the main
form. Make the button's OnClick handler look like this...

procedure TForm1.Button1Click(Sender: TObject);
begin
IdSNMP1.ReceiveTimeout := -2;
IdSNMP1.Binding.Port := 162;
IdSNMP1.Binding.Bind;
if IdSNMP1.ReceiveTrap <> 0 then
ListBox1.Items.Add(IdSNMP1.Trap.ValueOID [0]);
end;

Run your app and press the button. The app will wait until a trap is
received - than it's details will be added to the listbox.

--
Colin
e-mail :co...@wilsonc.demon.co.uk
web: http://www.wilsonc.demon.co.uk/delphi.htm

Posted with XanaNews 1.12.5.2

Mike Cherven

unread,
Dec 18, 2002, 1:37:10 PM12/18/02
to
"Colin Wilson" <co...@wilsonc.demon.co.uk> wrote in message
news:3e00...@newsgroups.borland.com...

> The problem is that you can only have one thing looking out for SNMP
> traps - and by default that's the Microsoft SNMP Trap Service. there
> are APIs that you can use to attach your application to this service so
> that it sends you the traps. The advantage of doing it this way is
> that other trap-detecting applications will still work!

Does the ms SNMP service actually perform trap detection? I thought that it
only sent traps and handled queries. Anyway, on my xp machine, with the
SNMP service running, your suggested code works. So, either ms doesn't have
an ear out for traps, or it doesn't do it by default.


Message has been deleted

Mike Cherven

unread,
Dec 18, 2002, 6:11:33 PM12/18/02
to
Ahhh....Thx! I see it under Services, and its not running.

<guit...@cox.net> wrote in message news:3E00EA...@cox.net...
> Colin was referring to the "SNMP Trap Service", not the "SNMP Service".
> When the "SNMP Trap Service" is running, it listens for traps, and you
> can use Windows API calls to be notified when traps are received. It
> listens on UDP port 162.

Bradley Plett

unread,
Dec 19, 2002, 1:58:09 AM12/19/02
to
Thanks a LOT!!! I think this is enough to get me started down the
right road.

Brad.

On 18 Dec 2002 09:30:38 -0800, "Colin Wilson"
<co...@wilsonc.demon.co.uk> wrote:

>Eyal Matzlavi wrote:
>
>>
>> I'm not sure you can recieve traps with the snmp component, but
>> here's a code example for sending a trap:
>
>You can receive traps with the Indy SNMP component - but you probably
>don't want to.
>
>The problem is that you can only have one thing looking out for SNMP
>traps - and by default that's the Microsoft SNMP Trap Service. there
>are APIs that you can use to attach your application to this service so
>that it sends you the traps. The advantage of doing it this way is
>that other trap-detecting applications will still work!
>
>If you really want to use Indy to do it, here's a very simple example.

>first disable the Microsoft SNMP Trap services.yihen start a new app,

Bryan Valencia

unread,
Jan 10, 2003, 2:05:31 PM1/10/03
to
Could you tell me where you found the value constants for GenTrap?
The one you used here is "snmptrapEnterpriseSpecific".
0 new messages