mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
![]() |
#!/srv/newsblur/venv/newsblur/bin/python
|
||
|
|
||
|
import sys
|
||
|
sys.path.append('/srv/newsblur')
|
||
|
|
||
|
import subprocess
|
||
|
import requests
|
||
|
import settings
|
||
|
import socket
|
||
|
import pymongo
|
||
|
|
||
|
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()
|
||
|
percent = int(percent.strip('%'))
|
||
|
admin_email = settings.ADMINS[0][1]
|
||
|
failed = False
|
||
|
feeds_fetched = 0
|
||
|
|
||
|
try:
|
||
|
client = pymongo.MongoClient('mongodb://%s' % settings.MONGO_DB['host'])
|
||
|
feeds_fetched = client.newsblur.statistics.find_one({"key": "feeds_fetched"})['value']
|
||
|
except Exception, e:
|
||
|
failed = e
|
||
|
|
||
|
if feeds_fetched < 5000000:
|
||
|
failed = True
|
||
|
|
||
|
if failed:
|
||
|
requests.post(
|
||
|
"https://api.mailgun.net/v2/%s/messages" % settings.MAILGUN_SERVER_NAME,
|
||
|
auth=("api", settings.MAILGUN_ACCESS_KEY),
|
||
|
data={"from": "NewsBlur Monitor: %s <%s>" % (hostname, admin_email),
|
||
|
"to": [admin_email],
|
||
|
"subject": "%s feeds fetched falling: %s" % (hostname, feeds_fetched),
|
||
|
"text": "Usage on %s: %s %s" % (hostname, output, failed)})
|
||
|
print(" ---> Feeds fetched falling! %s" % (feeds_fetched))
|
||
|
else:
|
||
|
print(" ---> Feeds fetched OK: %s" % (feeds_fetched))
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
main()
|