From ac9c36f203456aef17abd79d68588293a1560098 Mon Sep 17 00:00:00 2001 From: mrpk1906 Date: Tue, 24 Nov 2020 22:55:25 +0700 Subject: [PATCH] sent report to telegram channel --- files/conf.maldet | 15 +++++++++++++++ files/internals/functions | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/files/conf.maldet b/files/conf.maldet index 0775a95..fbbc5bb 100644 --- a/files/conf.maldet +++ b/files/conf.maldet @@ -42,6 +42,21 @@ slack_token="AUTH_TOKEN" # where the scan report will be shared. slack_channels="maldetreports" +# Enable or disable telegram alerts +# [0 = disabled, 1 = enabled] +telegram_alert="0" + +# Caption for report file will be sent to telegram channel +telegram_file_caption="maldet alert from $(hostname)" + +# Telegram bot token. +# more information https://core.telegram.org/bots +telegram_bot_token="TELEGRAM_BOT_TOKEN" + +# Telegram channel id +# more information https://stackoverflow.com/questions/33858927/how-to-obtain-the-chat-id-of-a-private-telegram-channel?answertab=active#tab-top +telegram_channel_id="TELEGRAM_CHANNEL_ID" + # This controls the daily automatic updates of LMD signature files # and cleaner rules. The signature update process preserves any # custom signature or cleaner files. It is highly recommended that this diff --git a/files/internals/functions b/files/internals/functions index ef6d996..d87613d 100644 --- a/files/internals/functions +++ b/files/internals/functions @@ -1492,6 +1492,17 @@ genalert() { fi fi fi + + if [ "$telegram_alert" == "1" ]; then + if [ "$type" == "file" ] && [ -f "$file" ]; then + telegram_response=$(curl -F "document=@$file" -F "caption=$telegram_file_caption" "https://api.telegram.org/$telegram_bot_token/sendDocument?chat_id=$telegram_channel_id" | grep -oP '^{"ok":true') + if [ "$telegram_response" ]; then + eout "{alert} scan report sent to telegram channel: $telegram_channel_id" 0 + else + eout "{alert} could not upload scan report to telegram channel, alert discarded" 1 + fi + fi + fi }