Created
February 16, 2021 15:44
-
-
Save TTTPOB/635ba0197b88fae17ab17fea9cb70db0 to your computer and use it in GitHub Desktop.
oversimplified script to monitor zpool status and send it to telegram via a bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Monitoring the zpool on my machine | |
[Service] | |
ExecStart=/usr/local/bin/zfsMonitor | |
Type=oneshot | |
StandardOutput=journal | |
User=root | |
[Install] | |
WantedBy = multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
[Timer] | |
OnBootSec=60 | |
OnCalendar=11:00 | |
Persistent=true | |
[Install] | |
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import requests | |
import subprocess | |
BOTTOKEN="xxxxxxxxxxxxxxx" | |
# I need this because I live in chn | |
proxies={ | |
'http': 'http://localhost:7890', | |
'https': 'http://localhost:7890' | |
} | |
zfsStatus=subprocess.run(['zpool','status'],stdout=subprocess.PIPE).stdout.decode('utf-8') | |
messageBody={ | |
"chat_id":'xxxxxxxxx', | |
"text": '`'+zfsStatus+'`', | |
"disable_notification": True, | |
"parse_mode":"markdown" | |
} | |
requests.post( | |
url="https://api.telegram.org/bot"+BOTTOKEN+"/sendMessage", | |
data=messageBody, | |
proxies=proxies | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment