Skip to content

Instantly share code, notes, and snippets.

@TTTPOB
Created February 16, 2021 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TTTPOB/635ba0197b88fae17ab17fea9cb70db0 to your computer and use it in GitHub Desktop.
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
[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
[Unit]
[Timer]
OnBootSec=60
OnCalendar=11:00
Persistent=true
[Install]
WantedBy=timers.target
#!/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