-
-
Save hivefans/2b8692f12efb2b6018cd to your computer and use it in GitHub Desktop.
|-|{"files":{"pushbullet_logging.py":{"env":"plain"}},"tag":"bigdata"}
This file contains hidden or 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
| #!/usr/bin/env python | |
| #coding:utf-8 | |
| import logging | |
| import requests | |
| import json | |
| _session = requests.Session() | |
| #APT KEY | |
| _pushbullet = "XXXXXXXXXXXXXXXXXXXXXXX" | |
| def pushbullet(title,sms): | |
| headers = {"Content-Type": "application/json"} | |
| post_data = {"type": "note", | |
| "title": title, | |
| "body": sms} | |
| a = _session.post("https://api.pushbullet.com/v2/pushes", | |
| auth =(_pushbullet,""), | |
| headers=headers, | |
| data=json.dumps(post_data)) | |
| if "error" in a.text: | |
| raise Exception(u"卧槽,粗大事了") | |
| return True | |
| class pushbulletHandler(logging.Handler): | |
| def __init__(self): | |
| super(pushbulletHandler,self).__init__() | |
| self.setLevel(logging.CRITICAL) | |
| def emit(self, record): | |
| pushbullet(u"某某脚本", self.format(record)) | |
| log = logging.getLogger(__name__) | |
| log.addHandler(pushbulletHandler()) | |
| log.critical(u"紧急信息,请处理") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment