Infrastructure at your Service

Nabil Saoual

Control M/ EM Send Mail and Alert Window notification with HHMMSS format with a job

Introduction

During my various tasks at work , it was sometimes and for many reasons , asked by users to have more precisions in jobs notifications sent by mail.
First of all, displaying the jobname , and why not the application name related and also the end of execution,without having to consult an eventual attached output.
Question
How can we define a job to send such information ( especially end time with hours minutes and seconds display in a more explicit way )?
Example

We see that we have no concrete information except the order id,and when the customer is not a user of controlm it can be not enough.We see for example the time format which is not really adapted.
The request was to have a notification format with HOUR , MINUTES and SECONDS in order to be more readable.
Solution
Control-M can use variable inside the jobs, so we will use this method to display the information needed in our mail.

Using Control-M system variables

Variables usage on Control-M :
All variables are identified by the %% prefix. If %% is included in the value for a job processing parameter, Control‑M assumes that it is referring to a variable or function.
To manage jobname and application name , we will use Control-M system variable such as %%JOBNAME and %%APPLIC

System variable list are available on BMC’s site or on your Control-M GUI client.

Using local variable

Define in the job, in the general part, the variable corresponding, with the inputs below:

Fill the variable name and the value:

Fill the variable parts with the value to be used in order to display hours minutes and seconds as you can see below by choosing “local” type:

Note:
%%SUBSTR function definition :

%%SUBSTR is a string function that is used to extract a substring from within a larger string.
This function has the following format:
result=%%SUBSTR variable startpos length

  • result: Any user variable or job submission variable.
  • variable: Any variable.
  • startpos: Numeric literal or variable that indicates the first position in the original string from which to extract the substring. The first character is position 1

length: A number or variable, indicating the length of the substring to extract  ( see Control M help on GUI )

Now we can also  define Alert windows to have a shout on the Global Alert Server (GAS) in case of good completion of the job


Define in the job  also the on-do action to send the mail in case of failure

Notice that you can also use the defined variables in the jobs command

Once the job defined with the correct variable , Control-M will read them and display them in the notification
Let’s see the jobs log

Here, we have also defined  the notification sent to the GAS as we have defined it to do a shout when ended ok by the same way

When we check the GAS the message is displayed and the variable applied as well

This kind of message is more explicit and can be helpful for example for your monitoring team when Control M is associated with another tool like Patrol,Truesight or Nagios,Centreon…
Now we can do a mailing test and check that date and time are well displayed

You can also make a simple mail notification which can be an alternative of CTMSYS,also you can put more information in the message,but you have to enter your mail list ( unless using a libmemsym but we will see it  later ,maybe in a blog dedicated to the variable usage and the libmemsym usage)

If the job fails, a mail will be sent to the address defined in Shout destination table (see one of my previous posts about this tool 😉)

So, to sum up , the job was defined to send a email in case of failure with jobname application related and time in format HH MIN SEC
He was also defined to send a message in the windows alert when it is ended OK
You can of course adapt the message characters between the variables you have defined for example HH/MIN/SEC or HH-MIN-SEC, and also call other variables
Alternative options

Using global variables

You can decide to extend theses variables to all jobs defined on your Control M Servers, by choosing global instead of local in your job’s definition.
Notice that the \ param is added to indicate that it is global to the Control-M/Server ( jevery job denied can use these variables)

Using LIBMEMSYM and POOLSYM method

Here is the BMC definition of LIBMEMSYM and POOLSYM variable
The %%LIBMEMSYM variable can be used in the Variable Assignment or Do Variable parameters to indicate a text file containing a list of Variable assignments. This variable enables you to create a central file containing Variable assignment statements that can be read by many job processing definitions.
You can also use the %%POOLSYM variable to call variables from a pool. %%POOLSYM is relevant only to a Control-M distributed system.
NOTE: Multiple LIBMEMSYM statements can be included in a single job processing definition. In this way you can maintain groups of local or global variables that are relevant to certain jobs and allow more than one such group to be applied to a job. However, if a variable is defined in more than one list, the last list defined overrides previous lists.

Using LIBMEMSYM

Instead of adding every variable in the job, you can store them in a LIBMEMSYM file and call them.
This have the advantage to be used in other jobs juste by adding one entry in the job under variable part ( the LIBMEMSYM path )
The format for the %%LIBMEMSYM variable:
%%LIBMEMSYM=path_name
path_name is the full (case sensitive) path name of a text file containing Variable assignment statements. This file must be accessible to Control‑M. The file must contain a single assignment on each line.

  • For the Variable Assignment parameter, the specified file is accessed at the time the job is submitted for execution by Control‑M.
  • If a %%LIBMEMSYM statement is specified using the Do Variable parameter, local variables defined in the specified file are relevant only during a rerun of the job if and when the On Statement/Code conditions are satisfied.

Creation of the Libmemsym ion the Control M server:

Definition in the job

Adding the path of the LIBMEMSYM you will use :

Using Named pools (POOLSYM)

You can defined a pool and call  the variables inside.
The format for the %%POOLSYM variable:
%%POOLSYM=<poolname>
poolname is the name of the pool containing the pool variable
Few commands to define a pool and set variable inside :

LOAD Loads variable values from a specified file to pool. The file name is the path name of a text file containing the variable assignment statements.
This file must be accessible to Control‑M. The file must contain a single assignment on each line.
EXAMPLE:
ctmvar -POOL load -POOLNAME <pool name> – FROM <file name>
SETVAR Defines a new or updates an existing variable in the specified pool.
If the variable does not exist in the data center, it is created.
If the variable already exists, it is updated with the specified value.
EXAMPLE:
ctmvar -POOL setvar -POOLNAME <pool name> -VAR <variable name> -VALUE <variable value>
DELETE Deletes a named pool from the data center.
EXAMPLE:
ctmvar – POOL – delete -POOLNAME <pool name>
LIST Lists all named pools in the data center.
EXAMPLE:
ctmvar -POOL list
VIEW Displays the list of variables in the named pool.
EXAMPLE:
ctmvar – POOL – view -POOLNAME <pool name>

Adding the variablle HH MM SS in the pool named POOL_HHMMSS :

CTMSRVCENTOS% ctmvar -pool setvar -POOLNAME POOL_HHMMSS -VAR MM -VALUE "%%SUBSTR %%TIME 3 2"
POOL SETVAR performed successfully.
POOL SETVAR performed successfully.
CTMSRVCENTOS% ctmvar -pool setvar -POOLNAME POOL_HHMMSS -VAR SS -VALUE "%%SUBSTR %%TIME 5 2"
POOL SETVAR performed successfully.
CTMSRVCENTOS% ctmvar -pool setvar -POOLNAME POOL_HHMMSS -VAR HH -VALUE "%%SUBSTR %%TIME 1 2"
POOL SETVAR performed successfully.
CTMSRVCENTOS% ctmvar -pool setvar -POOLNAME POOL_HHMMSS -VAR HOUR -VALUE "%%TIME"
POOL SETVAR performed successfully.
Use ctmvar utility  to also list and view the POOLS you have created:

Definition in the job

Result

This two other methods may have the same result as the first one ( locally defined on only one job ), but can be assigned to each job using these variables %%LIBMEMSYM %%POOLSYM

Conclusion

You know now how to make a more readable notification to help your team to be more reactive or to be more explicit for a non Control M user.
Take a look on BMC documentation and site to have more ways to use notifications and don’t forget to check what’s new on dbi’s blogs.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Nabil Saoual
Nabil Saoual

Consultant