37 lines
847 B
Django/Jinja
37 lines
847 B
Django/Jinja
#!/usr/bin/env python3
|
|
|
|
import json
|
|
|
|
import requests
|
|
|
|
import sudoisinflux
|
|
|
|
|
|
def check():
|
|
r = requests.get("https://federationtester.matrix.org/api/report?server_name={{ matrix_domain }}")
|
|
r.raise_for_status()
|
|
j = r.json()
|
|
|
|
# bool -> int
|
|
assert isinstance(j['FederationOK'], bool)
|
|
|
|
federation_ok = int(j['FederationOK'])
|
|
assert federation_ok == 0 or federation_ok == 1
|
|
|
|
addr = j['DNSResult']['Addrs'][0]
|
|
ssl_valid_until_ts = j['ConnectionReports'][addr]['Keys']['valid_until_ts']
|
|
|
|
tags = {
|
|
"matrix_domain": "{{ matrix_domain }}",
|
|
"addr": addr
|
|
}
|
|
fields = {
|
|
"federation_ok": int(federation_ok),
|
|
"ssl_valid_util_ts": int(ssl_valid_until_ts)
|
|
}
|
|
|
|
sudoisinflux.write_datapoint("matrix_federation", tags, fields, precision="h")
|
|
|
|
if __name__ == "__main__":
|
|
check()
|