PowerSNMP for .NET
Parse Method
Example 




A stream containing the MIB file to parse.
Parses the provided MIB file data.
Syntax
Public Sub Parse( _
   ByVal mib As Stream _
) 
Dim instance As MibNodes
Dim mib As Stream
 
instance.Parse(mib)
public void Parse( 
   Stream mib
)
public: void Parse( 
   Stream* mib
) 
public:
void Parse( 
   Stream^ mib
) 

Parameters

mib
A stream containing the MIB file to parse.
Remarks

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.

Example
The following example demonstrates loading a MIB file at runtime, and retrieving the value of an object defined in that MIB from an agent.
/* 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
See Also

Reference

MibNodes Class
MibNodes Members


PowerSNMP for .NET Documentation Version 8.0
© 2024 Dart Communications. All Rights Reserved.
Send comments on this topic