Central

Amplify Central Agent Status Change Notifier Using API Builder

Amplify Central Agent Status Change Notifier Using API Builder

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.

While this example uses Microsoft Teams, you could send your notification message to other systems such as Slack or to a mobile phone as an SMS using Twilio.

The overall steps are as follows:

  1. Create an API Builder Project
  2. Create an API by importing a swagger that defines an Amplify Central Integration (Resource) Webhook
  3. Create a flow that parses the webhook payload and sends a message to Microsoft Teams using Microsoft Team’s Incoming Webhook Connector
  4. Create an Amplify Integration Webhook for Agent Status updates and point to the API Builder API’s URL
  5. 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.

API Builder Flow Editor

Note that all of this was covered here.

Create The API Builder API Flow

The completed flow is shown below:

Completed Flow

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:
MS Teams Notification Message

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:

agentstatuschangesint.yaml:

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:

MS Teams Notification Message

Summary

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.