跳到主要内容

Webhook

Webhooks are custom HTTP callbacks that you define. They are usually triggered by an event, such as creating a new application instance or triggering a new deploy task. For example, you can use webhooks to:

  • Trigger other systems, such as starting a test when the deploy task started.
  • Send notifications, such as notifying specific people when a application instance is deleted.

You can connect horizon to more external systems through webhook and your custom webhook receivers.

Events

The following events are supported.

Event typeTrigger
applications_createdA new application is created.
application_deletedAn application is deleted.
application_transferredAn application is transferred to another group.
instances_createdA new instance is created.
instances_deletedA instance is deleted.
instances_builddeployedA instance has completed a build task and triggered a deploy task.
instances_deployedA instance has triggered a deploy task.
instances_rollbackedA instance has triggered a rollback task.
instances_freedA instance has been freed.
instances_kubernetes_eventsAn event related to instance from kubernetes has been captured

Note: "*" indicates that you want to follow any event.

Create a webhook

In Settings->Webhooks on the group home page, you can view the list of created webhooks and create a new webhook.

Webhooks contain the following configuration.

  • URL: URL of the webhook endpoint. The URL must be percent-encoded if it contains one or more special characters.
  • Enable ssl verify: Whether to enable ssl verification when the url schema is HTTPS.
  • Description: Description of your webhook.
  • Secret: Secret Token of your custom webhook receiver.
  • Triggers: Events to trigger the webhook.

Click "submit" to complete the creation, you can see some basic information of the newly created webhook in the webhook list, and through the "operations" column to edit, delete webhook and view logs.

View the logs and retry

Click "View logs" on the right side of the webhook list to enter the logs list page, you can see the logs of this webhook, click "id" to enter the log details page, where you can view the request header, request body, response header, response body information of this trigger record.

If the webhook fails to send, you can resend it via the "resend" button in the upper right corner.

Headers and Payload example

Content-Type: application/json;charset=utf-8
X-Horizon-Webhook-Secret: "secret"

{
"eventID": 1,
"webhookID": 1,
"application": {
"id": 1,
"name": "test",
"priority": "P0"
},
"eventType": "applications_created",
"user": {
"id": 1,
"name": "test",
"email": "test@noreply.com"
}
}

For instances_kubernetes_event, the simplified kube event occupied the extra field.

Content-Type: application/json;charset=utf-8
X-Horizon-Webhook-Secret: "secret"
{
"eventID": 78402,
"webhookID": 33,
"instance": {
"id": 61400,
"name": "for-argocd-error",
"applicationName": "for-argocd",
"env": "online"
},
"eventType": "instances_kubernetes_event",
"extra": "{\"involvedObject\":{\"apiVersion\":\"argoproj.io/v1alpha1\",\"kind\":\"Rollout\",\"name\":\"for-argocd-error\",\"namespace\":\"online-64\"},\"lastTimestamp\":\"2023-06-15T09:03:44Z\",\"message\":\"Completed all steps\",\"name\":\"for-argocd-error.1768c4d94710ae4f\",\"reason\":\"SettingStableRS\",\"type\":\"Normal\"}"
}