notification/README.md
2024-01-22 00:24:07 +03:00

3.0 KiB

notification

Install E-Mail/Telegram notifications

Dependencies

  • Python 3.9 or above on inventory hosts (in repo on Debian | from sources in /usr/local/bin on CentOS)

Download a Role

wget -qO- https://git.hmp.today/pavel.muhortov/notification/archive/master.tar.gz | tar -xvz -C .

Edit Role Variables

# nano ./notification/vars/main.yml
sendmail_smtp: smtp.host.zone
sendmail_port: 587
sendmail_from: user@host.zone
sendmail_pass: pass
sendmail_dest: user@host.zone
sendtelegram_api_key: YOURAPIKEY
sendtelegram_silence: true
## single chat
sendtelegram_chat_id: 123456789
## chat topics
sendtelegram_chat_id: -100123456789
sendtelegram_thrd_id: 123

Create Playbook Example

tee ./notification.yml > /dev/null <<'EOF'
- name: Install E-Mail/Telegram notification
  hosts: all
  become: yes
  roles:
  - notification
EOF

Run Playbook

ansible-playbook ./notification.yml

Clean

rm -rf ./notification*

Manually installation E-Mail notification

Dependencies:

# download sendmail-reboot.sh
sudo wget https://git.hmp.today/pavel.muhortov/notification/raw/branch/master/templates/sendmail-reboot.sh -O /etc/init.d/sendmail-reboot.sh
sudo chmod +x /etc/init.d/sendmail-reboot.sh
sudo update-rc.d sendmail-reboot.sh defaults #debian
sudo chkconfig --add /etc/init.d/sendmail-reboot.sh #rhel

# download sendmail-login.sh
sudo wget https://git.hmp.today/pavel.muhortov/notification/raw/branch/master/templates/sendmail-login.sh -O /etc/profile.d/sendmail-login.sh
sudo chmod +x /etc/profile.d/sendmail-login.sh

# edit sendmail.config
sudo tee /usr/local/bin/sendmail.config > /dev/null <<'EOF'
smtp=smtp.host.zone
port=587
from=user@host.zone
pass=pass
dest=user@host.zone
EOF

Manually installation Telegram notification

Dependencies:

# download sendtelegram-reboot.sh
sudo wget https://git.hmp.today/pavel.muhortov/notification/raw/branch/master/templates/sendtelegram-reboot.sh -O /etc/init.d/sendtelegram-reboot.sh
sudo chmod +x /etc/init.d/sendtelegram-reboot.sh
sudo update-rc.d sendtelegram-reboot.sh defaults #debian
sudo chkconfig --add /etc/init.d/sendtelegram-reboot.sh #rhel

# download sendtelegram-login.sh
sudo wget https://git.hmp.today/pavel.muhortov/notification/raw/branch/master/templates/sendtelegram-login.sh -O /etc/profile.d/sendtelegram-login.sh
sudo chmod +x /etc/profile.d/sendtelegram-login.sh

# edit sendtelegram.config
sudo tee /usr/local/bin/sendtelegram.config > /dev/null <<'EOF'
API_URL=https://api.telegram.org/YOURAPIKEY/sendMessage
SILENCE=True
## single chat
CHAT_ID=123456789
## chat topics
CHAT_ID=-100123456789
THRD_ID=123
EOF