WebNMS 5 API Specification

com.adventnet.management.cli
Class CLIProperty

java.lang.Object
  |
  +--com.adventnet.management.Property
        |
        +--com.adventnet.management.cli.CLIProperty
All Implemented Interfaces:
java.io.Serializable

public class CLIProperty
extends Property
implements java.io.Serializable

This is the implementation of com.adventnet.management.Property for CLI protocol. It encapsulates the Information about the device like, name of the device, port no to contact the device etc., and the command(s) to be executed after making the connection to the device. The CLIProperty can be used for two purposes. One of these is for opening a new CLI Session and the other purpose is to send a CLI command/request. In both cases certain parameters have to be set on the CLIProperty instance.

For example to establish a CLI Session the following parameters are required:

  // Create a new CLIProperty
  CLIProperty prop = new CLIProperty();
  prop.setTargetHost("testhost"); // sets the target host name
  prop.setLoginName("guest"); // sets the login name
  prop.setPassword("guest"); // sets the password
  
The other parameters (like login Prompt, password prompt and shell prompt) if not explicitly set take their default values.

For example to send a CLI request/command the following parameters are required in addition to the TargetHost and TargetPort:

  // Create a new CLIProperty
  CLIProperty prop = new CLIProperty();
  // Create a Command List
  prop.setTargetHost("testhost"); // set the target host
  prop.setTargetPort("23"); //set the target port
  String[] commandList = { "date" , "who" }; // eg commands
  prop.setCommandList(commandList); // sets the list of commands
  // Create a prompt list
  String[] promptList = { "$","#" }; // eg prompts
  prop.setPromptList(promptList); // sets the Prompt List
  
The above property can then be used to send the list of CLI commands specified in the command list

See Also:
Serialized Form

Fields inherited from class com.adventnet.management.Property
OP_READ, OP_WRITE, RESULT_INT, RESULT_LONG, RESULT_OBJECT, RESULT_STRING
 
Constructor Summary
CLIProperty()
          Creates an instance of CLIProperty setting the Protocol type field to 'CLI'.
 
Method Summary
 void copy(Property property)
          Copy the property value to this instance.
 java.lang.String getCombinedPropKey()
          This method is not being used in CLI protocol.
 java.lang.String getCommand()
          Getter for Command.
 java.lang.String[] getCommandList()
          Gets the list of commands to be executed on the Device.
 java.lang.String getEventKey()
          This method will return the sessionId as the key for the event generated.
 java.lang.String getLoginName()
          Getter for LoginName.
 java.lang.String getLoginPrompt()
          Getter for Login Prompt.
 java.lang.String getPassword()
          Getter for Password.
 java.lang.String getPasswordPrompt()
          Getter for Password Prompt.
 java.util.Properties getPromptAction()
          Gets the prompt and its corresponding action.
 java.lang.String[] getPromptList()
          Gets the Prompt list.
 java.util.Hashtable getProperties()
          This method will return a Hashtable which will have the property values with the corresponding keys.
 java.lang.String getSessionId()
          Gets the sessionId that has been set by the user.
 java.lang.String getSessionKey()
          Returns the session key associated with a particular cli property.
 java.lang.String getShellPrompt()
          Getter for Shell Prompt.
 java.lang.String getTargetHost()
          Gets the target host.
 java.lang.String getTargetPort()
          Getter for the Target port.
 boolean isPerformPing()
          Gets the perform ping flag.
 void setCommand(java.lang.String command)
          Setter for Command.
 void setCommandList(java.lang.String[] list)
          Sets the list of commands to be executed in the Target Host.
 void setLoginName(java.lang.String loginName)
          Setter for LoginName.
 void setLoginPrompt(java.lang.String loginPrompt)
          Setter for LoginPrompt.
 void setPassword(java.lang.String passwd)
          Setter for Password.
 void setPasswordPrompt(java.lang.String passwordPrompt)
          Setter for PasswordPrompt.
 void setPerformPing(boolean flag)
          Sets the perform ping flag.
 void setPromptAction(java.util.Properties prop)
          This method is used for setting the possible prompts and action/command to be executed when the prompt is encountered.
 void setPromptList(java.lang.String[] list)
          Sets the list of prompt(s) to be expected after the end of each and every command corresponding to the command provided in the setCommandList method.
 void setProperties(java.util.Hashtable prop)
          This method will set a list of properties on this CLIProperty instance.
 void setSessionId(java.lang.String sessId)
          Sets the Session Id.
 void setShellPrompt(java.lang.String shellPrompt)
          Setter for ShellPrompt.
 void setTargetHost(java.lang.String host)
          Sets the target host.
 void setTargetPort(java.lang.String p)
          Setter for the Target port.
 
Methods inherited from class com.adventnet.management.Property
addSubProperty, getComponent, getFilterClass, getFilterParameters, getGroupName, getMethodName, getMethodParameterClassNames, getMethodParameterValues, getMethodResultParameterIndex, getOperationType, getPollInterval, getPropertyType, getProtocolPDU, getRequestID, getResultType, getRetries, getTimeout, getUserProperties, getUserProperty, getWriteType, getWriteTypes, getWriteValue, getWriteValues, removeUserProperty, setComponent, setFilterClass, setFilterParameters, setGroupName, setMethodDetail, setMethodName, setOperationType, setPollInterval, setPropertyType, setProtocolPDU, setRequestID, setResultType, setRetries, setTimeout, setUserProperty, setWriteType, setWriteTypes, setWriteValue, setWriteValues
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CLIProperty

public CLIProperty()
Creates an instance of CLIProperty setting the Protocol type field to 'CLI'.
Method Detail

setTargetHost

public void setTargetHost(java.lang.String host)
Sets the target host.
Parameters:
host - host name of the target CLI device which can be a either the * dns name or ip address in string format like 100.100.100.100.

getTargetHost

public java.lang.String getTargetHost()
Gets the target host.
Returns:
the dns name or ip address of the target device whichever has been set.

setCommandList

public void setCommandList(java.lang.String[] list)
Sets the list of commands to be executed in the Target Host. This can be used when multiple CLI commands need to be executed through syncSend() or send() on the device. Each command will be executed in succession in the same order as in the list.
Parameters:
list - of commands to be executed after making the connection to the device.

getCommandList

public java.lang.String[] getCommandList()
Gets the list of commands to be executed on the Device.
Returns:
list of commands to be executed after making the connection to the device.

setPromptList

public void setPromptList(java.lang.String[] list)
Sets the list of prompt(s) to be expected after the end of each and every command corresponding to the command provided in the setCommandList method. The CLI API waits for the prompt to know the termination of the command's response. Each command may have a seperate prompt. This list should map one-to-one with the command list i.e. for every command in the command list, corresponding prompt has to be specified in the prompt list. Even if all commands have the same prompt they have to be set separately in this list.
Parameters:
list - of prompt to expected to know the end of the execution of the command given.

getPromptList

public java.lang.String[] getPromptList()
Gets the Prompt list.
Returns:
an array of Prompt Strings which correspond to the Command list.

setCommand

public void setCommand(java.lang.String command)
Setter for Command. The field Command represents the CLI command to be executed in the Device, after establishing the connection. In this case the prompt list set using setPromptList will have only one entry for the prompt. If more than one command needs to be executed use the setCommandList method.
Parameters:
command - to be executed after making the connection to the device.
See Also:
setCommandList(String[] cmdList)

getCommand

public java.lang.String getCommand()
Getter for Command. The field Command represents the command to be executed in the Device, after establishing the connection. If the command list has been set with more than one command then this call will return the first command in the list.
Returns:
command to be executed after making the connection to the device.

setTargetPort

public void setTargetPort(java.lang.String p)
Setter for the Target port. The port value specifies the port to which the telnet connection is to be established with the Device. The port value should be a valid Integer between 1 and 65535 inclusive. If this field is not set, then the default value 23 is taken.
Parameters:
p - the port value in string format

getTargetPort

public java.lang.String getTargetPort()
Getter for the Target port. The port value specifies the port to which telnet connection is to be established with the Device.
Returns:
the port value in string format

setPassword

public void setPassword(java.lang.String passwd)
Setter for Password. Password field represents the Password to be used while making connection to the device as user @LoginName.
Parameters:
passwd, - the password reqd. to connect to the device as LoginName.

getPassword

public java.lang.String getPassword()
Getter for Password. Password field represents the Password to be used while making connection to the device as user @LoginName.
Returns:
the password used to connect to the device.

setLoginName

public void setLoginName(java.lang.String loginName)
Setter for LoginName. LoginName field represents the user/login name to be used while making connection to the device.
Parameters:
loginName, - the username reqd. to connect to the device.

getLoginName

public java.lang.String getLoginName()
Getter for LoginName. LoginName field represents the user/login name to be used while making connection to the device.
Returns:
the username/loginname required to connect to the device.

getLoginPrompt

public java.lang.String getLoginPrompt()
Getter for Login Prompt. LoginPrompt field represents the prompt which asks for the user to enter the user/login Name to log in to the device.
Returns:
the prompt which requests the user to enter the loginName.

setLoginPrompt

public void setLoginPrompt(java.lang.String loginPrompt)
Setter for LoginPrompt. LoginPrompt field represents the prompt which asks for the user to enter the user/login Name to log in to the device. If this field is set to empty string then the login is not performed. If this field is not set, then the default value 'login' is taken.
Parameters:
loginPrompt - the prompt which requests the user to enter the loginName.

getPasswordPrompt

public java.lang.String getPasswordPrompt()
Getter for Password Prompt. Password Prompt field represents the prompt which asks for the user to enter the password to log in to the device.
Returns:
the prompt which requests the user to enter the password.

setPasswordPrompt

public void setPasswordPrompt(java.lang.String passwordPrompt)
Setter for PasswordPrompt. PasswordPrompt field represents the prompt which asks for the user to enter the password to log in to the device. If the Device doesn't has any authentication then make this field empty(""). If this field is not set, then the default value 'Password' is taken.
Parameters:
passwordPrompt, - the prompt which requests the user to enter the password.

getShellPrompt

public java.lang.String getShellPrompt()
Getter for Shell Prompt. Shell Prompt field represents the prompt which informs the users that they have logged in to the device.
Returns:
the prompt which informs the user about the successful login and asks the user to enter the commands.

setShellPrompt

public void setShellPrompt(java.lang.String shellPrompt)
Setter for ShellPrompt. ShellPrompt field represents the prompt which informs the users that they have logged in to the device. If this field is not set, then the default value '$' is taken.
Parameters:
shellPrompt - the prompt which informs the user about the successful login and asks the user to enter the commands.

getPromptAction

public java.util.Properties getPromptAction()
Gets the prompt and its corresponding action. This is the list of prompts, one of which will be returned by the device after execution of a command. The prompts can also have a command/action defined for it. When one of the prompts is encountered, the command corresponding to the prompt is sent by the session. When no action or command is defined for a prompt, it will have an empty value and this will be assumed as the command prompt.
Returns:
prompts and its command as a Properties object.
See Also:
setPromptAction(Properties)

setPromptAction

public void setPromptAction(java.util.Properties prop)
This method is used for setting the possible prompts and action/command to be executed when the prompt is encountered. The session will wait for one of the prompts to be returned by the device for a command sent. If any command is to be sent for the prompt received, the command can be set as the value of the prompt.
        prop.setProperty(prompt, cmd);
 
When no action or command is defined for a prompt, it will be assumed as the command prompt. Note that the suffix, if any, should also be given in the command set for the prompt, as no suffix would be appended to the command, when it is sent.
Parameters:
prop - prompts and its command as a Properties object.
See Also:
#getCLIPromptAction()

isPerformPing

public boolean isPerformPing()
Gets the perform ping flag. This is used to check whether ping is to be done for the host, before establishing a connection with it.
Returns:
a boolean value to indicate if ping needs to be done.

setPerformPing

public void setPerformPing(boolean flag)
Sets the perform ping flag. When this is enabled, a ping is done to check if the device is alive before establishing a connection with it. Only if the ping succeeds a connection is opened to the device, otherwise a ConnectException is thrown.
Parameters:
flag - a boolean value to enable/disable ping.

copy

public void copy(Property property)
Copy the property value to this instance. Copies the list of properties provided in the argument to this CLIProperty instance.
Overrides:
copy in class Property
Parameters:
property - the property object containing the properties to be set

setProperties

public void setProperties(java.util.Hashtable prop)
This method will set a list of properties on this CLIProperty instance. This is a convenience method for setting all the properties in one single call. The Hashtable contains the various property fields present in this class and their values. The property names i.e the key values that should be present in the hashtable and their meaning are given below:

  PropertyName    	 Meaning
  host			 TargetHost 
  port			 TargetPort 
  loginPrompt		 login Prompt 
  loginName		 login name to be used 
  password		 The password for login 
  passwordPrompt	 The password prompt to be used 
  shellPrompt		 The shell prompt to be used
  timeout         	 The request timeout
  commandList          The list of commands to be sent
  promptList           The prompts that will be received for the command sent.
  promptAction         The prompt and action to be performed for it.
  performPing          The flag to indicate if ping is to be done.
 
For example:
  // Create the Hashtable for setting the properties
	Hashtable table = new Hashtable();
   // Set the various parameters
	table.put("host","test");
	table.put("port","23");
	table.put("loginName","guest");
	table.put("password, "gugest");
	// Create a new CLIProperty
	CLIProperty prop = new CLIProperty();
	// Set all the properties
	prop.setProperties(table);
 
The above code sets the basic parameters like the host, port, login name and password.
Overrides:
setProperties in class Property
Parameters:
prop - the hashtable containing the various property names (as keys) and their values.

getProperties

public java.util.Hashtable getProperties()
This method will return a Hashtable which will have the property values with the corresponding keys. The meaning of the different parameters are explained in the setProperties() method.
Overrides:
getProperties in class Property
Returns:
the hashtable containing the property name, value pair.
See Also:
setProperties(Hashtable prop)

setSessionId

public void setSessionId(java.lang.String sessId)
Sets the Session Id. This is the unique ID that can be used to identify the particular CLI session opened with this property. Users can set this field with a unique id.
Overrides:
setSessionId in class Property
Parameters:
sessionID - the session ID

getSessionId

public java.lang.String getSessionId()
Gets the sessionId that has been set by the user. If this has not been set by the user it will be constructed internally from the target host, port and login name. Format of the id returned in such cases will be 'TargetHostPortLoginName'. For eg testrouter23guest.
Overrides:
getSessionId in class Property
Returns:
the session id

getCombinedPropKey

public java.lang.String getCombinedPropKey()
This method is not being used in CLI protocol. It always returns null.
Overrides:
getCombinedPropKey in class Property
Returns:
null string

getEventKey

public java.lang.String getEventKey()
This method will return the sessionId as the key for the event generated.
Overrides:
getEventKey in class Property
Returns:
the sessionId as event key.

getSessionKey

public java.lang.String getSessionKey()
Returns the session key associated with a particular cli property. In the CLI implementation this is the same as the Session id.
Overrides:
getSessionKey in class Property
Returns:
the session key

WebNMS 5 API Specification