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




tableOid
The OID that indicates the table to retrieve.
version
SnmpVersion to use.
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.
Performs a series of blocking 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 _
) 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 value() As Variable
 
value = instance.GetTable(tableOid, version, community, security, agentEP)
C# 
public Variable[,] GetTable( 
   string tableOid,
   SnmpVersion version,
   string community,
   Security security,
   IPEndPoint agentEP
)
Managed Extensions for C++ 
public: Variable*[,]* GetTable( 
   string* tableOid,
   SnmpVersion version,
   string* community,
   Security* security,
   IPEndPoint* agentEP
) 
C++/CLI 
public:
array<Variable^,>^ GetTable( 
   String^ tableOid,
   SnmpVersion version,
   String^ community,
   Security^ security,
   IPEndPoint^ agentEP
) 

Parameters

tableOid
The OID that indicates the table to retrieve.
version
SnmpVersion to use.
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.

Return Value

A two-dimensional Variable array representing the table.

Example

The following example demonstrates how to retrieve a table using a series of internal GetNext requests.
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 GetNext requests
    Variable[,] table = slave.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, 
        SnmpVersion.Two, "public", null, address, 161);

    //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 GetNext requests
    Dim table(,) As Variable = slave.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, _
        SnmpVersion.Two, "public", Nothing, address, 161)

    '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 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. 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 GetBulkMessage and specify the OIDs of the table columns.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

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