Refactor integrations
This commit is contained in:
parent
72332eddfc
commit
7b385a8790
16 changed files with 145 additions and 112 deletions
|
|
@ -2,7 +2,7 @@ import pytest
|
|||
|
||||
from apps.alerts.incident_appearance.templaters import AlertSlackTemplater
|
||||
from apps.alerts.models import AlertGroup
|
||||
from apps.integrations.metadata.configuration import grafana
|
||||
from config_integrations import grafana
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ from apps.alerts.incident_appearance.templaters import (
|
|||
AlertWebTemplater,
|
||||
)
|
||||
from apps.alerts.models import Alert, AlertReceiveChannel
|
||||
from apps.integrations.metadata.configuration import grafana
|
||||
from config_integrations import grafana
|
||||
from common.jinja_templater import jinja_template_env
|
||||
from common.utils import getattrd
|
||||
|
||||
|
|
|
|||
|
|
@ -1,99 +0,0 @@
|
|||
# Main
|
||||
enabled = True
|
||||
title = "Amazon SNS"
|
||||
slug = "amazon_sns"
|
||||
short_description = None
|
||||
is_displayed_on_web = True
|
||||
description = None
|
||||
is_featured = False
|
||||
is_able_to_autoresolve = True
|
||||
is_demo_alert_enabled = True
|
||||
|
||||
description = None
|
||||
|
||||
# Default templates
|
||||
slack_title = """\
|
||||
{% if payload|length == 0 -%}
|
||||
{% set title = payload.get("AlarmName", "Alert") %}
|
||||
{%- else -%}
|
||||
{% set title = "Alert" %}
|
||||
{%- endif %}
|
||||
|
||||
*<{{ grafana_oncall_link }}|#{{ grafana_oncall_incident_id }} {{ title }}>* via {{ integration_name }}
|
||||
{% if source_link %}
|
||||
(*<{{ source_link }}|source>*)
|
||||
{%- endif %}"""
|
||||
|
||||
slack_message = """\
|
||||
{% if payload|length == 1 and "message" in payload -%}
|
||||
{{ payload.get("message", "Non-JSON payload received. Please make sure you publish monitoring Alarms to SNS, not logs: https://docs.amixr.io/#/integrations/amazon_sns") }}
|
||||
{%- else -%}
|
||||
*State* {{ payload.get("NewStateValue", "NO") }}
|
||||
Region: {{ payload.get("Region", "Undefined") }}
|
||||
_Description_: {{ payload.get("AlarmDescription", "Undefined") }}
|
||||
{%- endif %}
|
||||
"""
|
||||
|
||||
slack_image_url = None
|
||||
|
||||
web_title = """\
|
||||
{% if payload|length == 0 -%}
|
||||
{{ payload.get("AlarmName", "Alert")}}
|
||||
{%- else -%}
|
||||
Alert
|
||||
{%- endif %}"""
|
||||
|
||||
web_message = """\
|
||||
{% if payload|length == 1 and "message" in payload -%}
|
||||
{{ payload.get("message", "Non-JSON payload received. Please make sure you publish monitoring Alarms to SNS, not logs: https://docs.amixr.io/#/integrations/amazon_sns") }}
|
||||
{%- else -%}
|
||||
**State** {{ payload.get("NewStateValue", "NO") }}
|
||||
Region: {{ payload.get("Region", "Undefined") }}
|
||||
*Description*: {{ payload.get("AlarmDescription", "Undefined") }}
|
||||
{%- endif %}
|
||||
"""
|
||||
|
||||
web_image_url = slack_image_url
|
||||
|
||||
sms_title = web_title
|
||||
|
||||
phone_call_title = web_title
|
||||
|
||||
email_title = web_title
|
||||
|
||||
email_message = "{{ payload|tojson_pretty }}"
|
||||
|
||||
telegram_title = sms_title
|
||||
|
||||
telegram_message = """\
|
||||
{% if payload|length == 1 and "message" in payload -%}
|
||||
{{ payload.get("message", "Non-JSON payload received. Please make sure you publish monitoring Alarms to SNS, not logs: https://docs.amixr.io/#/integrations/amazon_sns") }}
|
||||
{%- else -%}
|
||||
<b>State</b> {{ payload.get("NewStateValue", "NO") }}
|
||||
Region: {{ payload.get("Region", "Undefined") }}
|
||||
<i>Description</i>: {{ payload.get("AlarmDescription", "Undefined") }}
|
||||
{%- endif %}
|
||||
"""
|
||||
|
||||
telegram_image_url = slack_image_url
|
||||
|
||||
source_link = """\
|
||||
{% if payload|length == 0 -%}
|
||||
{% if payload.get("Trigger", {}).get("Namespace") == "AWS/ElasticBeanstalk" -%}
|
||||
https://console.aws.amazon.com/elasticbeanstalk/home?region={{ payload.get("TopicArn").split(":")[3] }}
|
||||
{%- else -%}
|
||||
https://console.aws.amazon.com/cloudwatch//home?region={{ payload.get("TopicArn").split(":")[3] }}
|
||||
{%- endif %}
|
||||
{%- endif %}"""
|
||||
|
||||
grouping_id = web_title
|
||||
|
||||
resolve_condition = """\
|
||||
{{ payload.get("NewStateValue", "") == "OK" }}
|
||||
"""
|
||||
|
||||
acknowledge_condition = None
|
||||
|
||||
group_verbose_name = web_title
|
||||
|
||||
example_payload = {"foo": "bar"}
|
||||
66
engine/config_integrations/elastalert.py
Normal file
66
engine/config_integrations/elastalert.py
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
# Main
|
||||
enabled = True
|
||||
title = "Elastalert"
|
||||
slug = "elastalert"
|
||||
short_description = "Elastic"
|
||||
is_displayed_on_web = True
|
||||
description = None
|
||||
is_featured = False
|
||||
is_able_to_autoresolve = True
|
||||
is_demo_alert_enabled = True
|
||||
|
||||
description = None
|
||||
|
||||
# Default templates
|
||||
slack_title = """\
|
||||
*<{{ grafana_oncall_link }}|#{{ grafana_oncall_incident_id }} Incident>* via {{ integration_name }}
|
||||
{% if source_link %}
|
||||
(*<{{ source_link }}|source>*)
|
||||
{%- endif %}"""
|
||||
|
||||
slack_message = "```{{ payload|tojson_pretty }}```"
|
||||
|
||||
slack_image_url = None
|
||||
|
||||
web_title = "Incident"
|
||||
|
||||
web_message = """\
|
||||
```
|
||||
{{ payload|tojson_pretty }}
|
||||
```
|
||||
"""
|
||||
|
||||
web_image_url = slack_image_url
|
||||
|
||||
sms_title = web_title
|
||||
|
||||
phone_call_title = sms_title
|
||||
|
||||
email_title = web_title
|
||||
|
||||
email_message = "{{ payload|tojson_pretty }}"
|
||||
|
||||
telegram_title = sms_title
|
||||
|
||||
telegram_message = "<code>{{ payload|tojson_pretty }}</code>"
|
||||
|
||||
telegram_image_url = slack_image_url
|
||||
|
||||
source_link = None
|
||||
|
||||
grouping_id = '{{ payload.get("alert_uid", "")}}'
|
||||
|
||||
resolve_condition = """\
|
||||
{%- if "is_amixr_heartbeat_restored" in payload -%}
|
||||
{# We don't know the payload format from your integration. #}
|
||||
{# The heartbeat alerts will go here so we check for our own key #}
|
||||
{{ payload["is_amixr_heartbeat_restored"] }}
|
||||
{%- else -%}
|
||||
{{ payload.get("state", "").upper() == "OK" }}'
|
||||
{%- endif %}"""
|
||||
|
||||
acknowledge_condition = None
|
||||
|
||||
group_verbose_name = "Incident"
|
||||
|
||||
example_payload = {"message": "This alert was sent by user for the demonstration purposes"}
|
||||
65
engine/config_integrations/kapacitor.py
Normal file
65
engine/config_integrations/kapacitor.py
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# Main
|
||||
enabled = True
|
||||
title = "Kapacitor"
|
||||
slug = "kapacitor"
|
||||
short_description = "InfluxDB"
|
||||
description = None
|
||||
is_displayed_on_web = True
|
||||
is_featured = False
|
||||
is_able_to_autoresolve = True
|
||||
is_demo_alert_enabled = True
|
||||
|
||||
description = None
|
||||
|
||||
# Default templates
|
||||
slack_title = """\
|
||||
*<{{ grafana_oncall_link }}|#{{ grafana_oncall_incident_id }} {{ payload.get("id", "Title undefined (check Slack Title Template)") }}>* via {{ integration_name }}
|
||||
{% if source_link %}
|
||||
(*<{{ source_link }}|source>*)
|
||||
{%- endif %}"""
|
||||
|
||||
slack_message = """\
|
||||
```{{ payload|tojson_pretty }}```
|
||||
"""
|
||||
|
||||
slack_image_url = None
|
||||
|
||||
web_title = '{{ payload.get("id", "Title undefined (check Web Title Template)") }}'
|
||||
|
||||
web_message = """\
|
||||
```
|
||||
{{ payload|tojson_pretty }}
|
||||
```
|
||||
"""
|
||||
|
||||
web_image_url = slack_image_url
|
||||
|
||||
sms_title = web_title
|
||||
|
||||
phone_call_title = web_title
|
||||
|
||||
email_title = web_title
|
||||
|
||||
email_message = slack_message
|
||||
|
||||
telegram_title = sms_title
|
||||
|
||||
telegram_message = "<code>{{ payload|tojson_pretty }}</code>"
|
||||
|
||||
telegram_image_url = slack_image_url
|
||||
|
||||
source_link = None
|
||||
|
||||
grouping_id = '{{ payload.get("id", "") }}'
|
||||
|
||||
resolve_condition = '{{ payload.get("level", "").startswith("OK") }}'
|
||||
|
||||
acknowledge_condition = None
|
||||
|
||||
group_verbose_name = '{{ payload.get("id", "") }}'
|
||||
|
||||
example_payload = {
|
||||
"id": "TestAlert",
|
||||
"message": "This alert was sent by user for the demonstration purposes",
|
||||
"data": "{foo: bar}",
|
||||
}
|
||||
|
|
@ -424,15 +424,16 @@ FEATURE_EXTRA_MESSAGING_BACKENDS_ENABLED = getenv_boolean("FEATURE_EXTRA_MESSAGI
|
|||
EXTRA_MESSAGING_BACKENDS = []
|
||||
|
||||
INSTALLED_ONCALL_INTEGRATIONS = [
|
||||
"apps.integrations.metadata.configuration.alertmanager",
|
||||
"apps.integrations.metadata.configuration.grafana",
|
||||
"apps.integrations.metadata.configuration.grafana_alerting",
|
||||
"apps.integrations.metadata.configuration.formatted_webhook",
|
||||
"apps.integrations.metadata.configuration.webhook",
|
||||
"apps.integrations.metadata.configuration.amazon_sns",
|
||||
"apps.integrations.metadata.configuration.heartbeat",
|
||||
"apps.integrations.metadata.configuration.inbound_email",
|
||||
"apps.integrations.metadata.configuration.maintenance",
|
||||
"apps.integrations.metadata.configuration.manual",
|
||||
"apps.integrations.metadata.configuration.slack_channel",
|
||||
"config_integrations.alertmanager",
|
||||
"config_integrations.grafana",
|
||||
"config_integrations.grafana_alerting",
|
||||
"config_integrations.formatted_webhook",
|
||||
"config_integrations.webhook",
|
||||
"config_integrations.kapacitor",
|
||||
"config_integrations.elastalert",
|
||||
"config_integrations.heartbeat",
|
||||
"config_integrations.inbound_email",
|
||||
"config_integrations.maintenance",
|
||||
"config_integrations.manual",
|
||||
"config_integrations.slack_channel",
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue