Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
naeem_maqsud
Advisor
Advisor
This blog intends to demonstrate with examples (using scripts registered with host agent) on how to transfer parameters of a custom operation or custom hook to a subsequent custom operation or custom hook. In particular this is in reference to SAP Note 2601394.

Parameters can be transferred to direct successors (custom operations/hooks that are executed immediately afterwards). This is done by using the keyword "ResultConverter" with entry of "hook" in the script registered with host agent. This means that special handling of the output of your script will be done. If the output had a line starting with [RESULT] then LaMa will set a transfer parameter per the following format.











Parameter [RESULT]:Param:<PARAMETER_NAME>=<PARAMETER_VALUE>
Secure parameter [RESULT]:ParamSecure:<PARAMETER_NAME>=<PARAMETER_VALUE>

All direct custom successors can access this parameter with the TRANS- prefix.

TRANS-<PARAMETER_NAME>

If your need is not for transfer of parameters to direct successors but rather to be used by any subsequent custom operation/hook, then this can be done by updating or creating custom properties in the script.



















Custom property [RESULT]:Property:<Property-Name>=<Property-Value>
Secure custom property [RESULT]:PropertySecure:<Property-Name>=<Property-Value>
System wide custom property [RESULT]:SystemProperty:<Property-Name>=<Property-Value>
Secure system wide custom property [RESULT]:SystemPropertySecure:<Property-Name>=<Property-Value>

In this scenario you access the custom property as below.

PROP-<PROPERTY_NAME>

You have to allow the update of custom properties when creating the provider definition in SAP Landscape Management (covered in example 2).

Test Environment:

  • SAP Landscape Management Enterprise Edition 3.0 SP13 (on Linux with SAP ASE database)

  • Managed host: SuSE Linux Enterprise 12 SP2


Example 1: Parameter transfer to direct successor

In this example we will have 2 very simple custom operations.

  • Custom operation 1 executes a script to determine number of CPUs on a host (entity on which you execute the operation) and assigns this to a parameter with name of HOST_CPUCOUNT.


 

  • Custom operation 2 executes a script that takes the value of HOST_CPUCOUNT from above operation and creates a temporary file /tmp/transfer_parameter with an entry of "HOST_CPUCOUNT was evaluated as xx"


Above will run back to back.

Create the configuration files in directory /usr/sap/hostctrl/exe/operations.d on the managed host that is going to run the custom operation.

Create file CO_trans_param1.conf
Username: root
Name:CO_trans_param1
Description: Determine CPU count and assign to transfer parameter HOST_CPUCOUNT
Command: /usr/sap/scripts/cpu_count_trans.sh
ResultConverter: hook
Platform: Unix

Important thing to note here is the "ResultConverter" keyword and setting it to "hook".

 

Set permissions:
chown root:root <.conf file>
chmod 755 <.conf file>

 

Create the bash script in a directory of your choice (in my case it was in /usr/sap/scripts):

Script name: “cpu_count_trans.sh”.
#!/bin/bash
# First we determine the cpu count and assign to internal variable cpu_count
cpu_count=`grep processor /proc/cpuinfo|wc -l`
# Now we can output something in a format that LaMa will process
# Assign the value to the transfer parameter HOST_CPUCOUNT
echo "[RESULT]:Param:HOST_CPUCOUNT=$cpu_count"

In the above script the key thing to note is the last line which produces an output in the correct syntax for the parameter to be transferred. This will trigger the handling by LaMa.

 

Set permissions
chown root:root <file>

chmod 755 <file>

 

Now let's create the custom operation that will use the transferred parameter.

Create file CO_trans_param2.conf
Username: root
Name:CO_trans_param2
Description: Access parameter transferred by previous operation
Command: /usr/sap/scripts/cpu_count_trans_file.sh $[TRANS-HOST_CPUCOUNT]
ResultConverter: flat
Platform: Unix

 

Important line here is where the command is executed. Note the use of TRANS-HOST_CPUCOUNT

We no longer need any special handling of output so we set ResultConverter in this case to flat.

Set permissions:
chown root:root <.conf file>
chmod 755 <.conf file>

 

Create the bash script in a directory of your choice (in my case it was in /usr/sap/scripts):

Script name: “cpu_count_trans_file.sh”.
#!/bin/bash
# First we retreive the value of the transfer parameter
cpu_count=$1
# Now we create the file
echo "HOST_CPUCOUNT was evaluated as $cpu_count" > /tmp/transfer_parameter

The value of TRANS-HOST_CPUCOUNT was passed as an argument to the above script so we reference it as $1

 

Set permissions
chown root:root <file>

chmod 755 <file>

 

First we create the provider definitions:

Automation Studio -> Provider Definition -> Create


No special settings are needed for the transfer.



Repeat for second provider definition - CO_trans_param2 with identical settings.


We create the custom operations:

Automation Studio -> Custom Operation -> Create



Repeat for the second custom operation "CO_trans_param2" (using the corresponding provider definition) with same settings.

Now to test the above custom operations running back to back, we create an Operation Template.

Automation Studio -> Operation Template -> Create


 


 

Execute the above Operation Template and you should see the file /tmp/transfer_parameter created demonstrating that the correct value transferred from CO_trans_param1 to CO_trans_param2 custom operation.

Verify:
nm-sles-12-1:~ # cat /tmp/transfer_parameter
HOST_CPUCOUNT was evaluated as 4

 

Example 2: Custom Property Set and Retrieve

In this example we will create a variation of example 1 and this time assign the cpu count value to a custom property.

  • Custom operation 1 -- cpu count is determined and assigned to a custom property


 

  • Custom operation 2 -- use the custom property set in custoom operation 1 and create a temporary file "/tmp/transfer_cust_property" with entry of "CUST_CPUCOUNT custom property value was retrieved as xx"


Create file CO_trans_cust_prop1.conf:
Username: root
Name:CO_trans_cust_prop1
Description: Determine CPU count and assign to custom property CUST_CPUCOUNT
Command: /usr/sap/scripts/cpu_count_trans_cust_prop1.sh
ResultConverter: hook
Platform: Unix

Important thing to note here is the "ResultConverter" keyword and setting it to "hook"

 

Set permissions:
chown root:root <.conf file>
chmod 755 <.conf file>

 

Create script: “cpu_count_trans_cust_prop1.sh”.
#!/bin/bash
# First we determine the cpu count and assign to internal variable cpu_count
cpu_count=`grep processor /proc/cpuinfo|wc -l`
# Now we can output something in a format that LaMa will process
# Assign the value to custom property CUST_CPUCOUNT
echo "[RESULT]:Property:CUST_CPUCOUNT=$cpu_count"

In the above script the key thing to note is the last line which produces an output in the correct syntax for the custom property to be set. This will trigger the handling by LaMa.

 

Set permissions
chown root:root <file>

chmod 755 <file>

 

Now let's create the custom operation that will use the custom property.

Create file CO_trans_cust_prop2.conf
Username: root
Name:CO_trans_cust_prop2
Description: Access custom property CUST_CPUCOUNT set by previous operation
Command:/usr/sap/scripts/cpu_count_trans_cust_prop_file.sh $[PROP-CUST_CPUCOUNT]
ResultConverter: flat
Platform: Unix

 

Important line here is where the command is executed. Note the use of PROP-CUST_CPUCOUNT

We no longer need any special handling of output so we set ResultConverter in this case to flat.

 

Set permissions:
chown root:root <.conf file>
chmod 755 <.conf file>

 

Create script: “cpu_count_trans_cust_prop_file.sh”.
#!/bin/bash
# First we retreive the value of the custom property that was passed as argument
cpu_count=$1
# Now we create the file
echo "CUST_CPUCOUNT custom property value was retrieved as $cpu_count" > /tmp/transfer_cust_property

 

The value of PROP-CUST_CPUCOUNT was passed as an argument to the above script so we reference it as $1

 

Set permissions
chown root:root <file>

chmod 755 <file>

 

First we create the first provider definition:


Note the check mark for "Update Custom Properties"


Repeat for the second provider definition - CO_cust_prop2 (using CO_trans_cust_prop2.conf) but do not check mark "Update Custom Properties" as we are not updating or setting new properties.

 

We create the custom operations. Create the first one:


 

Create the second custom operation "CO_trans_cust_prop2" with similar settings as above.

Now we can test the 2 custom operations but this time we do not need to create an Operation Template. This is because custom properties are persistent and can be retrieved at any time.

Execute custom operation CO_cust_prop1 and you will see a pop-up letting you know that the custom property has been set.

 


 

Now execute custom operation CO_cust_prop2 which will use the previously set custom property and create the file using the value.

Verify:
nm-sles-12-1:~ # cat /tmp/transfer_cust_property
CUST_CPUCOUNT custom property value was retrieved as 4

 

References:

  1. https://blogs.sap.com/2020/02/28/sap-landscape-management-lama-automation-studio/

  2. SAP Landscape Management Enterprise 3.0 User Guide

  3. SAP Note 2601394

17 Comments