Implement Odoo license expiry monitor.

This commit is contained in:
Joachim Desroches 2021-09-09 16:34:41 +02:00
parent be4c8dc5a5
commit 4be512e6c1
No known key found for this signature in database
GPG key ID: 6778C9C29C02D691

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)