Chapter 6. Event management products and best practices 351
needs to account for the \. If a custom script is executed, it can be coded to
remove the appropriate \ characters. Example 6-55 shows a Korn shell script
snippet that provides this function.
Example 6-55 Korn shell code to handle sanitized variables
#!/bin/ksh
#
# The purpose of this script is to simulate a user script which
# sends a page after some processing to test nvcorrd and actionsvr
#
# We used to send the following:
# /usr/OV/bin/nvpage 1234567@skytel hi joe `date` $NVS $NVATTR_2 $NVATTR_3
# Now we will use sed to remove the escape characters
set -x
# fix up $NVATTR_2 to remove backslash “\”
host=`echo $NVATTR_2 | sed “s:\\\\\\::g”`
echo $host
/usr/OV/bin/nvpage 1234567@skytel hi joe `date` $NVS $host $NVATTR_3
exit
#
6.9.2 IBM Tivoli Enterprise Console
There are two main methods of executing automation from IBM Tivoli Enterprise
Console. Tivoli tasks can be run from an IBM Tivoli Enterprise Console rule, or a
script can be executed. The method that you choose depends upon the purpose
of the automation.
Tasks
If you want to run a task out of a rule from IBM Tivoli Enterprise Console, you can
use the exec_task predicate. For example, you may have a task called
example_task in the T/EC Tasks library, which runs a script called example.sh
and echoes “hello world” into a log file that you want to run every time you
receive an event of the class EVENT. In this case, you can use a rule such as the
one shown in Example 6-56.
Example 6-56 Running a task from within a rule using the exec_task predicate
rule:
run_task_example:
(
event: _event of_class EVENT where
352 Event Management and Best Practices
[
status: equals 'OPEN',
hostname: _hostname
],
reception_action:
(
exec_task(_event, 'example_task', '-l "T/EC Tasks" -h "%s"', [_hostname],
'YES'),
commit_action
)
).
This rule runs the task specified on whichever host name the event came from. If
you look at the line starting with exec_task, you can see, at the end, that there is
a ‘YES’. If this parameter is set to YES, you can see a display of the output from
the task on the event console. You can see this by clicking the icon next to the
event. Then you see a window showing you the output and the success or failure
of the task, as shown in Figure 6-56.
Figure 6-56 Output of a task executed from a rule
Scripts
If you want to execute the example.sh script without using a task and you want to
run it from the IBM Tivoli Enterprise Console event server itself, use the
exec_program predicate.
Chapter 6. Event management products and best practices 353
To use this predicate, we modify our rule as shown in Example 6-57.
Example 6-57 Run a script from a rule using the exec_program predicate
rule:
run_task_example:
(
event: _event of_class EVENT where
[
status: equals 'OPEN',
hostname: _hostname
],
reception_action:
(
exec_program(_event, '/tmp/example.sh', '', [], 'YES'),
commit_action
)
).
This runs the same script that we ran from the task. Notice the ‘YES’. You can
also view the output from this program by clicking in the same icon as you would
the task. The output should look similar to what is shown in Figure 6-57.
Use tasks to execute automation that must run on a system other than the event
server.
Tivoli tasks can be executed upon any system defined to the Tivoli Management
Region. Therefore, this is a good way to run automation on a problem system.
Since the exec_program predicate runs a script on the event server itself, it is not
as useful in automation that must run on the failing machine, such as gathering
diagnostic data and attempting recovery.
It is possible to use exec_program to run a script on the event server and have
the script trigger Tivoli tasks on the problem machine. This serves the same
function as using the execute_task predicate for the target machine. However, it
adds complexity, which makes it more difficult to determine what the rule set is
doing and how to maintain it.
Note: Any programs the run from the exec_program predicate must reside on
the machine where the event server is located.

Get Event Management and Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.