PowerSNMP for .NET
GetTable(String,String) Method
Example 




The OID that indicates the table to retrieve.
The IP Address in dot notation or hostname of the agent managing the table.
Performs a series of blocking GetNext requests to retrieve a table using SNMP version 1.
Syntax
Public Overloads Function GetTable( _
   ByVal tableOid As String, _
   ByVal agentNameOrAddress As String _
) As Variable(,)
Dim instance As SnmpSocket
Dim tableOid As String
Dim agentNameOrAddress As String
Dim value() As Variable
 
value = instance.GetTable(tableOid, agentNameOrAddress)

Parameters

tableOid
The OID that indicates the table to retrieve.
agentNameOrAddress
The IP Address in dot notation or hostname of the agent managing the table.

Return Value

A two-dimensional Variable array representing the table.
Remarks

This method walks the MIB by sending a GetNextMessage for each element in the table. The method blocks and will not return until the complete table has been retrieved or any single request exceeds the value of the Socket.ReceiveTimeout property. The time required to complete this request is a function of the number of elements in a table. Very large tables can take some time to retrieve.

The returned Variable array is a two dimensional array. Use Array.GetLength(0) and Array.GetLength(1), respectively, to determine the number of rows and columns in the returned table.

The remotePort defaults to the "well-known" agent port 161 when the Transport is set to Transport.UDP or 10161 when the Transport is Transport.DTLS. The community defaults to "public".

The format of the requested table array depends upon the specification of a valid tableOid.

For improved performance, use GetResponse(RequestMessage,String) or GetResponse(RequestMessage,IPEndPoint) with a GetBulkMessage and specify the OIDs of the table columns.

Example
The following example demonstrates how to retrieve a table using the GetTable method that utilizes GetNext requests.
private void button1_Click(object sender, EventArgs e)
{
    //Start a worker thread to retrieve and display an SNMP Table
    manager1.Start(getTable, null);
}

private void getTable(SnmpSocket managerSocket, object state)
{
    //Retrieve the table data from the agent
    Variable[,] table = managerSocket.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, SnmpVersion.Two, "public", null, myAgentAddress, 0);

    //Marshal table to UI thread
    manager1.Marshal(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, table, "", null);
}

private void manager1_Table(object sender, Dart.Snmp.TableEventArgs e)
{
    //Raised on the UI thread.
    //Populate a ListView control with the table data
    buildTable(e.Table);
}

private void buildTable(Variable[,] table)
{
    //Add columns to the listview for each column in the table
    for (int i = 0; i < table.GetLength(1); i++)
        lvwTable.Columns.Add(table[0, i].Definition.Name, 150, HorizontalAlignment.Left);

    ListViewItem tableRow;
    int r, c = 0;
    for (r = 0; r < table.GetLength(0); r++)
    {
        //Create a new row and add the first cell
        tableRow = new ListViewItem(table[r, 0].Value.ToString());

        //Add each additional cell in the row
        for (c = 1; c < table.GetLength(1); c++)
            tableRow.SubItems.Add((table[r, c] == null) ? "NULL" : table[r, c].Value.ToString());

        //Add the row to the listview
        lvwTable.Items.Add(tableRow);
    }
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Start a worker thread to retrieve and display an SNMP Table
    manager1.Start(AddressOf getTable, Nothing)
End Sub

Private Sub getTable(ByVal managerSocket As SnmpSocket, ByVal state As Object)
    'Retrieve the table data from the agent
    Dim table(,) As Variable = managerSocket.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, SnmpVersion.Two, "public", Nothing, myAgentAddress, 0)

    'Marshal table to UI thread
    manager1.Marshal(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, table, "", Nothing)
End Sub

Private Sub manager1_Table(ByVal sender As Object, ByVal e As Dart.Snmp.TableEventArgs)
    'Raised on the UI thread.
    'Populate a ListView control with the table data
    buildTable(e.Table)
End Sub

Private Sub buildTable(ByVal table(,) As Variable)
    'Add columns to the listview for each column in the table
    For i As Integer = 0 To table.GetLength(1) - 1
        lvwTable.Columns.Add(table(0, i).Definition.Name, 150, HorizontalAlignment.Left)
    Next i

    Dim tableRow As ListViewItem
    Dim r As Integer, c As Integer = 0
    For r = 0 To table.GetLength(0) - 1
        'Create a new row and add the first cell
        tableRow = New ListViewItem(table(r, 0).Value.ToString())

        'Add each additional cell in the row
        For c = 1 To table.GetLength(1) - 1
            tableRow.SubItems.Add(If(table(r, c) Is Nothing, "NULL", table(r, c).Value.ToString()))
        Next c

        'Add the row to the listview
        lvwTable.Items.Add(tableRow)
    Next r
End Sub
See Also

Reference

SnmpSocket Class
SnmpSocket Members
Overload List


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