lextudio / sharpsnmplib

Sharp SNMP Library- Open Source SNMP for .NET
https://sharpsnmp.com
MIT License
356 stars 152 forks source link

How to respond to Inform message #463

Closed lextudio-support closed 2 hours ago

lextudio-support commented 2 hours ago

Hi,

We're trying to send inform messages and respond to them. We are getting the messages on the receiver side, but are getting timeouts because we can't find how to send an acknowledgement. We've tried:

void listener_MessageReceived(object sender, InformRequestMessageReceivedEventArgs e)
{
//Process the message...

//send acknowledgement  
var responseMessage = new ResponseMessage(e.InformRequestMessage.RequestId(), e.InformRequestMessage.Version,  
                                          e.InformRequestMessage.Community(), ErrorCode.NoError, 0,  
                                          e.InformRequestMessage.Variables());  
responseMessage.Send(new IPEndPoint(IPAddress.Loopback, 162));  

}

With the sender sending V2 inform messages, the responseMessage.Send(..) is giving a "not a trap mesage" error. We'd appreciate any information on how to send an acknowledgement to an inform request.

Thanks.

Original Reported Date: 2012-02-28T04:48:07.313-08:00 Original CodePlex Discussion Thread ID: 346560

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

The Send extension method is for TRAP messages only.

In your case, you need to host the SNMP pipeline like Browser.exe does in NotificationPanel.cs,

https://github.com/lextm/sharpsnmplib/blob/master/Browser/NotificationPanel.cs

Then you will receive notification when an INFORM message arrives. Note that the pipeline automatically sends out the acknowledge message for you, and you don't need to send out a response any more.

Regards,

Lex

Original Posted Date: 2012-02-29T03:56:17.043-08:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Can we control if the ack is sent back? i.e. if the handler throws an exception, will the ack still be sent? For example, in:

private void ListenerInformRequestReceived(object sender, InformRequestMessageReceivedEventArgs e)

    {

        LogMessage(string.Format(CultureInfo.InvariantCulture, StrSends, DateTime.Now, e.Sender, e.InformRequestMessage.ToString(Objects)));

    }

if LogMessage raised an exception, we would want to receive the message again and as such, not return an ack.

Original Posted Date: 2012-02-29T05:44:34.5-08:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

You can see from InformRequestMessageHandler how ListenerInformRequestReceived is consumed.

https://github.com/lextm/sharpsnmplib/blob/master/SharpSnmpLib/Pipeline/InformRequestMessageHandler.cs

I think you may write your own InformRequestMessageHandler class and then hook it to the pipeline (via Unity) without using the default implementation, then you can have full control over how the INFORM message is handled.

Remember the pipeline is pluggable.

Regards,

Lex

Original Posted Date: 2012-03-01T05:03:37.043-08:00

lextudio-support commented 2 hours ago

Marked as Answer Date: 2013-10-06T04:14:57.167-07:00