Exports remaining Odoo license days to Prometheus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

42 lines
1.2 KiB

#!/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
import sys
USER = "odoo"
HTTP_PORT = 9402
INTERVAL = 10
if __name__ == '__main__':
if len(sys.argv) == 2:
DBNAME = sys.argv[1]
else:
sys.exit("Invalid number of arguments. " +
"Usage: {} [dbname]".format(sys.argv[0]))
# 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)