Visual Basic (Declaration) | |
---|---|
Public Overloads Function GetTable( _ ByVal tableOid As String, _ ByVal agentNameOrAddress As String _ ) As Variable(,) |
Visual Basic (Usage) | ![]() |
---|---|
Dim instance As ManagerSlave Dim tableOid As String Dim agentNameOrAddress As String Dim value() As Variable value = instance.GetTable(tableOid, agentNameOrAddress) |
C# | |
---|---|
public Variable[,] GetTable( string tableOid, string agentNameOrAddress ) |
Managed Extensions for C++ | |
---|---|
public: Variable*[,]* GetTable( string* tableOid, string* agentNameOrAddress ) |
C++/CLI | |
---|---|
public: array<Variable^,>^ GetTable( String^ tableOid, String^ 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.C# | ![]() |
---|---|
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 Basic | ![]() |
---|---|
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 |
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.
Target Platforms: Microsoft .NET Framework 2.0