lextudio / sharpsnmplib

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

Requests logging in an agent #385

Closed lextudio-support closed 4 hours ago

lextudio-support commented 4 hours ago

Hi !

First of all I wanted to thank you for your amazing work on the Lib. Without you my life would be much more complicated :-)

I'm currently working on a particular agent "simulator", and for that I plan on using #SNMP. I already made a little prototype and it works perfectly.

But I'm asking myself something. My agent will receive tons and tons of get- requests and get-next-requests. I was wondering how I could log those requests and give the user information like : "Received get-request from xxx.xxx.xxx.xxx on port 161. Response : […]". I read a lot of the source code, especially in the Pipeline namespace, but I couldn't figure a way to detect a get or get-next request.

If there is no feature allowing this usage, I suggest you plan to implement one. But I'm pretty sure that it's just me who can't figure it out :-)

PS: I didn't find any answer on this matter in the discussions, documentation, google… but i apologize if an answer has already been given.

EDIT:: I just found the event in the Listener. The question now is : Can I intercept a response ?

Original Reported Date: 2012-02-02T23:47:49.95-08:00 Original CodePlex Discussion Thread ID: 291057

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Actually when you run snmpd.exe for a few times, you will notice that it generates log files on which requests have been handled. So you should follow its style to perform logging,

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

Check the OnLogRequest method.

You can use the default logger, https://github.com/lextm/sharpsnmplib/blob/master/snmpd/RollingLogger.cs or implement your own.

Regards,

Lex

Original Posted Date: 2012-02-03T03:07:48.937-08:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Awesome ! =)

I think I'll use that instead of the MessageReceived event in the Listener. But a question stays : is there a way to also log the response messages sent by my agent ? It would be really great for me.

I also noticed that in the Pipeline.ObjectStore class, there is no way to get the List of objects (except for using successive GetNextObject() calls, which I find pretty messy solution). Once again, it may be me who can't figure out how. And once again, if there is no way, I'd suggest defining the IList in protected instead of private, so future users that want to do the same thing can implement their own class with getter on the list (or put a getter in there).

I don't know if my suggestions are pertinent, I'm quite new to the programming world, so please accept my apologies if I'm wasting your time =)

Thanks for your help !

Regards,

Pegazz

EDIT:: I just answered myself the first question, it's in the context used by the Logger. I must learn to look carefully before asking, sorry :P.

Original Posted Date: 2012-02-03T05:06:25.893-08:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

ObjectStore in fact has more known issues than the one you noticed. As snmpd is only a demo project, not a real world SNMP agent, such issues won't matter much.

If you intend to build a real world agent, then you have to put more things into consideration, and then build up something completely different.

Regards,

Lex

Original Posted Date: 2012-02-03T23:24:42.17-08:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Ok, it's good to know.

But actually, except from that, the classes in the Pipeline section seem to meet all my needs, as my "agent" should only be able to handle SNMPv1 get and getnext requests and change some OIDs' values through a GUI. I think I'll just extend the ObjectStore class to add some functionalities.

I haven't enough time nor knowledge to build up something new, and the prototype that I created using #SNMP works just fine.

Thank you very much for your answers ! =)

Regards,

Pegazz

Original Posted Date: 2012-02-04T02:49:55.99-08:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

Then please make any change you like to ObjectStore.

Just note that the pipeline code is released under LGPL.

Regards,

Lex

Original Posted Date: 2012-02-05T01:18:13.85-08:00

lextudio-support commented 4 hours ago

Copied from CodePlex without authors:

A quick update is that starting from http://sharpsnmplib.codeplex.com/releases/view/79079, #SNMP is released under MIT/X11 (MIB support is under BSD 3 Clause).

Lex

Original Posted Date: 2013-02-01T00:52:33.82-08:00

lextudio-support commented 4 hours ago

Marked as Answer Date: 2013-10-06T04:08:40.55-07:00