Adding some additional output to expiration command. (#626)

This commit is contained in:
kevgliss 2016-12-21 11:01:21 -08:00 committed by GitHub
parent edc0116a3a
commit 8c5c30dfd4
1 changed files with 4 additions and 0 deletions

View File

@ -26,10 +26,14 @@ def expire(ttl):
"""
Removed all endpoints that have not been recently updated.
"""
print("[+] Staring expiration of old endpoints.")
now = arrow.utcnow()
expiration = now - timedelta(hours=ttl)
endpoints = database.session_query(Endpoint).filter(cast(Endpoint.last_updated, ArrowType) <= expiration)
for endpoint in endpoints:
print("[!] Expiring endpoint: {name} Last Updated: {last_updated}".format(name=endpoint.name, last_updated=endpoint.last_updated))
database.delete(endpoint)
metrics.send('endpoint_expired', 'counter', 1)
print("[+] Finished expiration.")