Files
postgres-web/tools/auth_changetrack/nagios_check.py
Magnus Hagander c1fb5de080 Implement synchronization for community authentication
This adds the concept of an apiurl to each site that uses community
authentication, that the main website server can make calls to and send
updates. This URL will receive POSTs from the main website when a user
account that has been used on this site gets updated, and can then
optionally update it's local entries with it (the django plugin sample
is updated to handle this fully).

Updates are only sent for users that have a history of having logged
into the specific site -- this way we avoid braodcasting user
information to sites requiring specific constent that the user hasn't
given, and also decreases the amount of updates that have to be sent.

Updates are queued by the system in a table and using listen/notify a
daemon that's running picks up what needs to be updated and posts it to
the endpoints. If this daemon is not running, obviously nothing gets
sent.

Updates are tracked using triggers in the database which push
information into this queue.
2020-08-11 11:33:46 +02:00

40 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
import sys
import psycopg2
from datetime import timedelta
# Up to 5 minutes delay is ok
WARNING_THRESHOLD = timedelta(minutes=5)
# More than 15 minutes something is definitely wrong
CRITICAL_THRESHOLD = timedelta(minutes=15)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: nagios_check.py <dsn>")
sys.exit(1)
conn = psycopg2.connect(sys.argv[1])
curs = conn.cursor()
# Get the oldest entry that has not been completed, if any
curs.execute("SELECT COALESCE(max(now()-changedat), '0') FROM account_communityauthchangelog")
rows = curs.fetchall()
conn.close()
if len(rows) == 0:
print("OK, queue is empty")
sys.exit(0)
age = rows[0][0]
if age < WARNING_THRESHOLD:
print("OK, queue age is %s" % age)
sys.exit(0)
elif age < CRITICAL_THRESHOLD:
print("WARNING, queue age is %s" % age)
sys.exit(1)
else:
print("CRITICAL, queue age is %s" % age)
sys.exit(2)