An example of an "Execute an arbitrary command" operation component is used here to explain the composition of a Ruby script.
require 'standard/swrba_input' require 'standard/swrba_command' | Mandatory | (1) Reading library to be used |
require 'kconv' | Optional | |
Logger = Swrba_Logger.new("swrba_command_run","swrba_standard_guest.log") | Optional | (2) Preparing log output for operation component |
input = Swrba_Input.new | Mandatory | (3) Preparing extraction of input information from input information file |
hostname = input.input_analysis(option[1],"hostname") ipaddress = input.input_analysis(option[1],"ipaddress") commandline = input.input_analysis(option[1],"commandline") username = input.input_analysis(option[1],"username") password = input.input_analysis(option[1],"password") execusername = input.input_analysis(option[1],"execusername") execpassword = input.input_analysis(option[1],"execpassword") | Optional | (4) Extracting input information |
if ipaddress != nil && ipaddress != "" hostname = ipaddress end if hostname == nil if commandline == nil | Optional | (5) Checking input information |
command = Swrba_Command.new | Optional | (6) Executing using library |
STDOUT.print command.stdout.toutf8 STDERR.print command.stderr.toutf8 | Optional | (7) Outputting execution results |
The details of the script file outlined above are explained below.
This reads the library to be used by the operation component. The libraries that can be used are the standard libraries provided by Ruby and the libraries that are described in the library reference. If you want to use a library provided by the product, define "standard/file name of library" in the "require" statement. Refer to "Libraries Provided by the Product" in the Systemwalker Runbook Automation Reference Guide for details of the libraries provided by the product.
Ruby script | Description |
---|---|
require 'standard/swrba_input' | Defining a library for analyzing the file that stores the input information. This library must be defined. |
require 'standard/swrba_command' | Defining a library for executing an arbitrary command |
require 'kconv' | Defining a library for performing conversion of the character code |
require 'standard/swrba_logger' | Defining a library for outputting a log of the operation component |
This prepares the processing results of the operation component to be output as a log.
Ruby script | Description |
---|---|
logger = Swrba_Logger.new ("swrba_command_run", "swrba_standard_guest.log") | Generating an instance for outputting a log
|
Include processing for preparing the extraction of input information.
Ruby script | Description |
---|---|
input = Swrba_Input.new | Generating an instance for analyzing the input information file |
option = [] | Performing data initialization |
option.push(data) | Obtaining parameter information and storing it in option |
if option.size != 2 | Checking the number of parameters |
if option[0] != "-input" | Checking the option type |
if File.exist?(option[1]) == false | Checking that the file exists |
This extracts the input information required for execution from the input information file.
Ruby script | Description |
---|---|
hostname = input.input_analysis(option[1],"hostname") | Extracting host name information from the input information file |
ipaddress = input.input_analysis(option[1],"ipaddress") | Extracting IP address information from the input information file |
commandline = input.input_analysis(option[1],"commandline") | Extracting information on the commands to be executed from the input information file |
username = input.input_analysis(option[1],"username") | Extracting information on connection user names from the input information file |
password = input.input_analysis(option[1],"password") | Extracting information on connection user passwords from the input information file |
execusername = input.input_analysis(option[1],"execusername") | Extracting information on executing user names from the input information file |
execpassword = input.input_analysis(option[1],"execpassword") | Extracting information on passwords of executing user names from the input information file |
This checks the extracted input information. If no mandatory input information exists, processing ends with an error.
Ruby script | Description |
---|---|
if ipaddress != nil && ipaddress != "" hostname = ipaddress end | If IP address information is included in input information file, specifying IP address in host name Note that depending on the specified content of the hostname option and the status of the Configuration Management Database (CMDB), it is possible that a value will only be configured in one of the "hostname" or "ipaddress" options, while the remaining option might contain a nil value. |
This writes the contents to be executed using a library. The Ruby script shown above is an example where the command library is to be used.
This outputs the executed results. The Ruby script shown above is an example where the command library is to be used.
Ruby script | Description |
---|---|
STDOUT.print | Standard output |
STDERR.print | Standard error output |
command.stdout.toutf8 | Converting the character code of the contents to be output to UTF-8 |
In the example shown above, this outputs a log if an exception occurs.
Ruby script | Description |
---|---|
logger.error(exc) | Output the exception results to a log |
The log files of an operation component are output in the following format:
uppercase initial of log type,[log output date and time#instance number] log type:process id:activity id:label name:log contents (Example) E, [2010-04-21T16:06:22.710069 #340] ERROR -- :process id:activity id:label name:[exception contents] |
The log files are stored in the following location and are in a 1-megabyte rotation. A maximum of 10 files are stored for each file name specified in the log output library within the script file.
Windows:
<Systemwalker Runbook Automation Management Server installation directory>\etc\share\rbaope\work\log\
The default <Systemwalker Runbook Automation Management Server installation directory> is "C:\Fujitsu\Systemwalker\SWRBAM".
Linux:
/etc/opt/FJSVswrbam/share/rbaope/work/log/
[File name]
The log file names are as follows:
The file name specified in the log output library within the script file
The file name.n specified in the log output library within the script file
(where n is a number from 0 to 8)
Return values of uniquely developed operation components can be set in a range between 0 and 255. Note that return values between 156 and 160 and between 171 and 240 have been reserved by Systemwalker Runbook Automation, so return values should not be set in these ranges. In addition, when return values between 161 and 170 are set, a retry is implemented. The retry count is set as I/O information for an operation component when an Automated Operation Process is developed.
(Example) Setting return value of "150": exit 150
After creating uniquely developed operation components, registering the operation components causes them to be stored in the following location of the Management Server:
Windows:
<Systemwalker Runbook Automation Management Server installation directory>\etc\share\rbaope\bin\parts\guest\E0\
The default <Systemwalker Runbook Automation Management Server installation directory> is "C:\Fujitsu\Systemwalker\SWRBAM".
Linux:
/etc/opt/FJSVswrbam/share/rbaope/bin/parts/guest/E0/
Specify the Ruby script file names as follows:
Use up to 64 bytes, including the extension (.rb), to specify the file name.
Only lowercase letters (a-z), uppercase letters (A-Z), numeric characters (0-9), half-size hyphen (-), half-size underscore (_), and period (.) can be used in a file name.
Ensure that the first character is a lowercase letter (a-z) or uppercase letter (A-Z).
In addition, the Ruby script file names of operation components that are provided as standard by the product have the prefix "swrba". In view of maintainability, adding the prefix "swrba" to Ruby script file names of uniquely developed operation components is not recommended.