|
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. The basic request-response interactions occurring between a manager and agent are get, getnext and sendtrap (trap messages from SNMP agents to one or more SNMP management applications). However, 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.
The SnmpPoller bean of the high-level API can be used for polling one or more variables. The SNMP Poller bean can be used in the applications, applets and also in bean builders. The values of the variables can be plotted in Graph components like LineGraphBean, BarGraphBean provided in com.adventnet.snmp.ui package.
The SnmpTable bean can be used for polling table data.
To use SnmpPoller for polling, instantiate, set up properties such as host name and community and register for receiving polled data. Refer the following code snippet.
|
poller.setObjectID("1.1.0"); //the OID to be polled
poller.setPollInterval(10); //polling interval in seconds. Default is 1 second.
poller.setSendTimeoutEvents(true); //to send the timeout events to the listener.
ResultListener listener = new ResultListener() { public void setResult(ResultEvent evt) { System.err.println("SnmpPoller Response: "+evt.getValue(0)); } }; poller.addResultListener(listener); |
Refer the example applet snmpPollerDemo.java in applications directory and the example application lineGraphDemo.java in examples/uiapplications directory for plotting the polled data in LineGraph.
The poller will automatically poll and generate events when responses are received. If the poll interval is not set,then the default poll interval of 1 seconds will be considered. If it is required that the poller should not start polling automatically, then setAutoActive(false) should be done. Now the poller will not start polling automatically. To start polling the data should be called.
|
poller.restartPolling() //to start polling the SNMP data |
For polling multiple OIDs
The ObjectIDs that need to be polled can be set using setObjectIDList() method. Refer the following code snippet.
|
poller.setObjectIDList(oids); ResultListener listener = new ResultListener() { public void setResult(ResultEvent evt) { for(int i=0;i<oids.length;i++) System.err.println("SnmpPoller Response: "+evt.getValue(i)); } }; poller.addResultListener(listener); |
The method evt.getValues() can also be used. This method will return a String array of polled data.
|