Dart.Snmp Namespace > SnmpSocket Class > GetTable Method : GetTable(String,SnmpVersion,String,Security,IPEndPoint,Int32,Int32) Method |
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 retries As Integer, _ ByVal maxRepetitions As Integer _ ) As Variable(,)
Dim instance As SnmpSocket Dim tableOid As String Dim version As SnmpVersion Dim community As String Dim security As Security Dim agentEP As IPEndPoint Dim retries As Integer Dim maxRepetitions As Integer Dim value() As Variable value = instance.GetTable(tableOid, version, community, security, agentEP, retries, maxRepetitions)
public Variable[,] GetTable( string tableOid, SnmpVersion version, string community, Security security, IPEndPoint agentEP, int retries, int maxRepetitions )
public: Variable*[,]* GetTable( string* tableOid, SnmpVersion version, string* community, Security* security, IPEndPoint* agentEP, int retries, int maxRepetitions )
public: array<Variable^,>^ GetTable( String^ tableOid, SnmpVersion version, String^ community, Security^ security, IPEndPoint^ agentEP, int retries, int maxRepetitions )
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. If retries is greater than 0, each retry must timeout before a timeout exception occurs. 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.
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 table using GetTable with 20 max-repetitions (retrieves up to 20 rows) Variable[,] table = managerSocket.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, SnmpVersion.Two, "public", null, myAgentAddress, 0, 20); //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 table using GetTable with 20 max-repetitions (retrieves up to 20 rows) Dim table(,) As Variable = managerSocket.GetTable(manager1.Mib.GetByNodeName(NodeName.ifTable).Oid, SnmpVersion.Two, "public", Nothing, myAgentAddress, 0, 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) '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