Dart.Snmp Namespace > MibNodes Class : Parse Method |
This method can be called once, or multiple times to process multiple MIB files. After parsing is completed, call GenerateNodes to populate MibNodes with the parsed definitions.
/* This snippet uses a MIB file with the following content: DART-TEST-MIB DEFINITIONS ::= BEGIN IMPORTS private FROM RFC1155-SMI OBJECT-TYPE FROM RFC-1212 DisplayString FROM RFC-1213; dart OBJECT IDENTIFIER ::= {private 42} testString OBJECT-TYPE SYNTAX DisplayString ACCESS read-write STATUS optional DESCRIPTION "This is a description for a string" ::= {dart 1} */ private void Form1_Load(object sender, EventArgs e) { //Load the MIB file defined above using (FileStream fs = new FileStream("DART-TEST-MIB.mib", FileMode.Open, FileAccess.Read)) manager1.Mib.Parse(fs); //Parse additional MIBs here, before calling GenerateNodes() manager1.Mib.GenerateNodes(); } private void button1_Click(object sender, EventArgs e) { //Create and send request for 'testString' from the MIB, on a worker thread manager1.Start(manager1_SendGetRequest, new Variable(manager1.Mib["testString"])); } private void manager1_SendGetRequest(SnmpSocket managerSocket, object state) { //Create Get Request GetMessage request = new GetMessage(); request.Variables.Add(state as Variable); //Send request and get response ResponseMessage response = managerSocket.GetResponse(request, myAgentAddress); //Marshal message to the UI thread using the Message event manager1.Marshal(new ResponseMessage[] { response }, "", null); } private void manager1_Message(object sender, MessageEventArgs e) { //Display info about the first variable in the response, and its value Variable vari = e.Messages[0].Variables[0]; label1.Text = vari.Definition.ToString() + vari.Value.ToString(); }
' This snippet uses a MIB file with the following content: ' 'DART-TEST-MIB DEFINITIONS ::= BEGIN ' 'IMPORTS ' private ' FROM RFC1155-SMI ' OBJECT-TYPE ' FROM RFC-1212 ' DisplayString ' FROM RFC-1213; ' 'dart OBJECT IDENTIFIER ::= {private 42} ' 'testString OBJECT-TYPE ' SYNTAX DisplayString ' ACCESS read-write ' STATUS optional ' DESCRIPTION ' "This is a description for a string" ' ::= {dart 1} ' ' Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) 'Load the MIB file defined above Using fs As New FileStream("DART-TEST-MIB.mib", FileMode.Open, FileAccess.Read) manager1.Mib.Parse(fs) End Using 'Parse additional MIBs here, before calling GenerateNodes() manager1.Mib.GenerateNodes() End Sub Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) 'Create and send request for 'testString' from the MIB, on a worker thread manager1.Start(AddressOf manager1_SendGetRequest, New Variable(manager1.Mib("testString"))) End Sub Private Sub manager1_SendGetRequest(ByVal managerSocket As SnmpSocket, ByVal state As Object) 'Create Get Request Dim request As New GetMessage() request.Variables.Add(TryCast(state, Variable)) 'Send request and get response Dim response As ResponseMessage = managerSocket.GetResponse(request, myAgentAddress) 'Marshal message to the UI thread using the Message event manager1.Marshal(New ResponseMessage() { response }, "", Nothing) End Sub Private Sub manager1_Message(ByVal sender As Object, ByVal e As MessageEventArgs) 'Display info about the first variable in the response, and its value Dim vari As Variable = e.Messages(0).Variables(0) label1.Text = vari.Definition.ToString() & vari.Value.ToString() End Sub