Polling Table Data

 

AdventNet SNMP API supports polling of one or more variables from the remote agent. Management applications in need of SNMP polling and automatic updates can use this feature.

 

Polling is a request-response interaction between a manager and agent. It is also used to report on behalf of a user to respond to specific user queries. In most cases, the information gathered by the management application for polling is through get and getnext requests. The frequency with which the management stations poll is called the polling frequency.

 

If all the table data are required to be polled, SnmpTable class can be used. Use the following code snippet.

 

table.setPollInterval(10);

// sets the poll interval at which the table should be polled

table.setTableOID("tableOID");

// sets the table OID and starts polling

table.addSnmpTableListener(listener);

// registers listener for table changes

 

The table data is received in tableChanged() method.

 

public void tableChanged(SnmpTableEvent e)

{

SnmpTable table = (SnmpTable)e.getSource();

if( e.isEndOfTable() || e.getType() == 2)

{

if (table.getRowCount() == 0)

System.err.println("Error string: " + table.getErrorString());

return;

}

// print column names

StringBuffer sb = new StringBuffer();

if (e.getFirstRow() == 0)

{

for (int i=0;i < table.getColumnCount();i++)

sb.append(table.getColumnName(i)+" \t");

System.out.println(sb.toString());

}

// print rows

sb = new StringBuffer();

for (int j=e.getFirstRow();j<=e.getLastRow();j++)

{

for (int i=0;i<table.getColumnCount();i++)

sb.append(table.getValueAt(j,i)+" \t");

}

System.out.println(sb.toString());

}

 

If only some columns in the table need to be polled, setColumnsPolled() method can be used to set the column OIDs that need to be polled. For example, if the columns first four columns of a table are needed to be polled:

 

Vector index = new Vector();

index.addElement(new Integer("0"));

index.addElement(new Integer("1"));

index.addElement(new Integer("2"));

index.addElement(new Integer("3"));

table.setColumnsPolled(index); //sets the columns that need to be polled

table.setTableOID("tableOID"); //sets the table OID and starts polling

table.addSnmpTableListener(listener); //registers listener for table changes

 

The columns that are set will only be polled and the data is received in the tableChanged() method.

 

 

 



Copyright © 1996-2006, AdventNet Inc. All Rights Reserved.