Sample Collection Guide > Notification with Variable Message Text

Notification with Variable Message Text

Objective: The notification given by the notification should contain a message text depending on the task activating it.

Objects used: Notification

Script elements used: ACTIVATE_UC_OBJECT, :ADD_ATT, GET_ATT, :PUT_ATT, :PUT_ATT_APPEND, :PUT_READ_BUFFER, :READ, STR_FIND, SYS_ACT_PARENT_NAME, SYS_ACT_PARENT_NR and SYS_ACT_PARENT_TYPE


Example

Notifications are used for sending messages via the monitor view of the notification, email or SNMP. Creating a notification whose message text contains information about the task triggering the notification is very useful. This notification can then be used for various purposes because the message content is automatically adapted.

Task

Enter the following script lines in the Post-Process tab of any task to start the notification.

!Storing the agent name in the Read buffer
:
SET &att_host = GET_ATT(HOST)
:
PUT_READ_BUFFER host# = '&att_host'

!Activating the notification

:
SET &ret = ACTIVATE_UC_OBJECT('CALLOP')

Attributes can only be retrieved from the Process tab of the very same task. Therefore, this example stores the name of the selected agent in the input buffer (Read buffer). The notification reads the value from there and uses it for the message to be sent.

Notification

Now create a new notification. Specify its priority and type (request, message, alert) and one or several users who should be notified.

The script structure is shown below. First, the agent name is read from the input buffer. Further information about the task is then retrieved (name, RunID and object type). It is helpful to keep common naming conventions for objects because the script verifies whether the name of the task contains a particular string (ADMIN).  If so, the defined user and the users of the user group "ADMIN" are notified.

The message text to be output is specified with the script statements :PUT_ATT and :PUT_ATT_APPEND. A line break can be created with the function UC_CRLF.

!Reading the agent name of the task
:
READ &host,,


:
SET &name = SYS_ACT_PARENT_NAME(ACT)
:
SET &runnr = SYS_ACT_PARENT_NR(ACT)
:
SET &typ = SYS_ACT_PARENT_TYPE(ACT)


!If 'ADMIN' is part of the task name ...

:
SET &string = STR_FIND (&name,'ADMIN')


!...all the users of the user group "ADMIN" are notified.

:
IF &string <> '0'
:  
ADD_ATT RECIPIENT, 'ADMIN'
:
ENDIF 



!Creating the message text

:
PUT_ATT CALL_TEXT = 'The following task was not successfully completed! Please check!'
:
PUT_ATT_APPEND CALL_TEXT = UC_CRLF()
:
PUT_ATT_APPEND CALL_TEXT = UC_CRLF()
:
PUT_ATT_APPEND CALL_TEXT = 'Name of the task: &name'
:
PUT_ATT_APPEND CALL_TEXT = UC_CRLF()
:
PUT_ATT_APPEND CALL_TEXT = 'RunID of the task: &runnr'
:
PUT_ATT_APPEND CALL_TEXT = UC_CRLF()
:
PUT_ATT_APPEND CALL_TEXT = 'Type of the task: &typ'
:
PUT_ATT_APPEND CALL_TEXT = UC_CRLF()
:
PUT_ATT_APPEND CALL_TEXT = 'Agent: &host'

The following illustration shows a notification called by the task "ADMIN.DB.MAINTENANCE" which notifies the user Smith. As the relevant task contains the string "ADMIN", the members of the user group ADMIN (Brown and Green) are also notified.

 

See also:

Notification - Execution