Quantcast
Channel: sharpsnmplib Forum Rss Feed
Viewing all 173 articles
Browse latest View live

New Post: Sample for sending V3 Traps

$
0
0
Ah I see, thanks for clarifying that. Once I have constructed a V3 Trap message as you have shown, what is the procedure to then send that message out to an endpoint?

Regards,
Neil

New Post: Sample for sending V3 Traps

$
0
0
Don't worry about that last question. Just found the Send method on the TrapV2Message class!

New Post: Sample for sending V3 Traps

$
0
0
Ok... so it looks like I am successfully sending a V3 trap following your example code but I'm not receiving it on the other end which is essentially the same code as the snmptrapd sample.

I used RawCap to sniff the packets being sent and can see a trap message getting sent out and a get-response coming back from my manager. The get-response contains an error status of authorizationError (16).

Here is a snippet of my manager code:
            Container = new UnityContainer().LoadConfiguration("snmptrapd");
            var users = this.Container.Resolve<UserRegistry>();
            users.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair);
            users.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication"))));
            users.Add(new OctetString("privacy"), new DESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication"))));

            var trapv1 = Container.Resolve<TrapV1MessageHandler>("TrapV1Handler");
            trapv1.MessageReceived += WatcherTrapV1Received;
            var trapv2 = Container.Resolve<TrapV2MessageHandler>("TrapV2Handler");
            trapv2.MessageReceived += WatcherTrapV2Received;
            var inform = Container.Resolve<InformRequestMessageHandler>("InformHandler");
            inform.MessageReceived += WatcherInformRequestReceived;

            Engine = Container.Resolve<SnmpEngine>();
            Engine.Listener.AddBinding(new IPEndPoint(IPAddress.Any, snmpPort));
            // The Engine is started later in the code as it is hosted in a service/console app
and here is my Trap sender code:
            var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 162);
            //var privacy = DefaultPrivacyProvider.DefaultPair;
            var privacy = new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication")));
            //var privacy = new DESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")));
            var trap = new TrapV2Message(
                VersionCode.V3,
                528732060,
                1905687779,
                new OctetString("authen"),
                new ObjectIdentifier("1.3.6"),
                0,
                new List<Variable>(),
                privacy,
                0x10000,
                new OctetString(ByteTool.Convert("80001F8880E9630000D61FF449")),
                0,
                0
               );

            trap.Send(endpoint);
As you can see I've tried all three types of PrivacyProvider from the samples but they all return authorizationError (16). Not quite sure what could be going wrong since my usernames, community and privacy phrases all seem to match up?

Neil

New Post: Sample for sending V3 Traps

$
0
0
I seem to have cracked it.

I checked through the code that decides whether to send an authorisationError response and noticed this line:
            if (parameters.EngineId != Group.EngineId)
            {
                // not from this engine.
                return false;
            }
And then noticed that the Engine ID is hard coded within the library!
        // TODO: make engine ID configurable from outside and unique.
        private readonly OctetString _engineId =
            new OctetString(new byte[] { 128, 0, 31, 136, 128, 233, 99, 0, 0, 214, 31, 244 });
So after tweaking my Trap message by copying the OctetString construction from above to the engineId parameter, it all started to work! Hurrah!

New Post: Add parameter range

$
0
0
Hi, for one of my projects I need the range of a MIB node. For example 0..10 in the following code:

toasterDoneness OBJECT-TYPE
SYNTAX INTEGER (1..10)
ACCESS read-write
STATUS mandatory
DESCRIPTION
"This variable controls how well-done is the ensuing toast. It 
      should be on a scale of 1 to 10. Toast made at 10 generally 
      is considered unfit for human consumption; 
      toast made at 1 is warmed lightly."
::= {toaster 4}

Can this please be implemented?
If not, can you please help me to change the code? Which code has to change?

New Post: Add parameter range

New Post: Need an option for disabling SNMP V3

$
0
0
If you use the library in your simulator, you can avoid calling the V3 APIs.

If you in fact build your simulator based on snmpd project, try to modify the config file.

New Post: Add parameter range

$
0
0
But that's closed source. Does anybody know an open source solution for this?

New Post: Add parameter range

$
0
0
As far as I know, in .NET open source world there is none.

New Post: Need an option for disabling SNMP V3

$
0
0
Hi,
Thank you very much for the reply.
I am using the library in my project, not building it based on SNMP project.
I'll try to follow your advise.
Sincerely,
Sivsprassd S. Nair

New Post: Issue creating INFORM listener on a worker thread

$
0
0
Hi,

First off, many thanks for an excellent library - I've only been working with it for a couple of weeks but it's proven extremely easy to use.

I'm experiencing a strange issue in regard to receiving INFORMs with the library. I'm currently developing two pieces of software - one in C# using #SNMP and one in Java using SNMP4J. The C# component is an extension to a pre-existing program and is implementing the INFORM listener, the Java component is a new development and is sending the INFORM messages.

I've done some testing with the following configurations:

(NET-SNMP) snmptrapd receiving messages from the java code - works fine
c# code receiving messages from (NET-SNMP) snmptrap - works fine
c# code receiving messages from the java code - doesn't work

The c# code is based on the sample snmptrapd.cs. Now, here's the strange thing. I create a simple test listener using the following code:
internal static IUnityContainer Container { get; private set; }

        static void Main(string[] args)
        {
            Container = new UnityContainer().LoadConfiguration("snmptrapd");
            var users = Container.Resolve<UserRegistry>();
            users.Add(new OctetString("??????????"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("??????????"))));

            var trapv1 = Container.Resolve<TrapV1MessageHandler>("TrapV1Handler");
            trapv1.MessageReceived += WatcherTrapV1Received;
            var trapv2 = Container.Resolve<TrapV2MessageHandler>("TrapV2Handler");
            trapv2.MessageReceived += WatcherTrapV2Received;
            var inform = Container.Resolve<InformRequestMessageHandler>("InformHandler");
            inform.MessageReceived += WatcherInformRequestReceived;
            using (var engine = Container.Resolve<SnmpEngine>())
            {
                engine.ExceptionRaised += new EventHandler<Lextm.SharpSnmpLib.Messaging.ExceptionRaisedEventArgs>(engine_ExceptionRaised);
                IPEndPoint endPoint = new IPEndPoint(new IPAddress(new byte[]{127,0,0,1}), 162);
                engine.Listener.AddBinding(endPoint);
                engine.Listener.ExceptionRaised += new EventHandler<Lextm.SharpSnmpLib.Messaging.ExceptionRaisedEventArgs>(Listener_ExceptionRaised);
                engine.Start();
                Console.WriteLine("Bound on " + endPoint.Address + ":" + endPoint.Port);
                Console.WriteLine("#SNMP is available at http://sharpsnmplib.codeplex.com");
                Console.WriteLine("Press any key to stop . . . ");
                Console.Read();
                engine.Stop();
            }
        }

        static void Listener_ExceptionRaised(object sender, Lextm.SharpSnmpLib.Messaging.ExceptionRaisedEventArgs e)
        {
            Console.WriteLine(e.Exception.ToString());
        }

        static void engine_ExceptionRaised(object sender, Lextm.SharpSnmpLib.Messaging.ExceptionRaisedEventArgs e)
        {
            Console.WriteLine("Exception: " + e.Exception.ToString());
        }

        private static void WatcherInformRequestReceived(object sender, InformRequestMessageReceivedEventArgs e)
        {
            Console.WriteLine("Inform message received");
            Console.WriteLine(e.InformRequestMessage);
        }

        private static void WatcherTrapV2Received(object sender, TrapV2MessageReceivedEventArgs e)
        {
            Console.WriteLine("Trap V2 message received");
            Console.WriteLine(e.TrapV2Message);
        }

        private static void WatcherTrapV1Received(object sender, TrapV1MessageReceivedEventArgs e)
        {
            Console.WriteLine("Trap V1 message received");
            Console.WriteLine(e.TrapV1Message);
        }
This works fine with the Java code. I place (almost) exactly the same code in the original C# project, and it doesn't work. The changes are twofold:
  1. The program is designed to be unattended, so the keypress stuff was removed, and instead, we perform:
                while (_running)
                    System.Threading.Thread.Sleep(500);
after engine.Start(). At the moment, the variable always has the value true, so this is in effect an infinite loop (although in the future we will need to be able to change it to stop the listener).
  1. Rather than running on the main thread, the code is wrapped in a void Start() method and started on a new thread:
                ThreadStart ts = () =>
                {
                    listener.Start();
                };
                Thread thread = new Thread(ts);
                thread.Name = listener.Name;
                thread.Start();
This is the only thread that utilizes #SNMP objects and there is only ever a single instance of the thread, simply to isolate it from the rest of the work that the program is doing.

I know the library isn't guaranteed to be thread-safe, but I assumed that we would be alright using it on a thread as long as we guaranteed that only that one thread used the library.

Any ideas on what might be going wrong? We're using TritonMate.

Thanks,

Austen

New Post: INFORM notInTimeWindow issue (was: Issue creating INFORM listener on a worker thread)

$
0
0
Hi again,

Done a bit more digging and I've found out what is going on here - the situation wasn't precisely as indicated above.

The solution works fine if I start the C# listener and then the Java sender such that they both start at the same time. However, if I stop one or the other, then restart after a couple of minutes, the requests are all rejected.

From walking through the code, the problem seems to be the testing of the time window of the messages - once the difference is >150s, it (correctly) rejects it as notInTimeWindow; however, it doesn't actually send the response to indicate that this is the reason for rejection (marked "TODO: handle error here. return TRAP saying authenticationFailed in SnmpApplication:117), so the SNMP4J time is never synchronized with the #SNMP time, and the problem continues indefinitely.

Thanks,

Austen

New Post: INFORM notInTimeWindow issue (was: Issue creating INFORM listener on a worker thread)

New Post: Receiving Traps from other communities?

$
0
0
Hello:
Following Lextm instructions, I have achieved to change the community name to listen. Now I am trying to listen to two different communities (or to all communities) with the same program and I don´t know how to achieved this.
Can you give me some link or instruction to add another SNMP v1 community to listen or to write my own provider?
I don´t know if II have to use wildcards in the community name or to inherit from some class...

Thank you in advance
Luis G.

New Post: How to discover many snmp agents

$
0
0
there is discover method in #snmp library to discover an agent.

but i need to discover all agents that present in a our lan . i think # snmp library is not supporting .please help me.

New Post: How to discover many snmp agents

New Post: Cannot receive V2 trap

$
0
0
Hello,

First of all, thank you for your great job on this library. I already use it to set and get some OID on a remote device and now I would like to extend my app with a snmp v2 trap listener. I tried your snmptrapd sample but unfortunately it cannot catch any trap. I have no such issue with an alternative trap listener tool so I restart the sample with a wireshark trace. From wireshark log, I can see that the trap is well received but then the strange thing is that SharpSnmpLib send a snmp report to the trap sender. Could you please have a look to the attached pcap capture ?

snm.trap.pcap

New Post: Cannot receive V2 trap

New Post: Receiving Traps from other communities?

$
0
0
Hi Luis,

You don't even need instruction on how to create your own provider, as I have provided several provider samples in the code base. Grab one of them and modify, then you get yours ready. Wild card is not supported by the built-in providers, so you have to write your own.

New Post: Getting value for a single OID from the SNMP Device.

$
0
0
How can I get the value for a single OID from the SNMP Device.
Viewing all 173 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>