4.3.3 Designing notifications
Ops I provides two notification function methods: notifications triggered when workflows, schedules, or work items are created, modified, or deleted (hereinafter referred to as “event-based notifications”), and notifications sent at times specified in the workflow definition (hereinafter referred to as “workflow-based notifications”).
The design of notifications involves two types of YAML definitions: Notification and Notifier.
(Table) Notification design items and outline
| Item | Definition method | Key design points |
|---|---|---|
| ・Notification ・Notifier |
YAML file | Assign an agent to be notified for each workflow step and configure notifications to be sent to the requester upon completion of the request. In addition, assign or configure agents to be notified for each schedule. Notification is made via the GUI or e-mail. |
[Event-based notifications]
(Figure) Notification and Notifier conceptual diagram (Event-based notifications)
Ops I allows you to define notifications triggered based on workflows, schedules, and work items. Here, “trigger” refers to the event that causes a notification to be sent. By defining in a YAML file the event conditions based on which notifications will be sent, the message, destinations, and sending methods, the agent assigned to the activity the user wants to be performed can receive a notification, and the requester can receive a report of the acceptance/completion of the request.
For information on notifications triggered based on workflows, see “Notification with workflow set as starting point”.
It is also possible to make notifications of start and completion of schedules and updates of work items.
If the schedule belongs to a calendar, you can limit notifications to users who belong to the group assigned to the calendar or to schedules associated with the calendar. In this case, the body, title, and link of the notification can be defined in the calendar information.
For information on notifications triggered based on schedules and work items, see “Notification with schedule/work item set as starting point”.
[Workflow-based notifications]
Add a notification task at the point in the workflow where you want to send a notification. Use this method when you want to send a notification at any point in the workflow.
(1) Flow of notification
Whether sending event-based or workflow-based notifications, you must first configure the following labels in the Notification YAML file.
- event.resource: The resource monitored for notifications (creation, update, and so on)
- event.type: The event type (creation, update, and so on)
- conditions: The conditions for triggering notifications. No configuration is required if "type" is set to "onDemand".
[Event-based notifications]
If "type" is not "onDemand" and the target specified in “event” meets the conditions defined in “conditions”, the notification source creates a notification object and sends it to the recipient. For examples of notification conditions and their YAML definitions, see “Example of notification of schedule and work item origin”.
[Workflow-based notifications]
If "type" is set to "onDemand" and any conditions are not configured, the Ops I component “oi.notify” is used. Notifications are sent at the timing specified in the workflow, and parameters defined in the workflow YAML file can be embedded. For examples of YAML definitions, see “Examples of workflow definitions including notifications”.
A notification object represents the notification recipient, delivery method, and notification message. It is configured using the “notifications” label in the Notification YAML file. You can choose to send notifications to Ops I users or groups as recipients.
The means of sending notifications is managed by YAML files of Notifier type. In addition to notifications through the Ops I GUI, notifications can also be sent by email.
When “.GetValue” is used, the resource specified in the “resource” parameter serves as the starting point. For a list of valid values, see “(Table) Object fields that can be used in Notification”.
The recipient of the notification can be specified by setting the requester, etc. in “assignedTo” of the schedule object. For information on schedule objects, see “(Table) Object fields that can be used in Notification”.
Since it is not clear on the GUI of the workflow or schedule which events have notification settings configured, the user who defined the notifications may need to inform the relevant persons.
For details on the Notification and Notifier YAML definitions, see “Notification, Notifier”.
(2) Notification with schedule/work item set as starting point
The schedule function includes schedules, work items linked to schedules, individual schedules linked to work items, and schedules linked to users. This function allows you to set up notifications triggered based on work items and schedules. The following is an example of a notification triggered based on a schedule, as well as the notification conditions and flow of notification.
(Figure) Schedule-originated notification flow
Notes
Since only one object can be specified in a single YAML file, settings for multiple objects must be described in separate YAML files.
For examples of notification conditions and their YAML definitions, see “Example of notification of schedule and work item origin”.
(3) Notification with workflow set as starting point
The following is an example of notification for each activity, triggered based on a workflow, when the VM lending operation is performed.
(Figure) Example of notification in case of VM lending tasks
(Table) List of contents of notifications in case of VM lending tasks
| Task name | Workflow Step |
Recipient of notification | Title | Body |
|---|---|---|---|---|
| VM lending | Make a request | Operations agent | [Workflow number (direct link)] VM lending request notification | A notification of request for the VM lending has been received. Please respond. Request date/time: Request date/time Requester: Requester |
| Review the request | Requester | [Workflow number (direct link)] VM lending rejection notification | A notification of rejection for the VM lending has been received. Please check the information provided and take the appropriate action. Request date/time: Request date/time Requester: Requester |
|
| Confirm creation of VM | Requester | [Workflow number (direct link)] VM lending cancellation notification | A notification of cancellation for the VM lending has been received. Please check the information provided and take the appropriate action. Request date/time: Request date/time Requester: Requester |
|
| Confirm creation of VM | Operation manager | [Workflow number (direct link)] VM lending approval notification | A notification of approval for the VM lending has been received. Please respond. Request date/time: Request date/time Requester: Requester |
|
| Confirm final VM creation | Operations agent | [Workflow number (direct link)] VM lending approval rejection notification | A notification of rejection for VM lending approval has been received. Please check the information provided and take the appropriate action. Request date/time: Request date/time Requester: Requester |
|
| Confirm final VM creation | Requester | [Workflow number (direct link)] VM lending completion notification | VM has been loaned. Please refer to the lending VM ledger. Request date/time: Request date/time Requester: Requester |
[Notification recipient settings]
When setting the agent assigned to the workflow step as the notification recipient in “assignedTo”, there are several steps that you need to take.
For the procedure for setting the recipients of notifications, see “API reference overview > Use cases and workflow for using API functions > (Table) Workflow for “Changing the agent of an activity corresponding to a specific step in My Workflow”” in “JP1 Cloud Service/Operations Integration API Reference”.
Below are a conceptual diagram of a Workflow YAML definition that sets the requester as the recipient of the notification and a definition example. Execute the following tasks using the information obtained from each task (context ID, parent “schedule” object ID, and the ID of the “schedule” object to be updated).
(Figure) Conceptual diagram of a YAML definition that sets the requester as the destination for notifications
<Definition example> YAML definition of the workflow that sets the applicant as the recipient
(omitted)
tasks:
### fetch_context_id Activity description
# Overview
# Retrieve the context ID from the list of practice-context using the current workflow’s Execution ID.
#
# Label description
# action: core.http
# To retrieve information about the currently running workflow,
# execute the GET /api/v1/practice-contexts API.
# To execute a REST API, use the “core.http” action in the “StackStorm” component.
#
# input:
# This section specifies the arguments to pass to “action”.
# Here, specify the arguments required to execute the “core.http” action.
# Specify the URL of the REST API to execute in the “url” field.
# Points:
# <% ctx().oiapi_location %> is an example of referencing a workflow variable
# defined as “Ops I’s URL/api/v1”. Modify this as required for your execution environment.
# Specify the REST API method in “method”.
# Specify the REST API header information (such as the credentials required to execute the REST API) in “headers”.
# Points:
# Specify the credentials required to execute the REST API (Ops I token or Ops I access token).
# In this example, the variable “oi_access_token”, which stores the Ops I access token
# obtained in advance by using the Ops I component’s “oi.fetch_access_token” action, is referenced.
#
# next:
# Based on the execution results of the REST API, select the next task to execute.
# In addition, use the “publish” attribute to save the context ID for use in subsequent processing.
# The context ID can be obtained from the first record in the list of “practice-context”
# (the response from the “GET /api/v1/practice-contexts” API).
# Retrieve the first record and assign it to the variable “context”, then retrieve the ID of “context” and assign it
# to the variable “context_id”.
fetch_context_id:
action: core.http
input:
url: <% ctx().oiapi_location %>/practice-contexts?filterBy=executionId%3Aeq%3A<% ctx().parent_execution_id %>
method: GET
headers:
Content-Type: application/json
Authorization: Bearer <% ctx().oi_access_token %>
next:
- when: <% succeeded() %>
publish:
- context: <% result().body.data.content.first(null) %>
- context_id: <% ctx().context.id %>
do: fetch_context
- when: <% failed() %>
do: fail
### fetch_context Activity description
# Overview
# Retrieves detailed information about a workflow and obtains the ID of the parent “schedule” object.
#
# Label description
# action: core.http
# Executes the “GET /api/v1/practice-contexts/{id}” API to retrieve details about a workflow.
# To execute the REST API, use the “core.http” action, just as in the “fetch_context_id” task.
# Use the “practice-context” ID obtained from the “fetch_context_id” task for {id}.
#
# input:
# This section specifies the arguments to pass to “action”.
# Here, specify the arguments required to execute the “core.http” action.
# The information to be specified is the same as that for the “fetch_context_id” activity.
#
# next:
# Here, use the “publish” attribute to retrieve the ID of the parent “schedule” object
# from the retrieved workflow details and assign it to the variable “parent_schedule_id”.
fetch_context:
action: core.http
input:
url: <% ctx().oiapi_location %>/practice-contexts/<% ctx().context_id %>
method: GET
headers:
Content-Type: application/json
Authorization: Bearer <% ctx().oi_access_token %>
next:
- when: <% succeeded() %>
publish:
- parent_schedule_id: <% result().body.data.schedule %>
do: fetch_schedule
- when: <% failed() %>
do: fail
### fetch_schedule Activity description
# Overview
# Retrieves the ID of the “schedule” object to be updated from the parent schedule information.
#
# Label description
# action: core.http
# To retrieve the “schedule” object to be updated,
# execute the “GET /api/v1/schedules/{id}” API to retrieve a list of child schedules.
# To execute the REST API, use the “core.http” action, just as in the “fetch_context_id” task.
# Use the ID of the parent “schedule” object obtained from the “fetch_context” task for {id}.
#
# input:
# This section specifies the arguments to pass to “action”.
# Here, specify the arguments required to execute the “core.http” action.
# The information to be specified is the same as that for the “fetch_context_id” activity.
#
# next:
# Search for the target “schedule” object in the list of child schedules
# and assign it to the “target_schedule” variable.
# Since the list of child schedules is an array, use a “where” expression to reference the “activity” of each element
# and search for the update target (in this example, “create_vm_wf_01”).
# The “update_schedule_body” variable contains the request body for the REST API call to be executed in the next task.
# Since the update uses the “PUT /api/v1/schedules/{id}” API,
# construct the request body using the information obtained in this task through the “target_schedule” variable.
# In this example, to update the assignee, use a “set” expression to set the “assignedTo” property of the “target_schedule” variable
# to the assignee’s user ID, and then assign the value to the “update_schedule_body” variable.
# For details about “where” expressions, “set” expressions, and other supported expressions, see the StackStorm manual.
fetch_schedule:
action: core.http
input:
url: <% ctx().oiapi_location %>/schedules/<% ctx().parent_schedule_id %>
method: GET
headers:
Content-Type: application/json
Authorization: Bearer <% ctx().oi_access_token %>
next:
- when: <% succeeded() %>
publish:
- target_schedule: <% result().body.data.children.where($.activity = “create_vm_wf_01”).first(null) %>
- target_schedule_id: <% ctx().target_schedule.id %>
- update_schedule_body: <% ctx().target_schedule.set(“assignedTo”, ctx().user_id) %>
do: update_schedule
- when: <% failed() %>
do: fail
### update_schedule Activity description
# Overview
# Change the workflow assignee based on information from the schedule being updated.
#
# Label description
# action: core.http
# To update the target “schedule” object,
# use the “PUT /api/v1/schedules/{id}” API.
# To execute the REST API, use the “core.http” action, just as in the “fetch_context_id” task.
# Use the ID of the “schedule” object to be updated, obtained from the “fetch_schedule” task, for {id}.
#
# input:
# This section specifies the arguments to pass to “action”.
# Here, specify the arguments required to execute the “core.http” action.
# Set the request body for the REST API in “body”.
# Since the “core.http” action requires string input,
# convert the value of the “update_schedule_body” variable to a string by using a “str” expression, and then set it.
#
# next:
# Once defined, variables can be reused.
# If you want to reuse a variable, initialize it by setting the variable to “null”
# to avoid using a previously assigned value.
update_schedule:
action: core.http
input:
url: <% ctx().oiapi_location %>/schedules/<% ctx().target_schedule_id %>
method: PUT
headers:
Content-Type: application/json
Authorization: Bearer <% ctx().oi_access_token %>
body:
<% str(ctx().update_schedule_body) %>
next:
- when: <% succeeded() %>
publish:
- target_schedule: null
- update_schedule_body: null
do: create_vm_wf_01
- when: <% failed() %>
do: fail
(omitted)
Other Workflow YAML definitions are shown as “omitted”. For information on the Workflow YAML definitions, see “Workflow”.
Subsection structure
4.3.3.1 Example of notification of schedule and work item origin
4.3.3.2 Examples of workflow definitions including notifications