Browse Source

Implement Odoo license expiry monitor.

master
Joachim Desroches 1 year ago
parent
commit
4be512e6c1
Signed by: jdesroches
GPG Key ID: 6778C9C29C02D691
  1. 37
      prometheus-odoo-license-exporter

37
prometheus-odoo-license-exporter

@ -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)
Loading…
Cancel
Save