HOME

com.ireasoning.protocol.snmp
Class SnmpAgentConfig

java.lang.Object
  extended bycom.ireasoning.protocol.snmp.DefaultAgentConfig
      extended bycom.ireasoning.protocol.snmp.SnmpAgentConfig
All Implemented Interfaces:
Serializable

public class SnmpAgentConfig
extends DefaultAgentConfig

This class represents agent's XML configuration data.

Any changes to the state of this object will result in invocation of save(). So you do not have to call save() method explicitly in most cases.

Sample Code:

  SnmpAgentConfig config = new SnmpAgentConfig("d:/config/snmpagent.xml");
  config.reloadConfig();
  ...
 

See Also:
Serialized Form

Constructor Summary
SnmpAgentConfig()
          Default config file
SnmpAgentConfig(Object fileName)
          Constructs a SnmpAgentConfig object and loads the passed fileName
SnmpAgentConfig(SnmpAgentConfig conf)
          Copy constructor
 
Method Summary
protected  boolean doAddGroup(Map attrs)
          Adds a group, views associated with this group should already exist.
protected  boolean doAddProxy(ProxyEntry entry)
          Adds a new proxy to the config settings
protected  boolean doAddTrapSink(Map attributes)
          Adds a trapSink or snmpV3TrapSink element
protected  boolean doAddUser(Map attrs)
          Adds a user.
protected  boolean doAddView(Map attrs)
          Adds a view
protected  Map doGetPropertiesProps()
          Returns a Map object which stores the attributes of properties node
protected  Map[] doGetProxyProps()
          Return proxies' properties
protected  Map[] doGetSnmpV3TrapSinkProps()
          Returns trapsinks' properties
protected  Map doGetTrapProxyProps()
          Returns trap proxy's properties
protected  Map[] doGetTrapSinkProps()
          Returns non-SNMPv3 trapsinks' properties
protected  void doReloadConfig()
          Reloads config settings
protected  boolean doRemoveGroup(String groupName)
          Removes a group.
protected  boolean doRemoveProxy(ProxyEntry entry)
          Adds a new proxy to the config settings
protected  boolean doRemoveTrapSink(String trapSinkHostName, int trapSinkPort, int trapSinkVersion)
          Removes a trapSink or snmpV3TrapSink element
protected  boolean doRemoveUser(String userName)
          Removes a user
protected  boolean doRemoveView(String viewName)
          Removes a view.
protected  void doSave()
          Saves config file.
 Map[] getCommunityViews()
          Returns communityView's properties
 String getFileName()
          Returns the config file name
 Map getGroupAttributes(String groupName)
          Returns the group's properties
 Map[] getGroups()
          Returns groups' properties
 InputStream getInputStream()
          Returns the InputStream of config.
 long getSaveDelayTime()
           
 Map getUserAttributes(String userName)
          Returns properties of a user whose name is the passed userName
 Map[] getUsers()
          Returns users' properties
 Map[] getViewAttributes(String viewName)
           
 Map[] getViews()
          Returns views' properties
protected  void postReloadConfig()
          It's invoked after reloadConfig() method is called
 void reloadConfig(InputStream istream)
          Reloads config from an InputStream object.
 void save(OutputStream ostream)
          Saves config file.
protected  boolean setAttributeValue(String elementName, Map keyvals, String attributeName, String attributeValue)
          Sets element node's attribute's value.
 void setSaveDelayTime(long time)
          Delays for a while then do save.
 
Methods inherited from class com.ireasoning.protocol.snmp.DefaultAgentConfig
addGroup, addPropertyChangeListener, addProxy, addReadCommunity, addTrapSink, addTrapSink, addUser, addView, addWriteCommunity, getEngineBoots, getEngineID, getInformRetries, getInformTimeout, getIpAddress, getManagerIpAddresses, getMasterAgentPort, getMaxPacketSize, getMaxThreadCount, getPort, getProxies, getReadCommunities, getReloadConfigOID, getRemoteMasterAgentIpAddress, getRemoteMasterAgentPort, getSubagentIpAddresses, getSysObjectID, getTrapSinks, getUnderCreationTimeWindow, getVersion, getWriteCommunities, isAuthTrapEnabled, isUseThreadPool, main, reloadConfig, removeGroup, removePropertyChangeListener, removeProxy, removeTrapSink, removeTrapSink, removeUser, removeView, save, setEngineBoots, setEngineID, setGroupAttributeValue, setInformRetries, setInformTimeout, setIpAddress, setManagerIpAddresses, setManagerIpAddresses, setMasterAgentPort, setMaxPacketSize, setPort, setProperty, setPropertyValue, setReadCommunities, setReloadConfigOID, setRemoteMasterAgentIpAddress, setRemoteMasterAgentPort, setSubagentIpAddresses, setSubagentIpAddresses, setSysObjectID, setUnderCreationTimeWindow, setUserAttributeValue, setUseThreadPool, setVersion, setWriteCommunities
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnmpAgentConfig

public SnmpAgentConfig()
Default config file


SnmpAgentConfig

public SnmpAgentConfig(Object fileName)
                throws IOException
Constructs a SnmpAgentConfig object and loads the passed fileName


SnmpAgentConfig

public SnmpAgentConfig(SnmpAgentConfig conf)
                throws IOException
Copy constructor

Method Detail

getFileName

public String getFileName()
Returns the config file name

It returns null if config was loaded from an InputStream object.


getInputStream

public InputStream getInputStream()
Returns the InputStream of config.

It returns null if config was loaded from a file.


setAttributeValue

protected boolean setAttributeValue(String elementName,
                                    Map keyvals,
                                    String attributeName,
                                    String attributeValue)
Sets element node's attribute's value.

Specified by:
setAttributeValue in class DefaultAgentConfig
Parameters:
keyvals - key/value pairs used to distinguish nodes with identical node names
elementName - element name
attributeName - attribute's name
attributeValue - attribute's value

doAddTrapSink

protected boolean doAddTrapSink(Map attributes)
Description copied from class: DefaultAgentConfig
Adds a trapSink or snmpV3TrapSink element

Specified by:
doAddTrapSink in class DefaultAgentConfig
Parameters:
attributes - a Map object containing the name/value of attributes, such as "verion" -- "2"

doRemoveTrapSink

protected boolean doRemoveTrapSink(String trapSinkHostName,
                                   int trapSinkPort,
                                   int trapSinkVersion)
Description copied from class: DefaultAgentConfig
Removes a trapSink or snmpV3TrapSink element

Specified by:
doRemoveTrapSink in class DefaultAgentConfig
Parameters:
trapSinkHostName - host name or ip address of trap receiver
trapSinkPort - port number of trap receiver
trapSinkVersion - version of trapSink. 1: SNMPv1, 2: SNMPv2c, 3: SNMPv3
Returns:
true if it's been successfully removed.

getViews

public Map[] getViews()
Description copied from class: DefaultAgentConfig
Returns views' properties

Specified by:
getViews in class DefaultAgentConfig
Returns:
null if no view. Otherwise it returns a Map array of view's properties

getViewAttributes

public Map[] getViewAttributes(String viewName)

doAddView

protected boolean doAddView(Map attrs)
Description copied from class: DefaultAgentConfig
Adds a view

Specified by:
doAddView in class DefaultAgentConfig
Parameters:
attrs - a map containing view's attributes
Returns:
true if view is successfully added; false otherwise(because some of the attributes are not present)

doRemoveView

protected boolean doRemoveView(String viewName)
Description copied from class: DefaultAgentConfig
Removes a view. Returns true if group is successfully removed. And if the view is removed, all the groups associated with this view will be removed as well.

Specified by:
doRemoveView in class DefaultAgentConfig

getGroups

public Map[] getGroups()
Returns groups' properties

Specified by:
getGroups in class DefaultAgentConfig
Returns:
null if no group. Otherwise it returns a Map array of group's properties

getGroupAttributes

public Map getGroupAttributes(String groupName)
Returns the group's properties

Parameters:
groupName - group's name

doAddGroup

protected boolean doAddGroup(Map attrs)
Description copied from class: DefaultAgentConfig
Adds a group, views associated with this group should already exist.

Specified by:
doAddGroup in class DefaultAgentConfig
Returns:
true if group is successfully added; false otherwise (Usually it's because the corresponding view does not exist, or some of the necessary attributes are not present.)

doRemoveGroup

protected boolean doRemoveGroup(String groupName)
Removes a group. Returns true if group is successfully removed. And if group is removed, all the users in this group will be removed as well.

Specified by:
doRemoveGroup in class DefaultAgentConfig

getCommunityViews

public Map[] getCommunityViews()
Returns communityView's properties

Overrides:
getCommunityViews in class DefaultAgentConfig
Returns:
null if no communityView. Otherwise it returns a Map array of communityView's properties

getUsers

public Map[] getUsers()
Returns users' properties

Specified by:
getUsers in class DefaultAgentConfig
Returns:
null if no user. Otherwise it returns a Map array of user's properties

getUserAttributes

public Map getUserAttributes(String userName)
Returns properties of a user whose name is the passed userName

Parameters:
userName - user's name

doAddUser

protected boolean doAddUser(Map attrs)
Adds a user. The group this new user belong to should already exist. New user is saved to the config file.

Specified by:
doAddUser in class DefaultAgentConfig
Parameters:
attrs - user's attributes, such as "name", "authPassword", "privPassword", etc
Returns:
true if user is successfully added. false otherwise (usually it's because the corresponding group does not exist, or some of the attributes are not present)

doRemoveUser

protected boolean doRemoveUser(String userName)
Removes a user

Specified by:
doRemoveUser in class DefaultAgentConfig
Returns:
true if user is successfully removed

setSaveDelayTime

public void setSaveDelayTime(long time)
Delays for a while then do save. The default value is no delay.

Parameters:
time - delay time, in milliseconds. If it's 0, save() will be invoked right away. If it's a negative number, save() will never occur.
See Also:
DefaultAgentConfig.save()

getSaveDelayTime

public long getSaveDelayTime()

save

public void save(OutputStream ostream)
          throws IOException
Saves config file. Config file won't be updated immediately unless you change the default delay time.

Parameters:
ostream - OutputStream object for saving config. If it's null, config can't be saved. ostream will be closed when save is finished
Throws:
IOException
See Also:
setSaveDelayTime(long)

doSave

protected void doSave()
               throws IOException
Saves config file. Config file won't be updated immediately unless you change the default delay time.

Specified by:
doSave in class DefaultAgentConfig
Throws:
IOException
See Also:
setSaveDelayTime(long)

reloadConfig

public void reloadConfig(InputStream istream)
                  throws IOException
Reloads config from an InputStream object. PropertyChangeListener will receive a null event

Parameters:
istream - an InputStream object from which config is loaded
Throws:
IOException
See Also:
DefaultAgentConfig.reloadConfig()

doReloadConfig

protected void doReloadConfig()
                       throws IOException
Description copied from class: DefaultAgentConfig
Reloads config settings

Specified by:
doReloadConfig in class DefaultAgentConfig
Throws:
IOException

postReloadConfig

protected void postReloadConfig()
Description copied from class: DefaultAgentConfig
It's invoked after reloadConfig() method is called

Overrides:
postReloadConfig in class DefaultAgentConfig

doGetPropertiesProps

protected Map doGetPropertiesProps()
Description copied from class: DefaultAgentConfig
Returns a Map object which stores the attributes of properties node

Specified by:
doGetPropertiesProps in class DefaultAgentConfig

doGetTrapSinkProps

protected Map[] doGetTrapSinkProps()
Returns non-SNMPv3 trapsinks' properties

Specified by:
doGetTrapSinkProps in class DefaultAgentConfig
Returns:
null if no trapsink. Otherwise it returns a Map array of trapsink's properties

doGetTrapProxyProps

protected Map doGetTrapProxyProps()
Description copied from class: DefaultAgentConfig
Returns trap proxy's properties

Specified by:
doGetTrapProxyProps in class DefaultAgentConfig

doGetProxyProps

protected Map[] doGetProxyProps()
Description copied from class: DefaultAgentConfig
Return proxies' properties

Specified by:
doGetProxyProps in class DefaultAgentConfig

doGetSnmpV3TrapSinkProps

protected Map[] doGetSnmpV3TrapSinkProps()
Returns trapsinks' properties

Specified by:
doGetSnmpV3TrapSinkProps in class DefaultAgentConfig
Returns:
null if no trapsink. Otherwise it returns a Map array of trapsink's properties

doAddProxy

protected boolean doAddProxy(ProxyEntry entry)
Adds a new proxy to the config settings

Specified by:
doAddProxy in class DefaultAgentConfig

doRemoveProxy

protected boolean doRemoveProxy(ProxyEntry entry)
Adds a new proxy to the config settings

Specified by:
doRemoveProxy in class DefaultAgentConfig

HOME

Copyright © 2002 iReasoning Inc. All Rights Reserved.