Event webhooks

Event webhooks allow integrating tsuru events with external systems. You can create an eventwebhook to notify the occurence of specific event types. When you create an event webhook,tsuru makes a request to the specified URL for every event according specific filters.

For more info on the client commands for handling webhooks, checktsuru client docs.

Configurations

Event webhook configurations basically involve filtering events and configuring the hook request.

Event filtering configurations

By default, all events that the webhook creator has access will trigger it. But the events may befiltered by some criteria:

  • Error only: triggers only failing events
  • Success only: triggers only successful events
  • Kind type: permission or internal
  • Kind name: one of the values returned by the tsuru permission-list command, like app.create or pool.update
  • Target type: global, app, node, container, pool, service, service-instance, team, user, iaas, role, platform, plan, node-container, install-host, event-block, cluster, volume or webhook
  • Target value: the value according to the target type. When target type is app, for instance, target value will be the app name

Hook request configurations

  • URL: the URL of the request
  • Method: GET, POST, PUT, PATCH or DELETE. Defaults to POST
  • Headers: HTTP headers, defined in key=value format
  • Body: Payload of the request, used when the method is POST, PUT or PATCH. Defaults to the serialized event in JSON
  • Proxy: Proxy server used for the requests
    The request body may be specified with Go templates,to use event fields as variables. Refer to event datafor the available fields.

Examples

Notifying every successful app deploy to a Slack channel:

  1. $ tsuru event-webhook-create my-webhook https://hooks.slack.com/services/...
  2. -d "all successful deploys"
  3. -t <my-team>
  4. -m POST
  5. -H Content-Type=application/x-www-form-urlencoded
  6. -b 'payload={"text": "[{{.Kind.Name}}]: {{.Target.Type}} {{.Target.Value}}"}'
  7. --success-only
  8. --kind-name app.deploy

Calling a specific URL every time a specific app is updated:

  1. $ tsuru event-webhook-create my-webhook <my-url>
  2. -t <my-team>
  3. --kind-name app.update
  4. --target-value <my-app>

原文: https://docs.tsuru.io/1.6/managing/event-webhooks.html