From f0fec1582434c9218c3a76aef094cc511e353df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 27 May 2022 10:39:54 +0200 Subject: [PATCH] munin: update for python 3 (#63779) --- munin/authentic_count_ | 8 ++++---- munin/authentic_count_cmd.py | 6 +++--- munin/publik_count | 20 ++++++++++---------- munin/publik_count_ | 24 ++++++++++++------------ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/munin/authentic_count_ b/munin/authentic_count_ index dbf94c8..96a4b90 100755 --- a/munin/authentic_count_ +++ b/munin/authentic_count_ @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/python3 import os import sys @@ -6,16 +6,16 @@ import sys tenant = os.path.basename(sys.argv[0]).replace('authentic_count_', '') if len(sys.argv) == 2 and sys.argv[1] == 'autoconf': - print 'yes' + print('yes') sys.exit(0) if len(sys.argv) == 2 and sys.argv[1] == 'config': - print '''graph_title Count of users for %s + print('''graph_title Count of users for %s graph_category entrouvert total_count.label Total total_logged_count.label Total once logged fc_count.label Total FC -''' % tenant +''' % tenant) sys.exit(0) os.system('machinectl shell authentic.node1.prod.saas.entrouvert.org /usr/bin/authentic2-multitenant-manage tenant_command runscript /home/fred//misc-fred/munin/authentic_count_cmd.py compute -d %s' % tenant) diff --git a/munin/authentic_count_cmd.py b/munin/authentic_count_cmd.py index b36acac..660216f 100644 --- a/munin/authentic_count_cmd.py +++ b/munin/authentic_count_cmd.py @@ -8,6 +8,6 @@ total_user_count = User.objects.filter(userexternalid__isnull=True, ).count() total_logged_count = User.objects.filter(userexternalid__isnull=True, last_login__isnull=False).count() fc_count = FcAccount.objects.all().count() -print 'total_count.value', total_user_count -print 'total_logged_count.value', total_logged_count -print 'fc_count.value', fc_count +print('total_count.value', total_user_count) +print('total_logged_count.value', total_logged_count) +print('fc_count.value', fc_count) diff --git a/munin/publik_count b/munin/publik_count index 0cedd7f..1d127b0 100755 --- a/munin/publik_count +++ b/munin/publik_count @@ -1,8 +1,8 @@ -#! /usr/bin/env python +#! /usr/bin/python3 #%# family=auto #%# capabilities=autoconf -import cPickle +import pickle import os import psycopg2 import itertools @@ -16,16 +16,16 @@ for dirname in os.listdir('/var/lib/machines/'): if len(sys.argv) == 2 and sys.argv[1] == 'autoconf': if base_dir: - print 'yes' + print('yes') else: - print 'no' + print('no') sys.exit(0) if len(sys.argv) == 2 and sys.argv[1] == 'config': - print '''graph_title Count of submitted forms + print('''graph_title Count of submitted forms graph_category entrouvert count.label Count -''' +''') sys.exit(0) total = 0 @@ -37,12 +37,12 @@ for tenant in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join(base continue if not os.path.isdir(os.path.join(base_dir, tenant)): continue - cfg = cPickle.load(open(os.path.join(base_dir, tenant, 'config.pck'))) - if not 'postgresql' in cfg: + cfg = pickle.load(open(os.path.join(base_dir, tenant, 'config.pck'), 'rb'), encoding='utf-8') + if 'postgresql' not in cfg: continue psql_cfg = {} for k, v in cfg['postgresql'].items(): - if v and isinstance(v, basestring): + if v and isinstance(v, (int, str)): psql_cfg[k] = v pgconn = psycopg2.connect(**psql_cfg) cur = pgconn.cursor() @@ -54,4 +54,4 @@ for tenant in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join(base total += cur.fetchone()[0] pgconn.close() -print 'count.value', total +print('count.value', total) diff --git a/munin/publik_count_ b/munin/publik_count_ index 37679a9..173c38c 100755 --- a/munin/publik_count_ +++ b/munin/publik_count_ @@ -1,8 +1,8 @@ -#! /usr/bin/env python +#! /usr/bin/python3 #%# family=auto #%# capabilities=autoconf -import cPickle +import pickle import itertools import os import psycopg2 @@ -16,31 +16,31 @@ for dirname in os.listdir('/var/lib/machines/'): if len(sys.argv) == 2 and sys.argv[1] == 'autoconf': if base_dir: - print 'yes' + print('yes') else: - print 'no' + print('no') sys.exit(0) tenant = os.path.basename(sys.argv[0]).replace('publik_count_', '') if len(sys.argv) == 2 and sys.argv[1] == 'config': - print '''graph_title Count of forms for %s + print('''graph_title Count of forms for %s graph_category entrouvert total_count.label Total total_user_count.label Front total_logged_user_count.label Front by logged user -''' % tenant +''' % tenant) sys.exit(0) for tenant_dir in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join(base_dir, 'tenants'))): if tenant_dir != tenant: continue - cfg = cPickle.load(open(os.path.join(base_dir, tenant, 'config.pck'))) - if not 'postgresql' in cfg: + cfg = pickle.load(open(os.path.join(base_dir, tenant, 'config.pck'), 'rb'), encoding='utf-8') + if 'postgresql' not in cfg: continue psql_cfg = {} for k, v in cfg['postgresql'].items(): - if v and isinstance(v, basestring): + if v and isinstance(v, (int, str)): psql_cfg[k] = v pgconn = psycopg2.connect(**psql_cfg) cur = pgconn.cursor() @@ -53,8 +53,8 @@ for tenant_dir in itertools.chain(os.listdir(base_dir), os.listdir(os.path.join( cur.execute('''SELECT COUNT(*) from wcs_all_forms WHERE status != 'draft' AND backoffice_submission = FALSE AND user_id is not NULL''') total_logged_user_count = cur.fetchone()[0] - print 'total_count.value', total_count - print 'total_user_count.value', total_user_count - print 'total_logged_user_count.value', total_logged_user_count + print('total_count.value', total_count) + print('total_user_count.value', total_user_count) + print('total_logged_user_count.value', total_logged_user_count) pgconn.close() break