com.agentpp.explorer.script.external
Interface Utils


public interface Utils

This interface describes the methods available in the "utils" context of the MIB Explorer scripting programming interface. The Utils context provides utility services to temporarily cease script execution, stop script execution, create random integers, and to create an empty Vector (e.g., to collect response PDUs).

Since:
1.5
Version:
2.2.2

Method Summary
 java.lang.Integer asInteger(java.lang.String integerString)
          Returns the Integer representation of the supplied number string.
 java.util.List asList(byte[] array)
          Converts the supplied byte array to a List.
 java.util.List asList(char[] array)
          Converts the supplied character array to a List.
 java.util.List asList(double[] array)
          Converts the supplied double array to a List.
 java.util.List asList(int[] array)
          Converts the supplied integer array to a List.
 java.util.List asList(long[] array)
          Converts the supplied long array to a List.
 java.util.List asList(java.lang.Object[] array)
          Converts the supplied object array to a List.
 java.util.List asList(short[] array)
          Converts the supplied short array to a List.
 void clearOutput()
          Clears the script's output buffer.
 java.util.Vector createVector()
          Creates an empty Vector.
 java.lang.String downloadFile(java.lang.String url, java.lang.String targetFileName)
          Downloads the file specified by the supplied URL to the given file name on the local system.
 java.lang.String downloadString(java.lang.String url)
          Downloads the content from the specified URL using the default character set in MIB Explorer's locale.
 java.util.Vector exec(java.util.List cmdarray)
          Executes the specified command and arguments in a separate process.
 java.util.Vector exec(java.util.List cmdarray, java.util.List envp)
          Executes the specified command arguments in a separate process with the specified environment.
 java.lang.String getCharacter(int uniCode)
          Gets the character with the specified unicode.
 LoopCondition loopCondition()
          Creates a loop condition which can be used in a VTL #foreach statement to control loop termination by a boolean expression.
 java.lang.Integer rand(int n)
          Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
 boolean saveOutput(java.lang.String fileName)
          Saves the content of the current script's output buffer to the supplied file.
 boolean sendEmail(java.lang.String smtpHost, java.lang.String fromAddress, java.lang.String to, java.lang.String charSet, java.lang.String subject, java.lang.String contentType, java.lang.String body)
          Sends a text email to a given list of receipiens using unauthenticated SMTP.
 boolean sendEmail(java.lang.String smtpHost, java.lang.String smtpUser, java.lang.String smtpPassword, java.lang.String fromAddress, java.lang.String to, java.lang.String charSet, java.lang.String subject, java.lang.String contentType, java.lang.String body)
          Sends a text email to a given list of receipiens using authenticated SMTP.
 void sleep(int millis)
          Causes the currently executing script to sleep (temporarily cease execution) for the specified number of milliseconds.
 void stop()
          Stop the execution of the script.
 java.lang.String[] toStringArray(java.util.List list)
          Converts a List (i.e.
 

Method Detail

createVector

java.util.Vector createVector()
Creates an empty Vector. This vector can be used to collect any data for further script processing.

Returns:
an empty Vector.

toStringArray

java.lang.String[] toStringArray(java.util.List list)
Converts a List (i.e. Vector) to a String array.

Parameters:
list - a List of arbitrary objects.
Returns:
an array of strings by invoking the toString() method of each object in list.
Since:
1.5.10

getCharacter

java.lang.String getCharacter(int uniCode)
Gets the character with the specified unicode.

Parameters:
uniCode - a value between 0 and 65535 (two bytes).
Returns:
a String representing the specified character.

sleep

void sleep(int millis)
Causes the currently executing script to sleep (temporarily cease execution) for the specified number of milliseconds.

Parameters:
millis - the length of time to sleep in milliseconds.

stop

void stop()
Stop the execution of the script.


rand

java.lang.Integer rand(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

Parameters:
n - the bound on the random number to be returned. Must be positive.
Returns:
a pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive).

exec

java.util.Vector exec(java.util.List cmdarray,
                      java.util.List envp)
Executes the specified command arguments in a separate process with the specified environment.

Given a list of strings cmdarray, representing the tokens of a command line, and a list of strings envp, representing "environment" variable settings, this method creates a new process in which to execute the specified command.

If envp is null, the subprocess inherits the environment settings of MIB Explorer.

The exec methods may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Win32, or shell scripts. The created subprocess does not have its own terminal or console.

Parameters:
cmdarray - a list of strings containing the command to call and its arguments.
envp - a list of strings, each element of which has environment variable settings in format name=value.
Returns:
a List of an Integer value followed by two strings: The first element is an integer value represents the exit code of the process. The second element is a string containing the output of the started process and third is a string containing the error output of the process. If the command could not be executed, null is returned.
Since:
1.5.10

exec

java.util.Vector exec(java.util.List cmdarray)
Executes the specified command and arguments in a separate process.

The command specified by the tokens in cmdarray is executed as a command in a separate process. This has exactly the same effect as exec(cmdarray, null).

Parameters:
cmdarray - a list of strings containing the command to call and its arguments.
Returns:
a List of an Integer value followed by two strings: The first element is an integer value represents the exit code of the process. The second element is a string containing the output of the started process and third is a string containing the error output of the process. If the command could not be executed, null is returned.
Since:
1.5.10

sendEmail

boolean sendEmail(java.lang.String smtpHost,
                  java.lang.String smtpUser,
                  java.lang.String smtpPassword,
                  java.lang.String fromAddress,
                  java.lang.String to,
                  java.lang.String charSet,
                  java.lang.String subject,
                  java.lang.String contentType,
                  java.lang.String body)
Sends a text email to a given list of receipiens using authenticated SMTP.

Parameters:
smtpHost - the SMTP host to use, for example "mailserv.my-company.com".
smtpUser - the user at the SMTP host.
smtpPassword - the password for the above user.
fromAddress - the from address to be used, for example "myname@my-company.com".
to - a comma separated list of destination email addresses.
charSet - the character set to be used to encode the subject and the body. If charSet is null or the empty string "", then the default character set for the current locale is used.
subject - the subject to be used. It will be encoded using the specified character set.
contentType - the content ID of the message body. If this parameter is null or the zero length string, plain text is used as the content type. Other possible values are for example "text/html" for a HTML body.
body - the body text. used. It will be encoded using the specified character set.
Returns:
true if the email has been sent, otherwise false is returned and a detailed error message is logged.
Since:
1.5.10

sendEmail

boolean sendEmail(java.lang.String smtpHost,
                  java.lang.String fromAddress,
                  java.lang.String to,
                  java.lang.String charSet,
                  java.lang.String subject,
                  java.lang.String contentType,
                  java.lang.String body)
Sends a text email to a given list of receipiens using unauthenticated SMTP.

Parameters:
smtpHost - the SMTP host to use, for example "mailserv.my-company.com".
fromAddress - the from address to be used, for example "myname@my-company.com".
to - a comma separated list of destination email addresses.
charSet - the character set to be used to encode the subject and the body. If charSet is null or the empty string "", then the default character set for the current locale is used.
subject - the subject to be used. It will be encoded using the specified character set.
contentType - the content ID of the message body. If this parameter is null or the zero length string, plain text is used as the content type. Other possible values are for example "text/html" for a HTML body.
body - the body text. used. It will be encoded using the specified character set.
Returns:
true if the email has been sent, otherwise false is returned and a detailed error message is logged.
Since:
1.5.10

clearOutput

void clearOutput()
Clears the script's output buffer. Calling this method in an alarm script has no effect.

Since:
1.5.11

saveOutput

boolean saveOutput(java.lang.String fileName)
Saves the content of the current script's output buffer to the supplied file.

Parameters:
fileName - the path of a writable file. If the file does not exist it will be created.
Returns:
true if the output could be saved, false otherwise.
Since:
1.5.11

asList

java.util.List asList(java.lang.Object[] array)
Converts the supplied object array to a List.

Parameters:
array - an Object array.
Returns:
a List containing the array's elements.
Since:
2.0

asList

java.util.List asList(int[] array)
Converts the supplied integer array to a List.

Parameters:
array - an integer array.
Returns:
a List containing the array's elements.
Since:
2.0

asList

java.util.List asList(byte[] array)
Converts the supplied byte array to a List.

Parameters:
array - a byte array.
Returns:
a List containing the array's elements.
Since:
2.0

asList

java.util.List asList(long[] array)
Converts the supplied long array to a List.

Parameters:
array - a long array.
Returns:
a List containing the array's elements.
Since:
2.0

asList

java.util.List asList(double[] array)
Converts the supplied double array to a List.

Parameters:
array - a double array.
Returns:
a List containing the array's elements.
Since:
2.0

asList

java.util.List asList(short[] array)
Converts the supplied short array to a List.

Parameters:
array - a short array.
Returns:
a List containing the array's elements.
Since:
2.0

asList

java.util.List asList(char[] array)
Converts the supplied character array to a List.

Parameters:
array - a character array.
Returns:
a List containing the array's elements.
Since:
2.0

asInteger

java.lang.Integer asInteger(java.lang.String integerString)
Returns the Integer representation of the supplied number string.

Parameters:
integerString - the integer String (must represent a valid int value).
Returns:
the corresponding Integer object.

downloadString

java.lang.String downloadString(java.lang.String url)
Downloads the content from the specified URL using the default character set in MIB Explorer's locale.

Parameters:
url - a HTTP URL of the form http://www.myserver.com/myfile.txt.
Returns:
the content of the object at the specified URL as a String. For binary data, the resulting string is not defined.
Since:
2.0.7

downloadFile

java.lang.String downloadFile(java.lang.String url,
                              java.lang.String targetFileName)
Downloads the file specified by the supplied URL to the given file name on the local system.

Parameters:
url - a HTTP URL of the form http://www.myserver.com/myfile.gif.
targetFileName - the file name of the file where the contents of url should be written
Returns:
null if the operation was successful, or an error text if it failed.
Since:
2.0.7

loopCondition

LoopCondition loopCondition()
Creates a loop condition which can be used in a VTL #foreach statement to control loop termination by a boolean expression.

Returns:
a LoopCondition instance whose state is "loop" until its state is set to "stop", until then the LoopCondition object returns increasing numbers starting from one.
Since:
2.2.2

Copyright 2003-2011, Frank Fock, All Rights Reserved. http://www.mibexplorer.com