New column 'downs' to store down servers
This commit is contained in:
pare
72279e5e3c
commit
c6ec648fe2
S'han modificat 2 arxius amb 25 adicions i 8 eliminacions
|
@ -142,7 +142,7 @@ sql = "create table "+table+" (server varchar(200) PRIMARY KEY, federated_with v
|
|||
create_table(db, db_user, table, sql)
|
||||
|
||||
table = "fediverse"
|
||||
sql = "create table "+table+" (server varchar(200) PRIMARY KEY, users INT, updated_at timestamptz, software varchar(50), version varchar(100), first_checked_at timestamptz, last_checked_at timestamptz)"
|
||||
sql = "create table "+table+" (server varchar(200) PRIMARY KEY, users INT, updated_at timestamptz, software varchar(50), version varchar(100), first_checked_at timestamptz, last_checked_at timestamptz, downs int)"
|
||||
create_table(db, db_user, table, sql)
|
||||
|
||||
table = "totals"
|
||||
|
|
31
fediverse.py
31
fediverse.py
|
@ -53,7 +53,7 @@ def get_alive_servers(server):
|
|||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute("select alive, software, users_api, version, first_checked_at from fediverse where server=(%s)", (server,))
|
||||
cur.execute("select alive, software, users_api, version, first_checked_at, downs from fediverse where server=(%s)", (server,))
|
||||
|
||||
row = cur.fetchone()
|
||||
|
||||
|
@ -64,6 +64,7 @@ def get_alive_servers(server):
|
|||
serv_api = row[2]
|
||||
soft_version = row[3]
|
||||
first_checked_at = row[4]
|
||||
downs_qty = row[5]
|
||||
|
||||
cur.close()
|
||||
|
||||
|
@ -158,12 +159,20 @@ def get_alive_servers(server):
|
|||
|
||||
if alive:
|
||||
|
||||
if downs_qty != None:
|
||||
|
||||
downs = downs_qty
|
||||
|
||||
else:
|
||||
|
||||
downs = 0
|
||||
|
||||
if soft_version != "" and soft_version is not None:
|
||||
print("Server " + str(server) + " (" + serv_soft + " " + soft_version + ") is alive!")
|
||||
else:
|
||||
print("Server " + str(server) + " (" + serv_soft + ") is alive!")
|
||||
|
||||
insert_sql = "INSERT INTO fediverse(server, users, updated_at, software, alive, users_api, version, first_checked_at, last_checked_at) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s) ON CONFLICT DO NOTHING"
|
||||
insert_sql = "INSERT INTO fediverse(server, users, updated_at, software, alive, users_api, version, first_checked_at, last_checked_at, downs) VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ON CONFLICT DO NOTHING"
|
||||
|
||||
conn = None
|
||||
|
||||
|
@ -173,15 +182,15 @@ def get_alive_servers(server):
|
|||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute(insert_sql, (server, users, now, serv_soft, alive, serv_api, soft_version, now, now))
|
||||
cur.execute(insert_sql, (server, users, now, serv_soft, alive, serv_api, soft_version, now, now, downs))
|
||||
|
||||
if first_checked_at != None:
|
||||
|
||||
cur.execute("UPDATE fediverse SET users=(%s), updated_at=(%s), software=(%s), alive=(%s), users_api=(%s), version=(%s), last_checked_at=(%s) where server=(%s)", (users, now, serv_soft, alive, serv_api, soft_version, now, server))
|
||||
cur.execute("UPDATE fediverse SET users=(%s), updated_at=(%s), software=(%s), alive=(%s), users_api=(%s), version=(%s), last_checked_at=(%s), downs=(%s) where server=(%s)", (users, now, serv_soft, alive, serv_api, soft_version, now, downs, server))
|
||||
|
||||
else:
|
||||
|
||||
cur.execute("UPDATE fediverse SET users=(%s), updated_at=(%s), software=(%s), alive=(%s), users_api=(%s), version=(%s), first_checked_at=(%s), last_checked_at=(%s) where server=(%s)", (users, now, serv_soft, alive, serv_api, soft_version, now, now, server))
|
||||
cur.execute("UPDATE fediverse SET users=(%s), updated_at=(%s), software=(%s), alive=(%s), users_api=(%s), version=(%s), first_checked_at=(%s), last_checked_at=(%s), downs=(%s) where server=(%s)", (users, now, serv_soft, alive, serv_api, soft_version, now, now, downs, server))
|
||||
|
||||
|
||||
cur.execute("UPDATE world SET checked='t' where server=(%s)", (server,))
|
||||
|
@ -268,6 +277,14 @@ def get_alive_servers(server):
|
|||
|
||||
if alive is False:
|
||||
|
||||
if downs_qty != None:
|
||||
|
||||
downs = downs_qty + 1
|
||||
|
||||
else:
|
||||
|
||||
downs = 1
|
||||
|
||||
conn = None
|
||||
|
||||
try:
|
||||
|
@ -279,11 +296,11 @@ def get_alive_servers(server):
|
|||
|
||||
if first_checked_at != None:
|
||||
|
||||
cur.execute("UPDATE fediverse SET updated_at=(%s), alive=(%s), first_checked_at=(%s) where server=(%s)", (now, alive, NULL, server))
|
||||
cur.execute("UPDATE fediverse SET updated_at=(%s), alive=(%s), first_checked_at=(%s), downs=(%s) where server=(%s)", (now, alive, NULL, downs, server))
|
||||
|
||||
else:
|
||||
|
||||
cur.execute("UPDATE fediverse SET updated_at=(%s), alive=(%s) where server=(%s)", (now, alive, server))
|
||||
cur.execute("UPDATE fediverse SET updated_at=(%s), alive=(%s), downs=(%s) where server=(%s)", (now, alive, downs, server))
|
||||
|
||||
cur.execute("UPDATE world SET checked='t' where server=(%s)", (server,))
|
||||
|
||||
|
|
Loading…
Referencia en una nova incidència