PowerSNMP for .NET CF
GetTable(String,SnmpVersion,String,Security,IPEndPoint,Int32) Method
See Also  Example Send comments on this topic.
Dart.Snmp Namespace > ManagerSlave Class > GetTable Method : GetTable(String,SnmpVersion,String,Security,IPEndPoint,Int32) Method




tableOid
The OID that indicates the table to retrieve.
version
SnmpVersion to use (cannot be SnmpVersion.One).
community
Community string to use. "public" is a typical value.
security
Security parameters to use for SnmpVersion.Three.
agentEP
The target IPEndPoint being used by the agent.
maxRepetitions
The max-repetitions value for each GetBulk request sent.
Performs one or more blocking GetBulk requests to retrieve a table.

Syntax

Visual Basic (Declaration) 
Public Overloads Function GetTable( _
   ByVal tableOid As String, _
   ByVal version As SnmpVersion, _
   ByVal community As String, _
   ByVal security As Security, _
   ByVal agentEP As IPEndPoint, _
   ByVal maxRepetitions As Integer _
) As Variable(,)
Visual Basic (Usage)Copy Code
Dim instance As ManagerSlave
Dim tableOid As String
Dim version As SnmpVersion
Dim community As String
Dim security As Security
Dim agentEP As IPEndPoint
Dim maxRepetitions As Integer
Dim value() As Variable
 
value = instance.GetTable(tableOid, version, community, security, agentEP, maxRepetitions)
C# 
public Variable[,] GetTable( 
   string tableOid,
   SnmpVersion version,
   string community,
   Security security,
   IPEndPoint agentEP,
   int maxRepetitions
)
Managed Extensions for C++ 
public: Variable*[,]* GetTable( 
   string* tableOid,
   SnmpVersion version,
   string* community,
   Security* security,
   IPEndPoint* agentEP,
   int maxRepetitions
) 
C++/CLI 
public:
array<Variable^,>^ GetTable( 
   String^ tableOid,
   SnmpVersion version,
   String^ community,
   Security^ security,
   IPEndPoint^ agentEP,
   int maxRepetitions
) 

Parameters

tableOid
The OID that indicates the table to retrieve.
version
SnmpVersion to use (cannot be SnmpVersion.One).
community
Community string to use. "public" is a typical value.
security
Security parameters to use for SnmpVersion.Three.
agentEP
The target IPEndPoint being used by the agent.
maxRepetitions
The max-repetitions value for each GetBulk request sent.

Return Value

A two-dimensional Variable array representing the table.

Example

The following example demonstrates how to retrieve a table using internal GetBulk requests to retrieve 20 cells at a time.
C#Copy Code
private void button1_Click(object sender, EventArgs e)
{
    //Retrieve and display an SNMP Table
    manager1.Start(getTable, myAgentAddress);
}

private void getTable(ManagerSlave slave, object state)
{
    //Get SNMP ifTable at specified address
    string address = state.ToString();
    slave.Socket.ReceiveTimeout = 3000;
    
    //Retrieve table using GetBulk with 20 max-repetitions
    Variable[,] table = slave.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, SnmpVersion.Two, "public", null,
        new System.Net.IPEndPoint(System.Net.IPAddress.Parse(address), 161), 20);

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

void manager1_Table(object sender, Dart.Snmp.TableEventArgs e)
{
    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("Column " + (i + 1).ToString(), 100, 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);
    }
}
Visual BasicCopy Code
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    'Retrieve and display an SNMP Table
    manager1.Start(AddressOf getTable, myAgentAddress)
End Sub

Private Sub getTable(ByVal slave As ManagerSlave, ByVal state As Object)
    'Get SNMP ifTable at specified address
    Dim address As String = state.ToString()
    slave.Socket.ReceiveTimeout = 3000

    //Retrieve table using GetBulk with 20 max-repetitions
    Dim table(,) As Variable = slave.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, _
        SnmpVersion.Two, "public", Nothing, New System.Net.IPEndPoint(System.Net.IPAddress.Parse(address), 161), 20)

    '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)
    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("Column " & (i + 1).ToString(), 100, 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
            If (table(r, c) Is Nothing) Then
                tableRow.SubItems.Add("NULL")
            Else
                tableRow.SubItems.Add(table(r, c).Value.ToString())
            End If
        Next c

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

Remarks

This method walks the MIB by sending one or more GetBulkMessage requests until the table is complete. 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 version must be SnmpVersion.Two or SnmpVersion.Three.

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

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 4.2
© 2010 Dart Communications. All Rights Reserved.