Define the MIB and send the SNMP trap to .net

I developed a special application for a company under .net in C #, and it has been used for years. Now it is developed, one of the main new functions that I have to implement is to integrate it with other software, sending it SNMP traps in some situations.

I am an experienced developer, but have never used SNMP. I google all day, but more and more confused about this topic. I do not have a clear “starting point”. I understand the basics of SNMP, but I don’t know where and how to start the implementation.

I have data that I have to send through the SNMP trap, it has about 10 properties, some dates, numbers and strings. I have to create MIB definitions (s) for these properties. Later I have to implement a function in my application that sends SNMP traps based on these MIBs.

The project was developed under .net 4 in C #. I found this library that seems promising: http://sharpsnmplib.codeplex.com/ It has some examples of sending SNMP traps.

My problem: where to start? How to identify MIB files? I know that these are some text files that need to be compiled, but cannot find the MIB editors and help in this topic.

Any help is appreciated!

Thanks!

+6
source share
6 answers

I am not an expert, but I have the experience of being in the same place as you, and finally found something enough for my project.

I used this codeplex library that you talked about earlier and found it pretty good. Here are some pointers to get you through http://sharpsnmplib.codeplex.com/ .

  • As far as I understand, a MIB file is required when you need to do snmpget and snmpset
    • This is your request that the server and server return to your client with a request to provide more detailed information and may be required if you require extensive information to share your application.
  • If you only need traps, you can do it
    • Run snmpd.exe, which will act as a snmp server receiving traps sent from your application.
    • Write a program similar to snmptrapd.exe and send your traps.

The link http://www.net-snmp.org/wiki/index.php/TUT:snmptrap is good for getting a basic understanding and for more information about the library.

Edit: just one point is missing. You will need a MIB file if you use get and install for snmp. If you have traps, you may not need it.

+3
source

SNMP V2 MIB traps are described as NOTICE. See a complete example of such a MIB: http://tools.cisco.com/Support/SNMP/do/BrowseMIB.do?local=en&mibName=CISCO-EPM-NOTIFICATION-MIB

+1
source

Since you are apparently using Windows for SNMP, you need to create your own SNMP extension agent to add custom SNMP identifiers and associated traps to your system. Each OID literally represents a variable in which you can store your information. Here is an example of such a DLL . As far as I know, MIB files are used only in Windows as a reference for SNMP agents and cannot be used to add new OIDs without creating a custom SNMP agent.

When you have your custom SNMP agent DLL agent, you need to specify it in the registry. You can do this (example):

[HKEY_LOCAL_MACHINE\SOFTWARE\Symbol\MyAgent\CurrentVersion] "Pathname"="C:\\MyCustomAgent\\MyAgent.dll" ;Add number of agent to the list (max num registered + 1) [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ExtensionAgents] "10"="SOFTWARE\\Symbol\\MyAgent\\CurrentVersion" 

After that, you will need to restart the SNMP service. If everything is correct, you can use your new custom OID to set \ receive some data.

To read / write to your SNMP variables, you will need to use the SNMP manager. I usually use Sharpsnmplib . There are also graphical managers that will be useful during the debugging process, for example: iReasoning MIB Browser .

Here is sample code for using lib:

 using System.Collections.Generic; using System.Net; using System.Net.Sockets; // SNMP Lib references using Lextm.SharpSnmpLib; using Mono.Options; using Lextm.SharpSnmpLib.Messaging; using Lextm.SharpSnmpLib.Security; ... List vList = new List(); ISnmpData data; data = new OctetString("test"); // variable to add in to string OID Variable test = new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.6.0"), data); // OID vList.Add(test); VersionCode versionH = VersionCode.V2; // SNMP protocol version to use IPAddress ipH; IPAddress.TryParse("127.0.0.1", out ipH); IPEndPoint receiverH = new IPEndPoint(ipH, 161); foreach (Variable variable in Messenger.Set(versionH, receiverH, new OctetString("private"), vList, 10))// set variable // Arguments: (ver of SNMP, IP, group, iList containing OID and variable, timeoout) { // output variable } ... 

You can also read an article about working with SNMP in Windows on technet: link . This article is not new, but may help you understand how to work with SNMP on Windows.

+1
source

If you just need to send traps, you don't need to define a MIB. MIB for other parties understand the meaning of the variables in it. You can document it in another format, such as a text file.

To send traps, you can use the C # SNMP library or just call the snmptrap program directly. Net-snmp provides free command line tools for sending traps. ( http://net-snmp.sf.net ). Its use is quite simple.

To check if traps were sent successfully, you can use the free MIB browser ( http://ireasoning.com/mibbrowser.shtml ) to retrieve them. If this can be obtained, it usually means that your traps are in order.

+1
source

So from http://www.net-snmp.org/tutorial/tutorial-5/commands/snmptrap.html

SNMPv2 Notification

The SNMPv2 notification format is slightly different. The definition in the MIB file is as follows

 NOTIFICATION-TEST-MIB DEFINITIONS ::= BEGIN IMPORTS ucdavis FROM UCD-SNMP-MIB; demonotifs OBJECT IDENTIFIER ::= { ucdavis 991 } demo-notif NOTIFICATION-TYPE STATUS current OBJECTS { sysLocation } DESCRIPTION "Just a test notification" ::= { demonotifs 17 } END 
+1
source

You can also try snmpsharpnet , which is very useful for playing with SNMP at the top of .NET?

As the MIB editor, I use the MG-SOFT MIB Browser , a professional edition sold with Visual MIB Builder for Windows.

0
source

Source: https://habr.com/ru/post/907073/


All Articles