Skip to content

Latest commit

 

History

History
551 lines (361 loc) · 10.8 KB

README.md

File metadata and controls

551 lines (361 loc) · 10.8 KB

Kapacitor Alerts API

Contents


Description

This API communicates with Influx's Kapacitor alerts/monitoring API to enable monitoring and alerting on Akkeris apps based on certain criteria/events. Alerts can be configured for HTTP 5xx status codes, Memory usage, Akkeris Releases, and when an app crashes.

Installation and Usage

Environment Variables

  • DATABASE_URL: URL of Postgres database (Required)
  • KAPACITOR_URL: URL of Kapacitor instance (Required)
  • RUN_MIGRATION: If this variable is present, run the database migration (Optional)

Usage

Replace the environment variable values with the correct values for your environment.

export DATABASE_URL="postgres://localhost:5432/kapacitor-alerts-api"
export KAPACITOR_URL="http://localhost:9092"
go run .

To run in Docker:

docker build -t kapacitor-alerts-api .
docker run \
	-e "DATABASE_URL=postgres://localhost:5432/kapacitor-alerts-api" \
	-e "KAPACITOR_URL=http://localhost:9092" \
	-p 8080:8080
	--rm \
	--name kapacitor-alerts-api \
	kapacitor-alerts-api

Testing

To run code coverage tests:

export DATABASE_URL="postgres://localhost:5432/kapacitor-alerts-api"
export KAPACITOR_URL="http://localhost:9092"
go test ./...

Database Migration

To import all memory, 5xx, crashed, and alerts tasks already present in Kapacitor, run this with the "RUN_MIGRATION" environment variable present. This will reset the database and import all tasks from Kapacitor.

API

These are the variables used in the API:

  • KAPACITOR_ALERTS_API: URI of the running instance
  • APP_NAME: App to act on
  • SLACK_CHANNEL: Slack channel to notify
  • EMAIL: Email address to notify
  • POST: URL to notify via webhook

NOTE: At least one of the notification options must be used (slack, email, post)

5xx

1. Get All Tasks

Get a list of the configuration of the 5xx event monitoring on all apps

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/tasks/5xx

2. Get Task

Get the configuration of the 5xx event monitoring on an app

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/task/5xx/{{APP_NAME}}

3. Get Task State

Get the current state of the 5xx event monitoring on an app

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/task/5xx/{{APP_NAME}}/state

4. Create Task

Begin monitoring an app for 5xx events

Endpoint:

Method: POST
URL: {{KAPACITOR_ALERTS_API}}/task/5xx

Headers:

Key Value Description
Content-Type application/json

Body:

{
	"app": "{{APP_NAME}}",		// App to monitor
	"tolerance": "low",		// Tolerance (low | medium | high)
	"slack": "{{SLACK_CHANNEL}}",	// *Optional* slack channel to notify
	"email": "{{EMAIL}}",		// *Optional* email address to notify
	"post": "{{POST}}"		// *Optional* URL to post a webhook to
}

5. Update Task

Update the configuration for 5xx monitoring on an app

Endpoint:

Method: PATCH
URL: {{KAPACITOR_ALERTS_API}}/task/5xx

Headers:

Key Value Description
Content-Type application/json

Body:

{
	"app": "{{APP_NAME}}",		// App to monitor
	"tolerance": "medium",		// Tolerance (low | medium | high)
	"slack": "{{SLACK_CHANNEL}}",	// *Optional* slack channel to notify
	"email": "{{EMAIL}}",		// *Optional* email address to notify
	"post": "{{POST}}"		// *Optional* URL to post a webhook to
}

6. Delete Task

Stop monitoring an app for 5xx events

Endpoint:

Method: DELETE
URL: {{KAPACITOR_ALERTS_API}}/task/5xx/{{APP_NAME}}

Crashed

Send an alert to a Slack channel, an email address, or as a webhook when an app crashes.

1. Get All Tasks

Get a list of the configuration of the crash event monitoring on all apps

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/tasks/crashed

2. Get Task

Get the configuration of the crash event monitoring on an app

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/task/crashed/{{APP_NAME}}

3. Create Task

Begin monitoring an app for crash events

Endpoint:

Method: POST
URL: {{KAPACITOR_ALERTS_API}}/task/crashed

Headers:

Key Value Description
Content-Type application/json

Body:

{
	"app": "{{APP_NAME}}",		// App to monitor
	"slack": "{{SLACK_CHANNEL}}",	// *Optional* slack channel to notify
	"email": "{{EMAIL}}",		// *Optional* email address to notify
	"post": "{{POST}}"		// *Optional* URL to post a webhook to
}

4. Update Task

Update the configuration for crash monitoring on an app

Endpoint:

Method: PATCH
URL: {{KAPACITOR_ALERTS_API}}/task/crashed

Headers:

Key Value Description
Content-Type application/json

Body:

{
	"app": "{{APP_NAME}}",		// App to monitor
	"slack": "{{SLACK_CHANNEL}}",	// *Optional* slack channel to notify
	"email": "{{EMAIL}}",		// *Optional* email address to notify
	"post": "{{POST}}"		// *Optional* URL to post a webhook to
}

5. Delete Task

Stop monitoring an app for crash events

Endpoint:

Method: DELETE
URL: {{KAPACITOR_ALERTS_API}}/task/crashed/{{APP_NAME}}

Memory

Send an alert to a Slack channel, email address, or as a webhook when an app uses more than the specified amount of memory.

1. Get All Tasks

Get the configuration of the release monitoring for all dynos on all apps

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/tasks/memory

2. Get All Tasks for App

Get the configuration of the release monitoring for all dynos on an app

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/tasks/memory/{{APP_NAME}}

3. Get Task

Get the configuration of the memory usage monitoring on an app and dyno

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/tasks/memory/{{APP_NAME}}/{{DYNO}}

4. Create Task

Begin monitoring an app for memory usage

Endpoint:

Method: POST
URL: {{KAPACITOR_ALERTS_API}}/task/memory

Headers:

Key Value Description
Content-Type application/json

Body:

{
	"app": "{{APP_NAME}}",		// App to monitor
	"dynotype": "web",		// Dyno to monitor (use 'all' to monitor all dynos)
	"warn": "200",			// Warning threshold (in MB)
	"crit": "500",			// Critical threshold (in MB)
	"window": "12h",		// Window to use for results
	"every": "1m",			// How often to check
	"slack": "{{SLACK_CHANNEL}}",	// *Optional* slack channel to notify
	"email": "{{EMAIL}}",		// *Optional* email address to notify
	"post": "{{POST}}"		// *Optional* URL to post a webhook to
}

5. Update Task

Update the configuration for memory usage monitoring on an app

Endpoint:

Method: PATCH
URL: {{KAPACITOR_ALERTS_API}}/task/memory

Headers:

Key Value Description
Content-Type application/json

Body:

{
	"app": "{{APP_NAME}}",		// App to monitor
	"dynotype": "web",		// Dyno to monitor (use 'all' to monitor all dynos)
	"warn": "500",			// Warning threshold (in MB)
	"crit": "700",			// Critical threshold (in MB)
	"window": "12h",		// Window to use for results
	"every": "1m",			// How often to check
	"slack": "{{SLACK_CHANNEL}}",	// *Optional* slack channel to notify
	"email": "{{EMAIL}}",		// *Optional* email address to notify
	"post": "{{POST}}"		// *Optional* URL to post a webhook to
}

6. Delete Task

Stop monitoring an app for memory usage

Endpoint:

Method: DELETE
URL: {{KAPACITOR_ALERTS_API}}/task/memory/{{APP_NAME}}/{{DYNO}}

Headers:

Key Value Description
Content-Type application/json

Release

Send an alert to a Slack channel, email address, or as a webhook when a new version of an app is released.

1. Get All Tasks

Get a list of the configuration of all release tasks

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/tasks/release

2. Get Task

Get the configuration of the release monitoring on an app

Endpoint:

Method: GET
URL: {{KAPACITOR_ALERTS_API}}/task/release/{{APP_NAME}}

3. Create Task

Begin monitoring an app for releases

Endpoint:

Method: POST
URL: {{KAPACITOR_ALERTS_API}}/task/release

Headers:

Key Value Description
Content-Type application/json

Body:

{
	"app": "{{APP_NAME}}",		// App to monitor
	"slack": "{{SLACK_CHANNEL}}",	// *Optional* slack channel to notify
	"email": "{{EMAIL}}",		// *Optional* email address to notify
	"post": "{{POST}}"		// *Optional* URL to post a webhook to
}

4. Update Task

Update the configuration for new release monitoring on an app

Endpoint:

Method: PATCH
URL: {{KAPACITOR_ALERTS_API}}/task/release

Headers:

Key Value Description
Content-Type application/json

Body:

{
	"app": "{{APP_NAME}}",		// App to monitor
	"slack": "{{SLACK_CHANNEL}}",	// *Optional* slack channel to notify
	"email": "{{EMAIL}}",		// *Optional* email address to notify
	"post": "{{POST}}"		// *Optional* URL to post a webhook to
}

5. Delete Task

Stop monitoring an app for releases

Endpoint:

Method: DELETE
URL: {{KAPACITOR_ALERTS_API}}/task/release/{{APP_NAME}}

Back to top