mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-04-13 09:42:01 +00:00

* master: (27 commits) Removing log override Moving logging over to the newsblur log. Fixing search indexer background task for new celery. Attempting to add gunicorn errors to console/log. Better handling of missing subs. Handling missing user sub on feed delete. Correct encoding for strings on systems that don't have utf-8 as default encoding. Writing in the real urllib3 dependency for requests. Upgrading requests due to urllib3 incompatibility. Login required should use the next parameter. Upgrading django oauth toolkit for django 1.11. Handling newsletters with multiple recipients. Extracting image urls sometimes fails. Handling ajax errors in json views. Adding timeouts to most outbound requests. Sentry SDK 0.19.4. Removing imperfect proxy warning for every story. Found four more GET/POST crosses. Feed unread count may need a POST. Namespacing settings. ...
40 lines
1.7 KiB
Python
Executable file
40 lines
1.7 KiB
Python
Executable file
#!/srv/newsblur/venv/newsblur3/bin/python
|
|
|
|
import sys
|
|
sys.path.append('/srv/newsblur')
|
|
|
|
import subprocess
|
|
import requests
|
|
from newsblur import settings
|
|
import socket
|
|
|
|
def main():
|
|
df = subprocess.Popen(["df", "/"], stdout=subprocess.PIPE)
|
|
output = df.communicate()[0]
|
|
device, size, used, available, percent, mountpoint = output.split("\n")[1].split()
|
|
hostname = socket.gethostname()
|
|
admin_email = settings.ADMINS[0][1]
|
|
|
|
r = requests.get("https://api.mailgun.net/v3/newsletters.newsblur.com/stats/total",
|
|
auth=("api", settings.MAILGUN_ACCESS_KEY),
|
|
params={"event": ["accepted", "delivered", "failed"],
|
|
"duration": "2h"})
|
|
stats = r.json()['stats'][0]
|
|
delivered = stats['delivered']['total']
|
|
accepted = stats['delivered']['total']
|
|
bounced = stats['failed']['permanent']['total'] + stats['failed']['temporary']['total']
|
|
|
|
if bounced / float(delivered) > 0.5:
|
|
requests.post(
|
|
"https://api.mailgun.net/v2/%s/messages" % settings.MAILGUN_SERVER_NAME,
|
|
auth=("api", settings.MAILGUN_ACCESS_KEY),
|
|
data={"from": "NewsBlur Newsletter Monitor: %s <admin@%s.newsblur.com>" % (hostname, hostname),
|
|
"to": [admin_email],
|
|
"subject": "%s newsletters bounced: %s > %s > %s" % (hostname, accepted, delivered, bounced),
|
|
"text": "Newsletters are not being delivered! %s delivered, %s bounced" % (delivered, bounced)})
|
|
print(" ---> %s newsletters bounced: %s > %s > %s" % (hostname, accepted, delivered, bounced))
|
|
else:
|
|
print(" ---> %s newsletters OK: %s > %s > %s" % (hostname, accepted, delivered, bounced))
|
|
|
|
if __name__ == '__main__':
|
|
main()
|