-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theoooooo add discord alerter #2379
base: beta
Are you sure you want to change the base?
Conversation
Add discord_webhook_url schema to type string. This will prevent errors while working with %s and % in the alerts.py file.
Add discord module needed for the alerter to work properly. (need pip install disword-webhook") Add a new alerter AlerterDiscord at the end of the file. This alerter new at least the url of the webhook the alerter will use to process the alert. I add many options available ; self.discord_emoji_title : Option to replace the static⚠️ in the title of the message posted (tested) self.discord_http_proxy and self.discord_https_proxy : Used to make the alerter work behind a proxy (tested) self.discord_proxy_login and discord_proxy_password : Used for the alerter to authenticate himself behind a proxy (not tested) self.discord_embed_color : Used to choose the color of the embed content send by the alerter (tested) self.discord_embed_footer : Used to add content on the footer of the embed content (tested) self.discord_embed_icon_url : Used to add an icon in the footer of the embed content (tested) I also setup the crop body to 2047 because the limit of the description field in an discord message if 2048 length long. I then update the message displayed if it is too long (not tested)
Import discord module to be able to send webhook messages
Add an exemple of a discord alerter that i wrote.
add another condition if you just want to add a icon-url to the footer unstead of text.
Add discord-webhook as a requirement
added more description
@Theoooooo Any updates to this? Would love to see this merged. |
@CharlieC3 The PR is all done. The only issue that appears in the CI checks is the exemple alert i've put inside the PR. |
Hello, |
There is a way to create a docker image by modifying the https://github.com/jertel/elastalert-docker/blob/master/Dockerfile of jertel / elastalert-docker as follows. We have not confirmed the operation.
|
I found that it doesn't work even if it is merged in the current state.
and bug 1、alerts.py L26 The following description is not required ./elastalert/alerts.py:26:1: F401 'discord_webhook.DiscordWebhook' imported but unused
2、alerts.py L2198 ./elastalert/alerts.py:2198:21: F821 undefined name 'unicode' before
after
3、alerts.py L2229 ./elastalert/alerts.py:2209:9: F841 local variable 'auth' is assigned to but never used before
fix
4、other ./elastalert/alerts.py:2178:1: E302 expected 2 blank lines, found 1 There still seems to be a bug
I deleted "proxies ['http'] ='% s'% (self.discord_http_proxy) if self.discord_http_proxy else None" and it worked. Probably proxies http is no longer set. alerts.py self.discord_http_proxy = self.rule.get('discord_http_proxy', None) proxies = {} if self.discord_http_proxy or self.discord_https_proxy else None example_rules/exemple_discord_any.yaml discord_http_proxy: http_proxy_address README.md and docs/source/elastalert.rst add 「- Discord」 docs/source/ruletypes.rst add
|
It has been merged by pull requesting discord alerter to jertel/elastalert:alt. |
@nsano-rururu Thank you very much! |
example alert:
- discord
alert_subject: a
alert_subject_args: []
alert_text: b
alert_text_args: []
discord_webhook_url: 'https://discord.com/api/webhooks/xxxx/xxxx'
discord_emoji_title: ':lock:'
discord_embed_color: 0xE24D42
discord_embed_footer: 'Message sent by ElastAlert from your computer'
discord_embed_icon_url: 'https://humancoders-formations.s3.amazonaws.com/uploads/course/logo/38/thumb_bigger_formation-elasticsearch.png'
filter:
- query:
query_string:
query: 'message:Quit'
index: mariadblog-*
is_enabled: true
name: a
realert:
minutes: 1
timestamp_field: '@timestamp'
timestamp_type: iso
type: any
use_strftime_index: false |
Merged into elastalert2 |
Added a discord alerter to ElastAlert.
I think i didn't forget to put any necessary piece of code for it to work.
I'm not a python expert to there is probably plenty of room for improvements.
I'm testing this alerter for about 2 week now when i have spare time but it's working properly for me and i'm using it for production level to be able to send alerts to peoples who are using discord.
That's why i'm putting this as a draft to let other peoples review what i've done ^^
There is a description for the biggest commit i did. I also add and modify single lines after that so feel free to navigate though the commits to read the description.
There is clearly verification to do on this work, i'm not really a python expert but i tried to follow the same logic of the alerts.py file while i wrote this alerter.