com.adventnet.snmp.mibs.agent
Class SnmpDBAdaptor

java.lang.Object
  extended by com.adventnet.snmp.snmp2.agent.SimpleRequestHandler
      extended by com.adventnet.snmp.mibs.agent.SnmpDBAdaptor
All Implemented Interfaces:
VarBindRequestListener, AgentEventListener

public class SnmpDBAdaptor
extends SimpleRequestHandler

SnmpDBAdaptor class is used to implement the database adaptor bean. The associated requests are converted to SQL queries.

This class extends SimpleRequestHandler

See Also:
SimpleRequestHandler

Field Summary
(package private) static int _QUERY
           
(package private) static int _UPDATE
           
(package private)  boolean getNextFlag
           
(package private)  JDBCAdapter jdbc
           
(package private)  com.adventnet.snmp.mibs.AgentMibOperations mibOps
           
(package private)  boolean msAccessDb
           
(package private)  boolean mysqlDb
           
(package private)  boolean oracleDb
           
(package private)  java.lang.String registeredOid
           
(package private)  boolean tableNameIsNull
           
 
Fields inherited from class com.adventnet.snmp.snmp2.agent.SimpleRequestHandler
instrumentHandler, listener, tableListener
 
Constructor Summary
SnmpDBAdaptor()
          constructor creates JDBCAdapter and initializes with default arguments.
 
Method Summary
 void addRegistrationListener(RegistrationListener rl)
          This method is called by BeanInfo for adding Registration Listener with PduRequestHandler
 com.adventnet.snmp.mibs.AgentMibOperations getAgentMibOperations()
          Getter for AgentMibOperations.
 java.lang.Integer getColumnProperty(java.lang.String columnName)
          This method can be used to get the maximum length for a column value.
 java.lang.String getDriverName()
          get the driverName.
 java.lang.String getMibFiles()
          getter for the mib file name(s) for which this bean aware of.
 int[] getOidRep()
          Retrives the integer representation of OID
 java.lang.String getPassword()
          get the password.
 java.lang.String getRegisteredOid()
          getter for the OID which needs to be proxied.
 int[] getSubidList()
          Gets the subid list of the oid.
 java.lang.String getTableName()
          getter for the tablename in the database to which the queries are made for the snmp request.
 java.lang.String[] getUrlList()
          get the urlList.
 java.lang.String getUserName()
          get the userName.
protected  void processGetNextRequest(SnmpVarBind varb, AgentNode node, VarBindRequestEvent pe)
          This handles the get next requests from the manager.
protected  void processGetRequest(SnmpVarBind varb, AgentNode node, VarBindRequestEvent pe)
          This handles the get requests from the manager.
protected  void processSetRequest(SnmpVarBind varb, AgentNode node, VarBindRequestEvent pe)
          This handles the set requests from the manager.
 void removeRegistrationListener(RegistrationListener rl)
          This method is called by BeanInfo for removing Registration Listener from PduRequestHandler
 void setAgentMibOperations(com.adventnet.snmp.mibs.AgentMibOperations mibs)
          setter for AgentMibOperations.
 void setColumnProperty(java.lang.String columnName, java.lang.Integer maxLength)
          This method can be used to set the maximum length for a column value.
 void setDataBase(java.lang.String dataBase)
          To set the DataBase where the Table values are stored.
 void setDriverName(java.lang.String driverName)
          set the driverName.
 void setMibFiles(java.lang.String mibFiles)
          setter for the mib file name(s) for which this bean aware of.
 void setPassword(java.lang.String password)
          set the password.
 void setRegisteredOid(java.lang.String oid)
          setter for the OID which needs to be proxied.
 void setScalarProperties(java.lang.String url, java.lang.String userName, java.lang.String passwd, java.lang.String driverName, java.lang.String getStatement, java.lang.String setStatement, java.lang.String scalarOid, java.lang.String scalarName, java.lang.String scalarType, int scalarAccess)
          This method will be useful in database access through SNMP for the specified scalar object.
 void setSqlGetForScalar(java.lang.String sqlGetForScalar)
          setter for the Sql get statement for scalar objects.
 void setSqlSetForScalar(java.lang.String sqlSetForScalar)
          setter for the Sql get statement for scalar objects.
 void setTableName(java.lang.String tableName)
          setter for the tablename in the database to which the queries are made for the snmp request.
 void setTableProperties(java.lang.String url, java.lang.String userName, java.lang.String passwd, java.lang.String driverName, java.lang.String tableName, java.lang.String entryOID, java.lang.String[] columnNames, java.lang.String[] types, int[] access, int[] subidList, java.lang.String[] indexNames)
          This method will be useful in making database table SNMP accessible.
 void setTableProperties(java.lang.String url, java.lang.String userName, java.lang.String passwd, java.lang.String driverName, java.lang.String tableName, java.lang.String entryOID, java.lang.String[] columnNames, java.lang.String[] types, int[] access, int[] subidList, java.lang.String[] indexNames, java.lang.String[] externalmoduleName)
           
 void setUrlList(java.lang.String[] urlList)
          set the urlList.
 void setUserName(java.lang.String userName)
          set the userName.
 
Methods inherited from class com.adventnet.snmp.snmp2.agent.SimpleRequestHandler
addInstrumentHandler, addTableListener, addUpdateListener, getInstrument, getMibVarHash, getNextRequest, getNextRequest, getObjectHash, getObjectTypeHash, getRequest, getTableListener, getUpdateListener, isWriteEachTime, processGetNextRequest, processGetRequest, processSetRequest, removeUpdateListener, setRequest, setWriteEachTime, writeIntoFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_QUERY

static final int _QUERY
See Also:
Constant Field Values

_UPDATE

static final int _UPDATE
See Also:
Constant Field Values

registeredOid

java.lang.String registeredOid

jdbc

JDBCAdapter jdbc

oracleDb

boolean oracleDb

mysqlDb

boolean mysqlDb

msAccessDb

boolean msAccessDb

mibOps

com.adventnet.snmp.mibs.AgentMibOperations mibOps

tableNameIsNull

boolean tableNameIsNull

getNextFlag

boolean getNextFlag
Constructor Detail

SnmpDBAdaptor

public SnmpDBAdaptor()
constructor creates JDBCAdapter and initializes with default arguments. calls SimpleRequestHandler no argument constructor.

See Also:
SimpleRequestHandler
Method Detail

setRegisteredOid

public void setRegisteredOid(java.lang.String oid)
setter for the OID which needs to be proxied.

Parameters:
oid - value of the OID
See Also:
()

getRegisteredOid

public java.lang.String getRegisteredOid()
getter for the OID which needs to be proxied.

Returns:
the value of OID
See Also:
setRegisteredOid()

setTableName

public void setTableName(java.lang.String tableName)
setter for the tablename in the database to which the queries are made for the snmp request.

See Also:
getTableName()

getTableName

public java.lang.String getTableName()
getter for the tablename in the database to which the queries are made for the snmp request.

See Also:
setTableName()

setSqlGetForScalar

public void setSqlGetForScalar(java.lang.String sqlGetForScalar)
setter for the Sql get statement for scalar objects.

See Also:
setSqlSetForScalar()

setSqlSetForScalar

public void setSqlSetForScalar(java.lang.String sqlSetForScalar)
setter for the Sql get statement for scalar objects.

See Also:
setSqlGetForScalar()

getUrlList

public java.lang.String[] getUrlList()
get the urlList.

See Also:
setUrlList()

setUrlList

public void setUrlList(java.lang.String[] urlList)
set the urlList.

See Also:
getUrlList()

getDriverName

public java.lang.String getDriverName()
get the driverName.

See Also:
setDriverName()

setDriverName

public void setDriverName(java.lang.String driverName)
set the driverName.

See Also:
getDriverName()

getUserName

public java.lang.String getUserName()
get the userName.

See Also:
setUsrName()

setUserName

public void setUserName(java.lang.String userName)
set the userName.

See Also:
getUsrName()

getPassword

public java.lang.String getPassword()
get the password.

See Also:
setPassword()

setPassword

public void setPassword(java.lang.String password)
set the password.

See Also:
getPassword()

setDataBase

public void setDataBase(java.lang.String dataBase)
To set the DataBase where the Table values are stored. Sql Statements are formed based on this.


getAgentMibOperations

public com.adventnet.snmp.mibs.AgentMibOperations getAgentMibOperations()
Getter for AgentMibOperations.

See Also:
setAgentMibOperations()

setAgentMibOperations

public void setAgentMibOperations(com.adventnet.snmp.mibs.AgentMibOperations mibs)
setter for AgentMibOperations.

See Also:
getAgentMibOperations()

getMibFiles

public java.lang.String getMibFiles()
getter for the mib file name(s) for which this bean aware of.


setMibFiles

public void setMibFiles(java.lang.String mibFiles)
setter for the mib file name(s) for which this bean aware of.


addRegistrationListener

public void addRegistrationListener(RegistrationListener rl)
This method is called by BeanInfo for adding Registration Listener with PduRequestHandler

Overrides:
addRegistrationListener in class SimpleRequestHandler
Parameters:
rl - the registration listener for an OID.
See Also:
removeRegistrationListener()

removeRegistrationListener

public void removeRegistrationListener(RegistrationListener rl)
This method is called by BeanInfo for removing Registration Listener from PduRequestHandler

Overrides:
removeRegistrationListener in class SimpleRequestHandler
Parameters:
rl - the registration listener for an OID.
See Also:
addRegistrationListener()

setColumnProperty

public void setColumnProperty(java.lang.String columnName,
                              java.lang.Integer maxLength)
This method can be used to set the maximum length for a column value.

Parameters:
columnName - The name of the column
maxLength - The maximum length of the column value

getColumnProperty

public java.lang.Integer getColumnProperty(java.lang.String columnName)
This method can be used to get the maximum length for a column value.

Parameters:
columnName - The name of the column
Returns:
The maximum length of the column value in the database

processGetRequest

protected void processGetRequest(SnmpVarBind varb,
                                 AgentNode node,
                                 VarBindRequestEvent pe)
                          throws AgentSnmpException
This handles the get requests from the manager.

It overrides the method in com.adventnet.snmp.snmp2.agent.SimpleRequestHandler.java

Overrides:
processGetRequest in class SimpleRequestHandler
Parameters:
varb - The received varbind .
node - The node for which Get Request is to be done.
pe - The VarBind Request Event created by this Get request.
Throws:
AgentSnmpException - This wraps all the Exceptions thrown while Processing the Event.

processGetNextRequest

protected void processGetNextRequest(SnmpVarBind varb,
                                     AgentNode node,
                                     VarBindRequestEvent pe)
                              throws AgentSnmpException
This handles the get next requests from the manager.

It overrides the method in com.adventnet.snmp.snmp2.agent.SimpleRequestHandler.java

Overrides:
processGetNextRequest in class SimpleRequestHandler
Parameters:
varb - The received varbind.
node - The node for which Get Next Request is to be done.
pe - The VarBind Request Event created by this GetNext request.
Throws:
AgentSnmpException - This wraps all the Exceptions thrown while Processing the Event.

processSetRequest

protected void processSetRequest(SnmpVarBind varb,
                                 AgentNode node,
                                 VarBindRequestEvent pe)
                          throws AgentSnmpException
This handles the set requests from the manager.

It overrides the method in com.adventnet.snmp.snmp2.agent.SimpleRequestHandler.java

Overrides:
processSetRequest in class SimpleRequestHandler
Parameters:
varb - The received varbind.
node - The node for which Get Next Request is to be done.
pe - The VarBind Request Event created by this GetNext request.
Throws:
AgentSnmpException - This wraps all the Exceptions thrown while Processing the Event.

setTableProperties

public void setTableProperties(java.lang.String url,
                               java.lang.String userName,
                               java.lang.String passwd,
                               java.lang.String driverName,
                               java.lang.String tableName,
                               java.lang.String entryOID,
                               java.lang.String[] columnNames,
                               java.lang.String[] types,
                               int[] access,
                               int[] subidList,
                               java.lang.String[] indexNames)
This method will be useful in making database table SNMP accessible. The various properties of the database and table are passed as the argument to this method. The code snippet for usage of this method is :

SnmpDBAdaptor dbAdaptor1 = new SnmpDBAdaptor();

dbAdaptor1.setTableProperties(

 "jdbc:odbc:Elections_DB",
 "user",
 "passwd",
 "sun.jdbc.odbc.JdbcOdbcDriver",
 "ElectionResultsTable",
 ".1.3.6.1.4.1.2162.4.9.1.1",
 new String[]{"electionResultsId", "candidate", "percentage", "electoral"},
 new String[]{"INTEGER", "DisplayString", "INTEGER", "INTEGER"},
 new int[]{SnmpAPI.RONLY, SnmpAPI.RWRITE, SnmpAPI.RWRITE, SnmpAPI.RWRITE},
 new int[]{1,2,3,4},
 new String[]{"electionResultsId"}
 
);

dbAdaptor1.addRegistrationListener(hdlr);//hdlr is the RegistrationListener(PduRequestHandler)//

The above code allows us to register a database table for SNMP access.

Parameters:
url - the URL of the database
userName - the user name for the database access.
passwd - the password for the database access.
driverName - the name of the driver
tableName - the name of the table in the database
entryOID - the entry level OID of the table defined in the MIB relevant to the database table.
columnName - the string array specifying the name of the columns present in the table.
types - the string array specifying the SNMP data types of the columns respectively.
acces - the string array specifying the access of the column as specified by the static values in the class com.adventnet.snmp.snmp2.SnmpAPI
subidList - the subid's of the columns.
indexNames - the string array specifying the column names which are indexed for the table.

setTableProperties

public void setTableProperties(java.lang.String url,
                               java.lang.String userName,
                               java.lang.String passwd,
                               java.lang.String driverName,
                               java.lang.String tableName,
                               java.lang.String entryOID,
                               java.lang.String[] columnNames,
                               java.lang.String[] types,
                               int[] access,
                               int[] subidList,
                               java.lang.String[] indexNames,
                               java.lang.String[] externalmoduleName)

setScalarProperties

public void setScalarProperties(java.lang.String url,
                                java.lang.String userName,
                                java.lang.String passwd,
                                java.lang.String driverName,
                                java.lang.String getStatement,
                                java.lang.String setStatement,
                                java.lang.String scalarOid,
                                java.lang.String scalarName,
                                java.lang.String scalarType,
                                int scalarAccess)
This method will be useful in database access through SNMP for the specified scalar object. The various properties of the database and SQL command are passed as the argument to this method. The code snippet for usage of this method is :

SnmpDBAdaptor dbAdaptor1 = new SnmpDBAdaptor();

dbAdaptor1.setScalarTableProperties(

 "jdbc:odbc:Elections_DB",
 "user",
 "passwd",
 "sun.jdbc.odbc.JdbcOdbcDriver",
 "select sysdescr from admin_topoobject where name='Sudhir'",
 "update admin_topoobject set sysdescr = $value where name='Sudhir'",
 ".1.3.6.1.4.1.2162.4.9.5",
 "acreateTable",
 "DisplayString",
 SnmpAPI.RWRITE
 
);

dbAdaptor1.addRegistrationListener(hdlr);//hdlr is the RegistrationListener(PduRequestHandler)//

The above code allows us to register a database for SNMP access.

Parameters:
url - the URL of the database
userName - the user name for the database access.
passwd - the password for the database access.
driverName - the name of the driver
getStatement - the SQL statement for this scalar object which should be executed when a SNMP get request is made on this scalar object(i.e for the specified OID)
setStatement - the SQL statement for this scalar object which should be executed when a SNMP set request is made on this scalar object(i.e for the specified OID). The value sent during the SET is substitued for the $value and the SQL query is executed.
tableName - the name of the table in the database
scalarOid - the OID of the scalar defined in the MIB.
scalarName - the string specifying the name of the scalar object.
scalarType - the string specifying the SNMP data type of the scalar object.
scalarAcces - the string specifying the access of the scalar as specified by the static values in the class com.adventnet.snmp.snmp2.SnmpAPI

getOidRep

public int[] getOidRep()
Description copied from class: SimpleRequestHandler
Retrives the integer representation of OID

Overrides:
getOidRep in class SimpleRequestHandler
Returns:
the integer array of OID

getSubidList

public int[] getSubidList()
Gets the subid list of the oid.

Overrides:
getSubidList in class SimpleRequestHandler
Returns:
the integer array of subid list