Implement Odoo license expiry monitor.
This commit is contained in:
parent
be4c8dc5a5
commit
4be512e6c1
1 changed files with 37 additions and 0 deletions
37
prometheus-odoo-license-exporter
Executable file
37
prometheus-odoo-license-exporter
Executable 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)
|
Loading…
Reference in a new issue