Skip to content
Snippets Groups Projects
Commit b198359a authored by Tomasz Wolniewicz's avatar Tomasz Wolniewicz
Browse files

arring sripts used to add link information - they only are neede if the...

arring sripts used to add link information - they only are neede if the database does not have this info or you want to renew it for some reason
parent 0c04b48c
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=invalid-name
"""
eduGAIN link checker
This script is setting the last OK status. It genetates UPDATE SQL queries
but does not execute them. This is done like that on purpose.
This script is meant to run just once. It is probably subopimal
but siece it is a one-timer, I did not want to waste extra time on it.
The user for this script needs only read access. Narurally, when loading
the resulting commands you will need write access to the federation_links table.
"""
import MySQLdb
db_host = 'your_host'
db_user = 'some_user'
db_password = 'the_password'
db_database = 'your_db'
def mysql_select(query):
"""
execute query
"""
cur.execute(query)
_current = cur.fetchone()
_res = []
while _current:
_row = _current
_current = cur.fetchone()
if _row is None:
continue
if len(_row) == 1:
_res.append(_row[0])
else:
_res.append(_row)
return _res
def set_last_ok(fed, timeLimit):
for url_type in ['registration', 'policy', 'fed_url', 'security_url']:
query = "SELECT result_code, url FROM federation_links where code = '" + fed + "' AND url_type = '" + url_type + "' AND test_time = '"+timeLimit+"'"
res = mysql_select(query)
for r in res:
if r[0] == 0:
q1 = "UPDATE federation_links SET last_ok = '"+timeLimit+"' WHERE code = '" + fed + "' AND url_type = '" + url_type + "' AND url = '"+r[1]+"' AND test_time = '"+timeLimit+"'"
print(q1+";")
else:
query = "SELECT test_time FROM federation_links where code = '" + fed + "' AND url_type = '" + url_type + "' AND url = '"+r[1]+"' AND result_code = 0 AND test_time < '"+timeLimit+"' ORDER BY test_time DESC LIMIT 1"
res_t = mysql_select(query)
if len(res_t) == 1:
q1 = "UPDATE federation_links SET last_ok = '"+res_t[0].isoformat()+"' WHERE code = '" + fed + "' AND url_type = '" + url_type + "' AND url = '"+r[1]+"' AND test_time = '"+timeLimit+"'"
print(q1+";")
mys = MySQLdb.connect(host= db_host, user=db_user, password=db_password,
db=db_database, use_unicode=True, charset="utf8")
mys.autocommit(True)
cur = mys.cursor()
cur.execute('set names utf8')
cur.execute('set @@old_mode="NO_DUP_KEY_WARNINGS_WITH_IGNORE"')
query = "SELECT distinct(code) as code FROM federation_links"
feds = mysql_select(query)
query = "SELECT test_time FROM federation_links_checks ORDER by test_time"
res = mysql_select(query)
for test in res:
testTime = test.isoformat()
for fed in feds:
set_last_ok(fed, testTime)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# pylint: disable=invalid-name
"""
eduGAIN link checker
This script is meant to set the same_status_since field by analysing the test results.
It produces an SQL file meant to be fed into to the DB. On purpose we are not running the updates
from the script itself.
This script needs be run only once!
The user for this script needs only read access. Narurally, when loading
the resulting commands you will need write access to the federation_links table.
"""
import MySQLdb
import sys
db_host = 'your_host'
db_user = 'some_user'
db_password = 'the_password'
db_database = 'your_db'
def mysql_select(query):
"""
execute query
"""
cur.execute(query)
_current = cur.fetchone()
_res = []
while _current:
_row = _current
_current = cur.fetchone()
if _row is None:
continue
if len(_row) == 1:
_res.append(_row[0])
else:
_res.append(_row)
return _res
def getTestResults(testTime):
tResults = {}
query = "SELECT code, url_type, url, result from federation_links where test_time = '" + testTime +"'"
res = mysql_select(query)
for r in res:
fed = r[0]
url_type = r[1]
url = r[2]
result = r[3]
tResults[fed,url_type,url] = result
return(tResults)
mys = MySQLdb.connect(host= db_host, user=db_user, password=db_password,
db=db_database, use_unicode=True, charset="utf8")
mys.autocommit(True)
cur = mys.cursor()
cur.execute('set names utf8')
cur.execute('set @@old_mode="NO_DUP_KEY_WARNINGS_WITH_IGNORE"')
testTimes = []
query = "SELECT test_time FROM federation_links_checks order by test_time"
res = mysql_select(query)
for test in res:
testTimes.append(test.isoformat())
currTests = getTestResults(testTimes[0])
statusTime = {}
for (fed, url_type, url) in currTests:
statusTime[fed, url_type, url] = testTimes[0]
prevTestTime = {}
for testTime in testTimes:
prevTests = currTests
currTests = getTestResults(testTime)
for (fed, url_type, url) in currTests:
if (fed, url_type, url) not in prevTests.keys() or prevTests[fed, url_type, url] != currTests[fed, url_type, url]:
statusTime[fed, url_type, url] = testTime
query = "UPDATE federation_links SET same_status_since ='" + statusTime[fed, url_type, url] + "' WHERE test_time = '" + testTime + "' AND code = '"+fed+"' AND url_type ='"+url_type+"' AND url = '"+url+"'"
print(query+';')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment