Implement Odoo license expiry monitor.

This commit is contained in:
Joachim Desroches 2021-09-09 16:34:41 +02:00
parent be4c8dc5a5
commit 4be512e6c1
Signed by untrusted user who does not match committer: jdesroches
GPG Key ID: 6778C9C29C02D691
1 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,37 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from prometheus_client import start_http_server, Gauge
from datetime import datetime
from time import sleep
import psycopg2
USER = "odoo"
HTTP_PORT = 9402
INTERVAL = 10
# FIXME: Make a parameter
DBNAME = "edurable_staging"
if __name__ == '__main__':
# Setup prometheus Gauge
prom_days = Gauge(
'odoo_license_remaining_days',
"Remaining days before Odoo license expiration")
# Serve metrics over HTTP
start_http_server(HTTP_PORT)
# Open connection
with psycopg2.connect(database=DBNAME, user=USER) as conn:
cur = conn.cursor()
while True:
cur.execute("SELECT value FROM ir_config_parameter WHERE key =" +
"'database.expiration_date';")
expiration_date = datetime.strptime(cur.fetchone()[0].split()[0],
"%Y-%m-%d").date()
now = datetime.now().date()
prom_days.set((expiration_date - now).days)
sleep(INTERVAL)