Creating a trigger
A trigger monitors for a specific event and then initiates an action if its conditions are met. You can create a trigger using a curl command or by using the Swagger UI for the WebSphere Automation REST API.
About this task
You must have access to the WebSphere Automation REST API, and you must authenticate with Red Hat OpenShift Container Platform administrator credentials by clicking Authorize on the Swagger UI page.
Creating a trigger in WebSphere Automation
Use the Swagger user interface for the WebSphere Automation REST API
to create a new action. The action resource is part of the Self-Secure API that are available in the
Swagger UI at
https://<cpd-route>/websphereauto/secvul/apis/openapi/ui/.
For more information on finding the <cpd-route>, see Viewing the REST API.
On the Swagger UI page for Self-Secure API, do the following steps to create a trigger.
- Click Post /trigger to create a trigger.
The section expands to show the Parameters tab, an example request body and schema, and responses.
- Click Schema to view the trigger schema.
Make sure that you are familiar with the schema and the acceptable values for each parameter.
- Click Try it out.
The request body area can now be edited.
- Modify the request body by changing the values in quotation marks after the colon for the
parameters that you want to modify.
For more information about the trigger resource parameters, see Trigger resource.
You can use JSONata
expressions to provide conditional processing or to pass values from the resource notification to the action. For more information, see Creating a resource trigger and Verifying JSONata expressions.
- Click Execute.
- Examine the response code.
If your trigger is valid, the response code is 201 for a successful operation. Your trigger is active and ready to invoke the action with the specified actionId if the defined criteria are met.
Verifying JSONata expressions
If you pass data from the resource notification through the trigger to the action, or if you use
conditional processing that is based on the data in the resource notification, you can verify your
JSONata expressions by using the JSONata Exerciser at https://try.jsonata.org/ .
- Copy the full JSON code for the resource notification that is the basis for your trigger and
paste it into the JSON panel.
For examples, see Trigger resource.
- Create a JSONata expression in the JSONata panel.
For example, the following JSONata expression evaluates a
create vulnerabilityevent to determine if one or more CVEs in the vulnerability have a severity of greater than 9 (on the CVSS scale of 0 to 10).$count(vulnerability.cves[cvssBaseScore > 9 ]) > 0As another example, the following JSONata expression
$vulnerability.cvesmight pass data that looks like the following code snippet:
{ "id": "CVE-2021-44228", "description": "Lorem ipsum dolor sit amet…", "cvssBaseScore": 10 } - The third panel automatically updates with the result of the expression.
To use the JSONata expression as a condition, the expression must be a boolean (that is, with a result of either true or false). A condition must evaluate as true for the trigger to invoke the action.
If you are passing data from the resource notification to the action, ensure that the expression is syntactically correct to pass the desired values.