Top
Systemwalker Runbook Automation Operation Guide
Systemwalker

3.4.2 Composition Example of a Ruby Script

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'
require 'standard/swrba_logger'

Optional

Logger = Swrba_Logger.new("swrba_command_run","swrba_standard_guest.log")

Optional

(2) Preparing log output for operation component

input = Swrba_Input.new
option = []
while data = ARGV.shift
option.push(data)
end
if option.size != 2
exit 198
end
if option[0] != "-input"
exit 198
end
if File.exist?(option[1]) == false
exit 198
end

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
exit 197
end

if commandline == nil
exit 197
end

Optional

(5) Checking input information

command = Swrba_Command.new
begin
command.run(hostname, username, password,
execusername,execpassword, commandline)

Optional

(6) Executing using library

STDOUT.print command.stdout.toutf8
rescue => exc

STDERR.print command.stderr.toutf8
logger.error(exc)
exit command.return_code
end

Optional

(7) Outputting execution results

3.4.2.1 Script Details

The details of the script file outlined above are explained below.

(1) Reading library to be used

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

(2) Preparing log output for 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

  • "swrba_command_run"

    Label name for identifying the output source of the log. Specify a label name that will be unique.

  • "swrba_standard_guest.log"

    File name of the log. Specify any file name. However, do not specify the log file name "swrba_standard.log", which is provided by Systemwalker Runbook Automation and is output by the operation component.

(3) Preparing extraction of input information from I/O information file

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

(4) Extracting input information

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

(5) Checking input information

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.
If a value is configured in the "ipaddress" option, substitute the "ipaddress" value in "hostname" to ensure "hostname" can be used when values are configured in subsequent processes.

(6) Executing using library

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.

(7) Outputting execution results

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

3.4.2.2 About Logs of Operation Components

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:

3.4.2.3 About Return Values of Operation Components

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

3.4.2.4 About Storage Locations and File Names of Operation Components

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:

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.