diff --git a/mamonsu/plugins/pgsql/driver/pg8000/core.py b/mamonsu/plugins/pgsql/driver/pg8000/core.py index d29c627d..9e6d0699 100755 --- a/mamonsu/plugins/pgsql/driver/pg8000/core.py +++ b/mamonsu/plugins/pgsql/driver/pg8000/core.py @@ -2,7 +2,7 @@ from collections import defaultdict, deque from datetime import datetime as Datetime from decimal import Decimal -from distutils.version import LooseVersion +from pkg_resources import packaging from hashlib import md5 from itertools import count, islice from struct import Struct @@ -1416,11 +1416,11 @@ def handle_PARAMETER_STATUS(self, data, ps): pass elif key == b"server_version": - self._server_version = LooseVersion(value.decode('ascii')) - if self._server_version < LooseVersion('8.2.0'): + self._server_version = packaging.version.parse(value.decode('ascii')) + if self._server_version < packaging.version.parse('8.2.0'): self._commands_with_count = ( b"INSERT", b"DELETE", b"UPDATE", b"MOVE") - elif self._server_version < LooseVersion('9.0.0'): + elif self._server_version < packaging.version.parse('9.0.0'): self._commands_with_count = ( b"INSERT", b"DELETE", b"UPDATE", b"MOVE", b"FETCH", b"COPY") diff --git a/mamonsu/plugins/pgsql/driver/pool.py b/mamonsu/plugins/pgsql/driver/pool.py index 1f39e525..7c402d5b 100644 --- a/mamonsu/plugins/pgsql/driver/pool.py +++ b/mamonsu/plugins/pgsql/driver/pool.py @@ -1,4 +1,4 @@ -from distutils.version import LooseVersion +from pkg_resources import packaging from .connection import Connection, ConnectionInfo @@ -132,19 +132,19 @@ def server_version(self, db=None): def server_version_greater(self, version, db=None): db = self._normalize_db(db) - return self.server_version(db) >= LooseVersion(version) + return packaging.version.parse(self.server_version(db)) >= packaging.version.parse(version) def server_version_less(self, version, db=None): db = self._normalize_db(db) - return self.server_version(db) <= LooseVersion(version) + return packaging.version.parse(self.server_version(db)) <= packaging.version.parse(version) def bootstrap_version_greater(self, version): - return str( - self._cache["bootstrap"]["version"]) >= LooseVersion(version) + return packaging.version.parse( + str(self._cache["bootstrap"]["version"])) >= packaging.version.parse(version) def bootstrap_version_less(self, version): - return str( - self._cache["bootstrap"]["version"]) <= LooseVersion(version) + return packaging.version.parse( + str(self._cache["bootstrap"]["version"])) <= packaging.version.parse(version) def in_recovery(self, db=None): db = self._normalize_db(db) @@ -166,8 +166,8 @@ def is_bootstraped(self, db=None): self._cache["bootstrap"]["counter"] = 0 # TODO: изменить на нормальное название, 'config' слишком общее sql = """ - SELECT count(*) - FROM pg_catalog.pg_class + SELECT count(*) + FROM pg_catalog.pg_class WHERE relname = 'config'; """ result = int(self.query(sql, db)[0][0]) @@ -175,7 +175,7 @@ def is_bootstraped(self, db=None): if self._cache["bootstrap"]["storage"][db]: self._connections[db].log.info("Found mamonsu bootstrap") sql = """ - SELECT max(version) + SELECT max(version) FROM mamonsu.config; """ self._cache["bootstrap"]["version"] = self.query(sql, db)[0][0] @@ -227,8 +227,8 @@ def is_pgpro_ee(self, db=None): def extension_installed(self, ext, db=None): db = self._normalize_db(db) result = self.query(""" - SELECT count(*) - FROM pg_catalog.pg_extension + SELECT count(*) + FROM pg_catalog.pg_extension WHERE lower(extname) = lower('{0}'); """.format(ext), db) return (int(result[0][0])) == 1 @@ -239,9 +239,9 @@ def extension_schema(self, extension, db=None): return self._cache["extension_schema"][extension][db] try: self._cache["extension_schema"][extension][db] = self.query(""" - SELECT n.nspname - FROM pg_extension e - JOIN pg_namespace n ON e.extnamespace = n.oid + SELECT n.nspname + FROM pg_extension e + JOIN pg_namespace n ON e.extnamespace = n.oid WHERE e.extname = '{0}' """.format(extension), db)[0][0] return self._cache["extension_schema"][extension][db] @@ -250,7 +250,7 @@ def extension_schema(self, extension, db=None): def databases(self): result, databases = self.query(""" - SELECT datname + SELECT datname FROM pg_catalog.pg_database; """), [] for row in result: @@ -309,13 +309,13 @@ def get_sys_param(self, param, db=None): db = self._normalize_db(db) if self.is_bootstraped() and self.bootstrap_version_greater("2.3.4"): result = self.query(""" - SELECT * + SELECT * FROM mamonsu.get_sys_param('{0}'); """.format(param))[0][0] else: result = self.query(""" - SELECT setting - FROM pg_catalog.pg_settings + SELECT setting + FROM pg_catalog.pg_settings WHERE name = '{0}'; """.format(param), db)[0][0] return result diff --git a/mamonsu/plugins/pgsql/memory_leak_diagnostic.py b/mamonsu/plugins/pgsql/memory_leak_diagnostic.py index a9da0a18..cb368a92 100644 --- a/mamonsu/plugins/pgsql/memory_leak_diagnostic.py +++ b/mamonsu/plugins/pgsql/memory_leak_diagnostic.py @@ -4,7 +4,7 @@ import os from .pool import Pooler import re -from distutils.version import LooseVersion +from pkg_resources import packaging import mamonsu.lib.platform as platform import posix @@ -91,7 +91,7 @@ def run(self, zbx): for row in Pooler.query(query=self.query): pids.append(row[0]) - if (LooseVersion(self.os_release) < LooseVersion("4.5") + if (packaging.version.parse(self.os_release) < packaging.version.parse("4.5") and not (self.os_name == "centos" and self.os_version == "7")) \ or (not self.os_name and not self.os_version): for pid in pids: diff --git a/mamonsu/plugins/pgsql/replication.py b/mamonsu/plugins/pgsql/replication.py index 3aa2ba46..0c53f5b6 100644 --- a/mamonsu/plugins/pgsql/replication.py +++ b/mamonsu/plugins/pgsql/replication.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from mamonsu.plugins.pgsql.plugin import PgsqlPlugin as Plugin -from distutils.version import LooseVersion +from pkg_resources import packaging from .pool import Pooler from mamonsu.lib.zbx_template import ZbxTemplate @@ -201,7 +201,7 @@ def discovery_rules(self, template, dashboard=False): def keys_and_queries(self, template_zabbix): result = [] - if LooseVersion(self.VersionPG) < LooseVersion("10"): + if packaging.version.parse(self.VersionPG) < packaging.version.parse("10"): result.append("{0},$2 $1 -c \"{1}\"".format("pgsql.replication_lag.sec[*]", self.query_agent_replication_lag.format( self.plugin_config("interval"), "xlog_receive_location", diff --git a/mamonsu/tools/zabbix_cli/operations.py b/mamonsu/tools/zabbix_cli/operations.py index e12db8af..d3b25e4a 100644 --- a/mamonsu/tools/zabbix_cli/operations.py +++ b/mamonsu/tools/zabbix_cli/operations.py @@ -5,7 +5,7 @@ import json from mamonsu.tools.zabbix_cli.request import Request from mamonsu.lib.parser import zabbix_msg -from distutils.version import LooseVersion +from pkg_resources import packaging from mamonsu.tools.zabbix_cli.dashboard import generate_dashboard @@ -171,10 +171,10 @@ def template(self, args): } }, 'source': open(file).read()} - if LooseVersion(zabbix_version) < LooseVersion('5.4'): + if packaging.version.parse(zabbix_version) < packaging.version.parse('5.4'): params['rules']['applications'] = {'createMissing': True, 'deleteMissing': True} - if LooseVersion(zabbix_version) < LooseVersion('5.2'): + if packaging.version.parse(zabbix_version) < packaging.version.parse('5.2'): params['rules']['templateScreens'] = {'createMissing': True, 'updateExisting': False, 'deleteMissing': True} @@ -329,7 +329,7 @@ def dashboard(self, args): if not len(args) == 2: return self._print_help() zabbix_version = str(self.req.post(method='apiinfo.version', params=[])) - if LooseVersion(zabbix_version) < LooseVersion('6.0'): + if packaging.version.parse(zabbix_version) < packaging.version.parse('6.0'): print("You can import Mamonsu dashboard only on Zabbix 6.0+.") return else: diff --git a/mamonsu/tools/zabbix_cli/request.py b/mamonsu/tools/zabbix_cli/request.py index 5b83427b..566868f9 100644 --- a/mamonsu/tools/zabbix_cli/request.py +++ b/mamonsu/tools/zabbix_cli/request.py @@ -5,7 +5,7 @@ from collections import OrderedDict -from distutils.version import LooseVersion +from pkg_resources import packaging import urllib.request as urllib2 @@ -26,7 +26,7 @@ def _auth(self): if self._auth_tocken is None: if not self._user: return None - user_field = 'user' if LooseVersion(self._api_version) < LooseVersion('6.4') else 'username' + user_field = 'user' if packaging.version.parse(self._api_version) < packaging.version.parse('6.4') else 'username' self._auth_tocken = self.post( 'user.login', {user_field: self._user, 'password': self._passwd})