Skip to content

Commit 4ca0b34

Browse files
authored
Merge branch 'master' into add_update_strategy_deployment
2 parents 604bfc4 + 6ceeb2c commit 4ca0b34

File tree

10 files changed

+293
-262
lines changed

10 files changed

+293
-262
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
- Add Webex Incoming Webhook alerter - [#1635](https://github.com/jertel/elastalert2/pull/1635) - @dennis-trapp
99
- Support jinja2 templates in `alertmanager_labels` and `alertmanager_annotations` - [#1642](https://github.com/jertel/elastalert2/pull/1642) - @tgxworld
1010
- [Helm] Add support of update strategy in the deployment [#1642](https://github.com/jertel/elastalert2/pull/1646) - @efazenda
11+
- Add Flashduty alerter - [#1649](https://github.com/jertel/elastalert2/pull/1649) - @pijiang3
12+
1113

1214
## Other changes
1315
- Fix `schema.yaml` to support Kibana 8.17 - [#1631](https://github.com/jertel/elastalert2/pull/1631) - @vpiserchia
1416
- [Helm] Clarified documentation around rootRulesFolder - @jertel
1517
- [IRIS] Fix `iris.py` to overcome a description overwriting bug - [#1643](https://github.com/jertel/elastalert2/pull/1643) - @jmolletAMNH
1618
- Add `metric_<metric_key>_formatted` and `metric_agg_value_formatted` to metric aggregation when using compound query keys - [#1647](https://github.com/jertel/elastalert2/pull/1647) - @dennis-trapp
19+
- Remove lineNotifyAlerter [#1638](https://github.com/jertel/elastalert2/pull/1638) - @nsano-rururu
20+
- Fixed an issue where the test-docker command would cause an error when running old docker-compose [#1638](https://github.com/jertel/elastalert2/pull/1638) - @nsano-rururu
1721

1822
# 2.23.0
1923

Makefile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
.PHONY: all production test docs clean
22

3-
COMPOSE = "-compose"
4-
$(which shell && shell docker$(COMPOSE) 2> /dev/null)
5-
ifneq ($(.SHELLSTATUS),0)
6-
COMPOSE = " compose"
7-
endif
3+
COMPOSE = $(shell if docker compose version >/dev/null 2>&1; then echo " compose"; else echo "-compose"; fi)
84

95
all: production
106

docs/source/alerts.rst

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ or
2626
- discord
2727
- email
2828
- exotel
29+
- flashduty
2930
- gitter
3031
- googlechat
3132
- gelf
@@ -34,7 +35,6 @@ or
3435
- iris
3536
- jira
3637
- lark
37-
- linenotify
3838
- matrixhookshot
3939
- mattermost
4040
- ms_teams
@@ -1417,21 +1417,6 @@ Example usage::
14171417
lark_bot_id: "your lark bot id"
14181418
lark_msgtype: "text"
14191419

1420-
Line Notify
1421-
~~~~~~~~~~~
1422-
1423-
Line Notify will send notification to a Line application. The body of the notification is formatted the same as with other alerters.
1424-
1425-
Required:
1426-
1427-
``linenotify_access_token``: The access token that you got from https://notify-bot.line.me/my/
1428-
1429-
Example usage::
1430-
1431-
alert:
1432-
- "linenotify"
1433-
linenotify_access_token: "Your linenotify access token"
1434-
14351420
Matrix Hookshot
14361421
~~~~~~~~~~~~~~~
14371422

@@ -2634,3 +2619,39 @@ Example usage::
26342619
- "yzj"
26352620
yzj_token: "token"
26362621

2622+
2623+
Flashduty
2624+
~~~~~~~~~~~~~
2625+
2626+
Flashduty alerter will send notification to a Flashduty application. The body of the notification formatted the same as with other alerters.
2627+
2628+
Required:
2629+
2630+
``flashduty_integration_key``: Flashduty integration key.
2631+
``flashduty_title``: Alert title , no more than 512 characters, will be truncated if exceeded. Default to ``ElastAlert Alert``.
2632+
``flashduty_event_status``: Alert status. Can be ``Info``, ``Warning``, ``Critical``, ``Ok``. Defaults to ``Info``.
2633+
2634+
2635+
Example usage::
2636+
2637+
alert_text: "**{0}** - ALERT on host {1}"
2638+
alert_text_args:
2639+
- name
2640+
- hostname
2641+
alert:
2642+
- flashduty
2643+
flashduty_integration_key: "xxx"
2644+
flashduty_title: "elastalert"
2645+
flashduty_event_status: "Warning"
2646+
flashduty_alert_key: "abc"
2647+
flashduty_description: "log error"
2648+
flashduty_check: "Too many occurrences of error logs"
2649+
flashduty_resource: "index_name"
2650+
flashduty_service: "service_name"
2651+
flashduty_metric: "The number of error logs is greater than 5"
2652+
flashduty_group: "sre"
2653+
flashduty_cluster: "k8s"
2654+
flashduty_app: "app"
2655+
flashduty_env: "dev"
2656+
2657+
Please refer to the parameter definition: https://docs.flashcat.cloud/en/flashduty/elastalert2-integration-guide

docs/source/elastalert.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Currently, we have support built in for these alert types:
3939
- Discord
4040
- Email
4141
- Exotel
42+
- Flashduty
4243
- Gitter
4344
- GoogleChat
4445
- Graylog GELF

elastalert/alerters/flashduty.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import json
2+
import warnings
3+
4+
import requests
5+
from elastalert.alerts import Alerter, DateTimeEncoder
6+
from elastalert.util import EAException, elastalert_logger
7+
from requests import RequestException
8+
9+
10+
class FlashdutyAlerter(Alerter):
11+
"""Creates a Flashduty message for each alert"""
12+
13+
required_options = frozenset(["flashduty_integration_key"])
14+
15+
def __init__(self, rule):
16+
super(FlashdutyAlerter, self).__init__(rule)
17+
self.flashduty_integration_key = self.rule.get("flashduty_integration_key", None)
18+
self.flashduty_title = self.rule.get("flashduty_title", "ElastAlert Alert")
19+
self.flashduty_alert_key = self.rule.get("flashduty_alert_key", None)
20+
self.flashduty_description = self.rule.get("flashduty_description", None)
21+
self.flashduty_event_status = self.rule.get("flashduty_event_status", "Info")
22+
self.flashduty_check = self.rule.get("flashduty_check", None)
23+
self.flashduty_service = self.rule.get("flashduty_service", None)
24+
self.flashduty_cluster = self.rule.get("flashduty_cluster", None)
25+
self.flashduty_resource = self.rule.get("flashduty_resource", None)
26+
self.flashduty_metric = self.rule.get("flashduty_metric", None)
27+
self.flashduty_group = self.rule.get("flashduty_group", None)
28+
self.flashduty_env = self.rule.get("flashduty_env", None)
29+
self.flashduty_app = self.rule.get("flashduty_app", None)
30+
31+
32+
def alert(self, matches):
33+
body = self.create_alert_body(matches)
34+
35+
headers = {
36+
"Content-Type": "application/json",
37+
}
38+
39+
payload = {
40+
"title": self.flashduty_title,
41+
"description": self.flashduty_description,
42+
"event_status": self.flashduty_event_status,
43+
"alert_key": self.flashduty_alert_key,
44+
"labels": {
45+
"check": self.flashduty_check,
46+
"service": self.flashduty_service,
47+
"cluster": self.flashduty_cluster,
48+
"resource": self.flashduty_resource,
49+
"metric": self.flashduty_metric,
50+
"group": self.flashduty_group,
51+
"env": self.flashduty_env,
52+
"app": self.flashduty_app,
53+
"information": body,
54+
}
55+
}
56+
57+
try:
58+
response = requests.post(
59+
"https://api.flashcat.cloud/event/push/alert/standard?integration_key=" + self.flashduty_integration_key,
60+
data=json.dumps(payload, cls=DateTimeEncoder),
61+
headers=headers,
62+
)
63+
warnings.resetwarnings()
64+
response.raise_for_status()
65+
except RequestException as e:
66+
raise EAException("Error posting to flashduty: %s" % e)
67+
68+
elastalert_logger.info("Trigger sent to flashduty")
69+
70+
def get_info(self):
71+
return {
72+
"type": "flashduty",
73+
"flashduty_integration_key": self.flashduty_integration_key,
74+
"flashduty_title": self.flashduty_title,
75+
"flashduty_description": self.flashduty_description,
76+
"flashduty_event_status": self.flashduty_event_status,
77+
"flashduty_check": self.flashduty_check,
78+
"flashduty_service": self.flashduty_service,
79+
"flashduty_cluster": self.flashduty_cluster,
80+
"flashduty_resource": self.flashduty_resource,
81+
"flashduty_metric": self.flashduty_metric,
82+
"flashduty_group": self.flashduty_group,
83+
"flashduty_env": self.flashduty_env,
84+
"flashduty_app": self.flashduty_app,
85+
"flashduty_alert_key": self.flashduty_alert_key,
86+
}

elastalert/alerters/line.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

elastalert/loaders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import jsonschema
99
import yaml
1010
import yaml.scanner
11+
from elastalert.alerters.flashduty import FlashdutyAlerter
1112
from jinja2 import Environment
1213
from jinja2 import FileSystemLoader
1314
from jinja2 import Template
@@ -27,7 +28,6 @@
2728
import elastalert.alerters.httppost2
2829
import elastalert.alerters.iris
2930
import elastalert.alerters.lark
30-
import elastalert.alerters.line
3131
import elastalert.alerters.pagertree
3232
import elastalert.alerters.rocketchat
3333
import elastalert.alerters.servicenow
@@ -130,7 +130,6 @@ class RulesLoader(object):
130130
'post': elastalert.alerters.httppost.HTTPPostAlerter,
131131
'post2': elastalert.alerters.httppost2.HTTPPost2Alerter,
132132
'pagertree': elastalert.alerters.pagertree.PagerTreeAlerter,
133-
'linenotify': elastalert.alerters.line.LineNotifyAlerter,
134133
'hivealerter': elastalert.alerters.thehive.HiveAlerter,
135134
'zabbix': ZabbixAlerter,
136135
'discord': elastalert.alerters.discord.DiscordAlerter,
@@ -147,6 +146,7 @@ class RulesLoader(object):
147146
'indexer': IndexerAlerter,
148147
'matrixhookshot': MatrixHookshotAlerter,
149148
'yzj': YzjAlerter,
149+
'flashduty': FlashdutyAlerter,
150150
}
151151

152152
# A partial ordering of alert types. Relative order will be preserved in the resulting alerts list

elastalert/schema.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,6 @@ properties:
659659
lark_bot_id: { type: string }
660660
lark_msgtype: { type: string, enum: [ 'text' ] }
661661

662-
### Line Notify
663-
linenotify_access_token: {type: string}
664-
665662
### Matrix Hookshot
666663
matrixhookshot_ca_certs: {type: [boolean, string]}
667664
matrixhookshot_webhook_url: *arrayOfString
@@ -920,3 +917,17 @@ properties:
920917
yzj_custom_loc: {type: string}
921918
yzj_proxy: {type: string}
922919

920+
### Flashduty
921+
flashduty_integration_key: {type: string}
922+
flashduty_title: {type: string}
923+
flashduty_description: {type: string}
924+
flashduty_event_status: {type: string, enum: [Info, Warning, Critical, Ok]}
925+
flashduty_alert_key: {type: string}
926+
flashduty_check: {type: string}
927+
flashduty_service: {type: string}
928+
flashduty_cluster: {type: string}
929+
flashduty_resource: {type: string}
930+
flashduty_metric: {type: string}
931+
flashduty_group: {type: string}
932+
flashduty_env: {type: string}
933+
flashduty_app: {type: string}

0 commit comments

Comments
 (0)