Top
Systemwalker Runbook Automation Operation Guide
Systemwalker

3.4.3 Composition Example of a Perl Script

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;
use warnings;
use IPC::Open3;
use Symbol;
use utf8;
use Encode;
use Encode::Guess qw/cp932 euc-jp 7bit-jis/;

Optional

binmode STDOUT, ':utf8';
binmode STDERR, ':utf8';

Optional

(2) Setting output character code of component execution results

my $input = new Swrba_Input;

if($#ARGV != 1){
exit 198;
}

if($ARGV[0] ne "-input"){
exit 198;
}

if( ! -f $ARGV[1] ){
exit 198;
}

Mandatory

(3) Preparing extraction of input information from input information file

my $hostname =
$input->input_analysis($ARGV[1],"hostname");
if($hostname eq ""){
exit 197;
}

my $commandline =
$input->input_analysis($ARGV[1],"commandline");
if($commandline eq ""){
exit 197;
}

Optional

(4) Extracting input information

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>;

foreach my $line (@out){
print STDOUT decode('Guess',$line);
}

foreach my $line (@err){
print STDERR decode('Guess',$line);
}

waitpid( $pid, 0 );
my $child_exit_status = $? >> 8;

close $cmd_stdin;
close $cmd_stdout;
close $cmd_stderr;

Optional

(5) Outputting execution results

exit $child_exit_status;

Optional

(6) Ending script

3.4.3.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 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.

(2) Setting output character code of component execution results

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

(3) Preparing extraction of input information from input information file

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

(4) Extracting input information

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

(5) Outputting execution results

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

(6) Ending script

This ends the Perl script.

Perl script

Description

exit $child_exit_status;

Ending script by using received return values

3.4.3.2 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.3.3 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:

/opt/FJSVswrbam/etc/share/rbaope/bin/parts/guest/E0

Specify Perl 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 Perl script file names of uniquely developed operation components is not recommended.