lextudio / sharpsnmplib

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

Receive trap in the Webservice ? #347

Closed lextudio-support closed 2 hours ago

lextudio-support commented 2 hours ago

Can I receive trap in the Webservice ?

Original Reported Date: 2011-06-13T23:41:16.367-07:00 Original CodePlex Discussion Thread ID: 261274

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Hi,

If you initiate a Listener object and set up bindings correctly, you should be able to receive traps. Our sample snmptrapd.exe shows how to receive traps in a normal application, and it is not too hard to do the same in a web service application, except that you should pay attention to common multi-threading things.

Regards,

Lex

Original Posted Date: 2011-06-14T05:38:18.223-07:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Lextm,

I did that and snmptrapd code compiles and works. However, I can find not documentation on how to pull the Var Binds from the trapMessages received. How do you do this?

It seem that you have a far supior LIB here than SnmpSharpNet, but will the VERY limited documentation, it is very hard to use. SnmpSharpNet guy has a lot of documentation and examples. Any chance you plan on adding more documentation and class library docs?

Thanks

-=Ryan

never mind: I found this:

http://sharpsnmplib.codeplex.com/releases/view/46604

Original Posted Date: 2011-12-14T08:33:03.057-08:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Lextm,

I am looking at your example program "snmpTrapD" and I am trying to understand how it works. Even after reading up on Unity as MSDN, I still don't understand how starting the "SnmpEngine" is connected to the event "WatcherTrapV2Received" ?

Would you create another example of snmpTrapD without using Unity, so I can see how you would hook the components together. Using Unity hides much of the implementation and it's hard to understand how your LIB works and function together.

Also, is SnmpEngine multi-thread supprted?

Thanks

Original Posted Date: 2011-12-14T11:14:21.273-08:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

The trick (event handler attaching) happens in Program.cs, http://code.google.com/p/sharpsnmplib/source/browse/Samples/C%23/snmptrapd/Program.cs, where the event handlers are assigned to message handler objects created in the Unity container. If you are familiar with IIS/ASP.NET, you will find this handler pattern almost the same.

It is not accurate to say something "multi-thread supported".

Like the samples show, if the SNMP objects are not altered at runtime, they work fine even if you send out lots of requests/traps, as multiple threads (thread pool) are used to process the incoming messages. Each incoming request goes to its own SnmpApplication object, and being handled by this SNMP pipeline.

However, not all classes participate in the pipeline are fully thread safe. For example, ObjectStore class and all ISnmpObject derived classes are not yet thread safe. If you want to create a full functional SNMP agent, you need to further tune the classes.

Regards,

Original Posted Date: 2011-12-14T19:40:07.55-08:00

lextudio-support commented 2 hours ago

Copied from CodePlex without authors:

Lex,

Thanks for te quick reply. Yeah, I see all that in program.cs, and I tried to decipher the linkage in app.config where all the unity stuff is mapped, but I cannot turn it into a C# program I can read and understand. It would be extremely helpful to be about to see how all your components fit together. At the risk of showing how little I may actually understand about C#, this is what I have tried to do to get your LIB coded in a fashion that makes sense to me:

    public partial class Form1 : Form
    {
        SnmpEngine snmpEngine;
        UserRegistry snmpUsers;
        SnmpApplicationFactory snmpAppFac;

        OctetString osPublic = new OctetString("public");
        OctetString osPrivate = new OctetString("private");
        OctetString osGet = new OctetString("get");
        OctetString osSet = new OctetString("set");

        public Form1()
        {
            InitializeComponent();
        }

        private void InitSnmpEngine()
        {
            snmpUsers = new UserRegistry();

            Version1MembershipProvider v1 = new Version1MembershipProvider(osGet, osSet);
            Version2MembershipProvider v2 = new Version2MembershipProvider(osGet, osSet);
            IMembershipProvider[] providers = { v1, v2 };
            ComposedMembershipProvider memProviders = new ComposedMembershipProvider(providers);
            ObjectStore store = new ObjectStore();          
            HandlerMapping v1Mapping = new HandlerMapping("v1", "TRAPV1", new TrapV1MessageHandler());
            HandlerMapping v2Mapping = new HandlerMapping("v2", "TRAPV2", new TrapV1MessageHandler());
            HandlerMapping[] mappings = { v1Mapping, v2Mapping };
            MessageHandlerFactory mhf = new MessageHandlerFactory(mappings);

            snmpAppFac = new SnmpApplicationFactory(store, memProviders, mhf);
            snmpEngine = new SnmpEngine(snmpAppFac, new Listener(), new EngineGroup());

            snmpUsers.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair);
            snmpUsers.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication"))));
            snmpUsers.Add(new OctetString("privacy"), new DESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication"))));

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //Engine Start
        }
    }

Original Posted Date: 2011-12-15T07:19:13.62-08:00

lextudio-support commented 2 hours ago

Marked as Answer Date: 2013-10-06T21:19:24.843-07:00