An example of creating an "Execute an arbitrary command on a local server" operation component is used here to explain the composition of a Perl script in an operation component.
Note
The only library for Perl provided by Systemwalker Runbook Automation is an input information library.
If you want to create operation components using Perl script, obtain Perl libraries as required and install them in the Management Server.
use Swrba_Input; | Mandatory | (1) Reading library to be used |
use strict; | Optional | |
binmode STDOUT, ':utf8'; | Optional | (2) Setting output character code of component execution results |
my $input = new Swrba_Input; | Mandatory | (3) Preparing extraction of input information from input information file |
my $hostname = | Optional | (4) Extracting input information |
my ($cmd_stdout, $cmd_stderr, $cmd_stdin) = (gensym, gensym, gensym); | Optional | (5) Outputting execution results |
exit $child_exit_status; | Optional | (6) Ending script |
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 Perl and those described in the library reference. Refer to "Libraries Provided by the Product" in the Systemwalker Runbook Automation Reference Guide for details of the libraries provided by the product.
Perl script | Description |
---|---|
use Swrba_Input; | Defining a library for analyzing the file that stores the input information. This library must be defined. |
use Symbol; use utf8; use Encode; use Encode::Guess qw/cp932 euc-jp 7bit-jis/; | Defining a library for performing conversion of the character code for standard output and standard error output for a component Here, the standard Perl libraries are being used. If these libraries have not been installed in the Management Server, you must obtain and install them. In this example, the character code is converted to UTF-8. |
This sets the character code type for the execution results of the operation component.
Perl script | Description |
---|---|
Binmode STDOUT, ':utf8'; binmode STDERR, ':utf8'; | Ensures that standard output and standard error output is output in UTF-8 |
Include processing for preparing the extraction of input information.
Perl script | Description |
---|---|
my $input = new Swrba_Input; | Declaring variable name "input" as a local variable |
if($#ARGV != 1){ exit 198; } if($ARGV[0] ne "-input"){ exit 198; } | Checking that the format of the parameter to be handled is correct |
if( ! -f $ARGV[1] ){ exit 198; } | Checking that the file to be handled as an input parameter exists |
This extracts the input information required for execution from the input information file.
Perl script | Description |
---|---|
my $commandline = $input->input_analysis($ARGV[1],"commandline"); if(defined($commandline)){ exit 197; } | Extracting command line information from the input information file |
This outputs the executed results.
Perl script | Description |
---|---|
my ($cmd_stdout, $cmd_stderr, $cmd_stdin) = (gensym, gensym, gensym); my $pid = open3( $cmd_stdin, $cmd_stdout, $cmd_stderr, $commandline); my @out = <$cmd_stdout>; my @err = <$cmd_stderr>; | Obtaining standard output and standard error output of the component |
foreach my $line (@out){ print STDOUT decode('Guess',$line); } | Standard output |
foreach my $line (@err){ print STDERR decode('Guess',$line); } | Standard error output |
waitpid( $pid, 0 ); my $child_exit_status = $? >> 8; | Receiving return values of the component |
This ends the Perl script.
Perl script | Description |
---|---|
exit $child_exit_status; | Ending script by using received return values |
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:
/opt/FJSVswrbam/etc/share/rbaope/bin/parts/guest/E0
Specify Perl script file names as follows:
Use up to 64 bytes, including the extension (.pl.
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 Perl script file names of uniquely developed operation components is not recommended.