1. Buat file konfigurasi bot telegram agar notifikasi file log kita ke kirim ke telegram
sudo nano /home/webserv2/notifikasi/tg-send.shCHAT_ID=Chat_ID_Telegram_Group_Bot (example : -344035569)TOKEN=Token_Bot_telegram (example : 882206788:AAE1x6WHUvhumE-sBYlJqCj0jUQFIguPZOI)curl -s "https://api.telegram.org/bot$TOKEN/sendMessage?chat_id=$CHAT_ID" --data-urlencode "text=[Log Website] $1"
kemudian save, dan ubah pengaturan chmod untuk file tadi.
chmod +x /home/webserv2/notifikasi/tg-send.sh
2. Buat file filter pattern untuk menyaring log yang akan di kirim ke notifikasi
sudo nano /home/webserv2/notifikasi/phperror.conftype=Singleptype=RegExppattern=WhatWebdesc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"type=Singleptype=RegExppattern=pythondesc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"type=Singleptype=RegExppattern=curldesc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"type=Singleptype=RegExppattern=webtechdesc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"type=Singleptype=RegExppattern=404desc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"type=Singleptype=RegExppattern=302desc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"type=Singleptype=RegExppattern=sqlmapdesc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"type=Singleptype=RegExppattern=AH01630desc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"type=Singleptype=RegExppattern=ssh2desc=$0action=shellcmd /home/webserv2/notifikasi/tg-send.sh "$0"
kemudian save
3. Buat file untuk menjalankan file notifikasi dan menentukan file log apa saja yang akan dimasukan ke notifikasi log tersebut
sudo /home/webserv2/notifikasi/run.sh#!/bin/bashsec -conf=/home/webserv2/notifikasi/phperror.conf -input=/var/log/apache2/other_vhosts_access.log -detach --bufsize=1sec -conf=/home/webserv2/notifikasi/phperror.conf -input=/var/log/auth.log -detach --bufsize=1
kemudian save, dan ubah pengaturan chmod untuk file tadi.
chmod +x /home/webserv2/notifikasi/run.sh
3. Cara Menjalankan File notifikasi, agar memudahkan menjalankan lewat terminal
sudo nano /usr/bin/notifikasi
#!/bin/bashbash /home/webserv2/notifikasi/run.sh
kemudian save, dan ubah pengaturan chmod untuk file tadi.
chmod +x /usr/bin/notifikasi
4. Cara Menjalankan autorun saat server hidup, buat sebuah file service
sudo nano /etc/systemd/system/notifikasi.service
Description=File_Notifikasi_LogWants=network.targetAfter=syslog.target network-online.target[Service]Type=simpleExecStart=/usr/bin/notifikasiRestart=on-failureRestartSec=10KillMode=process[Install]WantedBy=multi-user.target
save file tersebut, kemudian jalankan perintah di bawah ini.
sudo systemctl daemon-reload
sudo systemctl enable notifikasi.service
sudo systemctl start notifikasi.service
sudo reboot
notifikasi log yang terkirim telegram sudah automatis di jalankan server saat server hidup.
SELESAI.