Created
May 12, 2017 13:40
-
-
Save tonybolanyo/2a01a468edf44b33a8750ed25ded0314 to your computer and use it in GitHub Desktop.
Using pushover from django
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
import logging | |
import httplib | |
import urllib | |
PUSHOVER_APPLICATION_TOKEN = "YOUR_TOKEN_HERE" | |
PUSHOVER_LOG_USER_TOKENS = [ | |
"USER_TOKEN_HERE", # Joe the admin | |
] | |
class PushoverHandler(logging.Handler): | |
"""A logging handler which pushes notifications | |
to site admins via Pushover.net""" | |
def emit(self, record): | |
for user_token in PUSHOVER_LOG_USER_TOKENS: | |
conn = httplib.HTTPSConnection("api.pushover.net:443") | |
conn.request("POST", "/1/messages", | |
urllib.urlencode({ | |
"token": PUSHOVER_APPLICATION_TOKEN, | |
"user": user_token, | |
"message": record.getMessage(), | |
}), | |
{ "Content-type": "application/x-www-form-urlencoded" }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from https://github.com/zacharytamas/django-pushover/blob/master/pushover_handler.py