This is a simple tool to walk through MIB tree using Simple Network Management Protocol (SNMP). I developed this tool solely for learning. Here, I'm presenting this tool to explain the techniques behind SNMP manager (client) development. This tool is not intended for serious managing stuff. But if you want to use it for serious system management, go ahead and use it. I won't stop you. But after that, don't complain to me about the bugs and lacking features ;). You are most welcome to modify or fix the bugs (if you have time ;)).
This tool will do two things. One is capturing the traps and the other is sending request and getting the response. See the above figure, first list control displays response and the bottom one displays the traps. Traps are captured independently by a thread, which is started in OnInitDialog function. So whenever you run this tool, it will start displaying the traps coming to your system. On this figure, displayed traps are from MyAgent.DLL agent, which I presented on the previous articles. Even in the rest of this article, I'm using MyAgent.DLL agent to explain this tool functionality.
Requesting To Agent
Under this heading, I am explaining the first part of this tool in detail. Like all communication, here also there is a need to call Open before making any request to server. Making the request is simple. All you have to do is, first open it using SnmpMgrOpen API, then make a request using SnmpMgrRequest and close it using SnmpMgrClose API. To open it, you should specify the agent's IP address and the community name. This seems simple, isn't it? Yeh!... it is simple. OK, now, take a look in to request types.
Example: Type IP address of your agent, here that is "127.0.0.1". Type the community name as "public" and click "Open". Make sure "public" community has READ WRITE access.
Set request (SNMP_PDU_SET): Set request can be performed only on to the variable with write access. Also, you should have opened the session with READ & WRITE enabled community in SnmpMgrOpen API. First, this tool will get the string from the value edit box and translate to the type specified by the type combo box (combo next to the value edit box), and then it will pass it to the following function below as AsnObjectIdentifier variable. This function will make the request based on the selected OID after putting this variable in to a SnmpVarBindList list. (Even though it is a list, only one variable name & value will be placed.)
Example: Type ".1.3.6.1.4.1.15.0.0.2" on the OID edit box, type "Some thing" on value edit box, and select "octet" in the type combo next to the value edit box. Then, click "Set". Now you can see traps coming with "Some thing". Which shows that the variable is set successfully.
CODE1**************
Get Request (SNMP_PDU_GET): This is reverse of the SET request. This tool will take the OID and make the request. The returning value will be translated to string and the edit box will be populated with that.
Example: Type ".1.3.6.1.4.1.15.0.0.1" on the OID and click "Get". You can see the "Author : Ramanan.T" coming on the value edit box and "octet" on the type combo.
CODE2**************
Get Next Request (SNMP_PDU_GETNEXT): This is same like the GET request, but instead of returning the requested OID value, it will return the next available OID and its value. It's very useful to traverse the MIB tree.
Example: To experiment this, type ".1.3.6.1.4.1.15" on the OID and click "Get All". You can see all the three nodes in MyAgent.DLL displayed on the list box. Another interesting thing, type ".1.3.6" on the OID, click "Get All", and wait for a while. You can see a long list showing most of your computer details.
CODE3**************
Capturing Traps
Only the following thread is dealing with traps. It is independent from the requests. To capture traps, you don't have to open it (click "Open" button). To capture traps, event is necessary. Event should be created (using CreateEvent) and passed to SnmpMgrTrapListen API. Then, using WaitForSingleObject API, wait for any traps, and when it appears, get it using SnmpMgrGetTrap API. Here in this tool, these captured traps are translated to string type and list control is populated with that.
CODE4