Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import http.client
- import urllib
- import subprocess
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- import smtplib
- import http.client, urllib
- import urllib.request
- def main():
- output = subprocess.run(["/bin/seaf-cli", "status"], capture_output=True)
- print (output.stdout)
- if "synchronized" in str(output.stdout):
- crashed = 0
- else:
- crashed = 1
- if "error" in str(output.stdout):
- error = 1
- else:
- error = 0
- if crashed == 1:
- print("Crashed")
- send_notification("Seafile_CLI-Sync possibly crashed")
- if crashed == 0 and error == 0:
- send_notification("Doing nothing")
- if crashed == 0 and error == 1:
- print("Send error message")
- send_notification("Seafile-cli-sync shows error")
- def send_notification(message):
- send_email(message)
- pushover(message)
- telegram_notification(message)
- def pushover(subject):
- conn = http.client.HTTPSConnection("api.pushover.net:443")
- conn.request("POST", "/1/messages.json",
- urllib.parse.urlencode({
- "token": "xxxxxxxxxxxxxxxxxxxx",
- "user": "xxxxxxxxxxxxxxxxxx",
- "message": subject,
- }), {"Content-type": "application/x-www-form-urlencoded"})
- conn.getresponse()
- def telegram_notification(subject):
- conn = http.client.HTTPSConnection("api.telegram.org:443")
- conn.request("POST", "/botxxxxxxxxxx:xxxxxxxxxxxxx/sendMessage?",
- urllib.parse.urlencode({
- 'chat_id': 000000000000000,
- 'text': subject,
- }), {"Content-type": "application/x-www-form-urlencoded"})
- conn.getresponse()
- def send_email(subject, message='No message provided'):
- msg = MIMEMultipart()
- password = "xxxxxxxxxxxxxx"
- msg['Subject'] = subject
- msg.attach(MIMEText(message, 'plain'))
- server = smtplib.SMTP('smtp.xxxxxx.xx: 587')
- server.starttls()
- server.login(msg['From'], password)
- server.sendmail(msg['From'], msg['To'], msg.as_string())
- server.quit()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement