In this blog post we’ll use Axway Amplify API Builder to create a simple integration with Amplify. We’ll implement an agent status update notifier as described here but with API Builder instead of Integration Builder, thereby providing enterprises increased flexibility in choosing the Amplify components that best suit their needs.
We’ll create an API Builder API and associated flow that will respond to Amplify webhooks associated with Amplify (Discovery and/or Traceability ) agent status changes. For example to be notified when an agent inadvertently stops running due to an issue on the Gateway. The flow will subsequently send a notification to Microsoft Teams to let the API Management team know that there was an agent status change.
The overall steps are as follows:
- Create an API Builder Project
- Create an API by importing a swagger that defines an Amplify Central Integration (Resource) Webhook
- Create a flow that parses the webhook payload and sends a message to Microsoft Teams using Microsoft Team’s Incoming Webhook Connector
- Create an Amplify Integration Webhook for Agent Status updates and point to the API Builder API’s URL
- Test it out
We already did a lot of this in this blog post. Refer to it to see how we created the API Builder API and set up the Amplify Integration Webhook and we’ll continue from there.
Create API Builder Project and API
I created an API Builder Project, agentstatuschangenotifier, and created an API, amplifycentralwebhookhandler, by importing a swagger file that defines an Amplify Central Integration (Resource) Webhook. Then I clicked on the Create Flow link for the new API to enter the flow editor.
Note that all of this was covered here.
Create The API Builder API Flow
The completed flow is shown below:
The flow basically does the following:
- Checks to make sure that the webhook corresponds to an agent status update webhook by checking the webhook payload for the following:
- metadata.subresource = “status”
- type = “SubResourceUpdated”
- kind = “DiscoveryAgent” OR “TraceabilityAgent”
- It then checks to see if the status has changed by checking first to see if status.previousState exists (it doesn’t on agent startup) and then to see if status.state is not equal to status.previousState (i.e. that there is a status CHANGE).
- If any of those conditions are not met, then the flow terminates.
- If all conditions are met, the the flow creates the MS Teams message card and then makes an HTTP POST to the MS Teams channel incoming webhook connector URL as follows:
The API Builder project can be downloaded here.
Create The Amplify Integration Webhook
As we described here, you can edit and use the following YAML to define the agent status update integration webhook in Amplify:
name: agentstatuschangesint kind: Integration apiVersion: v1alpha1 title: Agents Status Changes Integration tags: - Agents spec: description: Agents Status Changes Integration --- name: agentstatuschangesintwh kind: Webhook apiVersion: v1alpha1 title: Agents Status Changes Integration Webhook attributes: release: 1.0.0 metadata: scope: kind: Integration name: agentstatuschangesint spec: enabled: true url: https://be15-xx-yyy-zzz-35.ngrok.io/api/amplifycentralwebhookhandler headers: apikey: wzZg........XeA4Tc --- group: management apiVersion: v1alpha1 kind: ResourceHook name: agentstatuschangesintrh title: Agents Status Changes Integration Resource Hook metadata: scope: kind: Integration name: agentstatuschangesint spec: triggers: - group: management kind: DiscoveryAgent name: "*" scope: kind: Environment name: "*" type: - updated - group: management kind: TraceabilityAgent name: "*" scope: kind: Environment name: "*" type: - updated webhooks: - agentstatuschangesintwh
Note that this will track agent status updates for both Discovery and Traceability agents in ALL (*) environments
Note the API Builder API Key header specification in the agentstatuschangesintwh section of the YAML file above.
Then use the following Axway CLI commands to create the integration:
axway auth login axway central create -f agentstatuschangesint.yaml
If you want to modify the YAML after the Integration was already created, say to limit to certain environments, then use the following command, after modifying your YAML file:
axway central apply -f agentstatuschangesint.yaml
You can stop an agent and restart it and you should start seeing MS Teams notifications as follows:
The openness and extensibility of the Amplify platform enables you to integrate Amplify with your IT and business processes and monitoring systems. In this blog post, we saw how API Builder, with it’s low code flow editor can help you easily create a notification system to help monitor your Amplify agents running in your Axway and non-Axway Gateways to make sure that your APIs are being discovered and monitored properly.
The API Builder project can be downloaded here.
You can also download a Docker container version here. This will eliminate the need to create and build an API Builder project. You can just deploy the container with proper environment variables set and point your integration webhook to it.
Read more about Amplify Central Agent Status Change Notifier.