-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcsf-lfd-notifications.sh
44 lines (34 loc) · 1.3 KB
/
csf-lfd-notifications.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
######################################################################
######## CSF LFD Notifications #######################################
######################################################################
# You will need to enable the relevant notifications in your CSF config file
# ie LF_SSH_EMAIL_ALERT etc. If these aren't enabled the log file won't have
# log entries to send via telegram
######################################################################
source telegram.conf
echo "$token" > /dev/null 2&>1
echo "$chat_id" > /dev/null 2&>1
#Below are emoji codes #######################################
# go to https://unicode.org/emoji/charts/full-emoji-list.html
# you will need its "U+1F4EB" code MINUS the + As seen below
##############################################################
padlock=$'\U1F512'
lookingglass=$'\U1F50D'
#Telegram API to send notification.
function telegram_send
{
curl -s -X POST https://api.telegram.org/bot"$token"/sendMessage -d chat_id="$chat_id" -d text="$padlock CSF LFD alert $lookingglass
$(hostname)
$message"
}
tail -fn0 /var/log/lfd.log |
while read -r line
do
[[ "$line" != *"*"* ]] && continue
echo $line > /tmp/lfd.txt
message=$(</tmp/lfd.txt)
echo "$message" > /dev/null 2&>1
telegram_send > /dev/null 2&>1
rm -r /tmp/lfd.txt
done