From a2cd6b94ec19f652fdd271b2dc1c24285e49dce6 Mon Sep 17 00:00:00 2001 From: Maxim Styushin Date: Mon, 15 Apr 2024 20:10:38 +0400 Subject: [PATCH 1/6] fix: remove deprecated distutils imports --- mamonsu/plugins/pgsql/driver/pg8000/core.py | 8 ++-- mamonsu/plugins/pgsql/driver/pool.py | 38 +++++++++---------- .../plugins/pgsql/memory_leak_diagnostic.py | 4 +- mamonsu/plugins/pgsql/replication.py | 4 +- mamonsu/tools/zabbix_cli/operations.py | 8 ++-- mamonsu/tools/zabbix_cli/request.py | 4 +- 6 files changed, 33 insertions(+), 33 deletions(-) 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}) From 37ddafeb70a9e4b9d98ed1d9fd75adac29881e1d Mon Sep 17 00:00:00 2001 From: Maxim Styushin Date: Wed, 17 Apr 2024 16:27:20 +0400 Subject: [PATCH 2/6] cicd: add ubuntu 24.04 to the dev tests --- .github/workflows/mamonsu-tests-dev.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/mamonsu-tests-dev.yml b/.github/workflows/mamonsu-tests-dev.yml index 216aa5b5..58ae1120 100644 --- a/.github/workflows/mamonsu-tests-dev.yml +++ b/.github/workflows/mamonsu-tests-dev.yml @@ -36,6 +36,9 @@ jobs: - docker_os: 'centos:8' pg_version: '16' zabbix_version: '6.4.13' + - docker_os: 'ubuntu:24.04' + pg_version: '16' + zabbix_version: '6.4.13' exclude: - docker_os: 'centos:8' pg_version: '12' From e1db914c52e401d06a62116b6e430c11312ef1b8 Mon Sep 17 00:00:00 2001 From: Maxim Styushin Date: Thu, 18 Apr 2024 22:23:18 +0400 Subject: [PATCH 3/6] fix: workaround for non-usual PG_VERSION string --- mamonsu/plugins/pgsql/driver/pg8000/core.py | 7 ++++++- mamonsu/plugins/pgsql/driver/pool.py | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mamonsu/plugins/pgsql/driver/pg8000/core.py b/mamonsu/plugins/pgsql/driver/pg8000/core.py index 9e6d0699..7816bffa 100755 --- a/mamonsu/plugins/pgsql/driver/pg8000/core.py +++ b/mamonsu/plugins/pgsql/driver/pg8000/core.py @@ -1416,7 +1416,12 @@ def handle_PARAMETER_STATUS(self, data, ps): pass elif key == b"server_version": - self._server_version = packaging.version.parse(value.decode('ascii')) + # LooseVersion() from distutils was able to handle non-relevant strings + # in version (like "16.2 (Ubuntu 16.2-1.pgdg20.04+1)") + # since distutils became deprecated we need this hack hoping that + # postgres package maintainers won't come up with something more exotic + string_version = value.decode('ascii').split(' ')[0] + self._server_version = packaging.version.parse(string_version) if self._server_version < packaging.version.parse('8.2.0'): self._commands_with_count = ( b"INSERT", b"DELETE", b"UPDATE", b"MOVE") diff --git a/mamonsu/plugins/pgsql/driver/pool.py b/mamonsu/plugins/pgsql/driver/pool.py index 7c402d5b..b7ca620b 100644 --- a/mamonsu/plugins/pgsql/driver/pool.py +++ b/mamonsu/plugins/pgsql/driver/pool.py @@ -124,8 +124,10 @@ def server_version(self, db=None): db = self._normalize_db(db) if db in self._cache["server_version"]["storage"]: return self._cache["server_version"]["storage"][db] + + version_string = self.query("show server_version", db)[0][0] result = bytes( - self.query("show server_version", db)[0][0], "utf-8") + version_string.split(" ")[0], "utf-8") self._cache["server_version"]["storage"][db] = "{0}".format( result.decode("ascii")) return self._cache["server_version"]["storage"][db] From 904046c2dfe6f1c04629d39297b14a80013e1f41 Mon Sep 17 00:00:00 2001 From: Maxim Styushin Date: Thu, 18 Apr 2024 22:25:34 +0400 Subject: [PATCH 4/6] fix: get rid of SyntaxWarnings in python3.12 --- mamonsu/plugins/system/linux/disk_stats.py | 4 +- mamonsu/plugins/system/linux/memory.py | 6 +- mamonsu/plugins/system/linux/proc_stat.py | 2 +- mamonsu/plugins/system/linux/scripts.py | 116 ++++++++++----------- 4 files changed, 64 insertions(+), 64 deletions(-) diff --git a/mamonsu/plugins/system/linux/disk_stats.py b/mamonsu/plugins/system/linux/disk_stats.py index 696b5f7f..e5381cad 100644 --- a/mamonsu/plugins/system/linux/disk_stats.py +++ b/mamonsu/plugins/system/linux/disk_stats.py @@ -23,7 +23,7 @@ class DiskStats(Plugin): # Track only physical devices without logical partitions OnlyPhysicalDevices = True - re_stat = re.compile("^(?:\s+\d+){2}\s+([\w\d]+) (.*)$") + re_stat = re.compile(r"^(?:\s+\d+){2}\s+([\w\d]+) (.*)$") # rd_ios rd_merges rd_sectors rd_ticks # wr_ios wr_merges wr_sectors wr_ticks @@ -43,7 +43,7 @@ def run(self, zbx): if m is None: continue dev, val = m.group(1), m.group(2) - if self.OnlyPhysicalDevices and re.search("\d+$", dev): # get drive name without digits at the end + if self.OnlyPhysicalDevices and re.search(r"\d+$", dev): # get drive name without digits at the end continue val = [int(x) for x in val.split()] read_op, read_sc, write_op, write_sc, ticks = val[0], val[2], val[4], val[6], val[9] diff --git a/mamonsu/plugins/system/linux/memory.py b/mamonsu/plugins/system/linux/memory.py index ef95f62d..c0906afa 100644 --- a/mamonsu/plugins/system/linux/memory.py +++ b/mamonsu/plugins/system/linux/memory.py @@ -5,9 +5,9 @@ class Memory(Plugin): AgentPluginType = "sys" - query_agent = "cat /proc/meminfo | awk '/^{0}\:/ " - query_agent_used = "MemTotal=$(cat /proc/meminfo | awk '/MemTotal\:/ { print $2 }'); " \ - "SUM=$(cat /proc/meminfo | awk '/(MemFree|Buffers|(Swap)?Cached|Slab|PageTables)\:/ " \ + query_agent = r"cat /proc/meminfo | awk '/^{0}\:/ " + query_agent_used = r"MemTotal=$(cat /proc/meminfo | awk '/MemTotal\:/ { print $2 }'); " \ + r"SUM=$(cat /proc/meminfo | awk '/(MemFree|Buffers|(Swap)?Cached|Slab|PageTables)\:/ " \ "{ SUM += $2 } END {print SUM}'); echo $((($MemTotal-$SUM)*1024))" query_agent_swap = "expr `grep -Ei 'Swap(Total|Free)' /proc/meminfo | awk '{print $2 * 1024}' | paste -s -d '-' " \ "| sed -E 's/-/ - /g'` " diff --git a/mamonsu/plugins/system/linux/proc_stat.py b/mamonsu/plugins/system/linux/proc_stat.py index 4da3960c..237e1955 100644 --- a/mamonsu/plugins/system/linux/proc_stat.py +++ b/mamonsu/plugins/system/linux/proc_stat.py @@ -16,7 +16,7 @@ class ProcStat(Plugin): # alert fork-rate ForkRate = 500 # /proc/stat all cpu line - re_stat = re.compile("cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)") + re_stat = re.compile(r"cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)") ProcessItems = [ # key, zbx_key, name, delta, color, side diff --git a/mamonsu/plugins/system/linux/scripts.py b/mamonsu/plugins/system/linux/scripts.py index 1ab25e73..58c2ff6c 100644 --- a/mamonsu/plugins/system/linux/scripts.py +++ b/mamonsu/plugins/system/linux/scripts.py @@ -14,13 +14,13 @@ class Scripts(object): while getopts "s::a:sj:uphvt:" OPTION; do case ${OPTION} in - + j) JSON=1 JSON_ATTR=(${OPTARG}) IFS="${IFS_DEFAULT}" ;; - + esac done @@ -46,10 +46,10 @@ class Scripts(object): count=1 while read line; do values=(${line}) - if [ $(contains "${list_str}" "," "${values[8]}") -eq 0 ]; then + if [ $(contains "${list_str}" "," "${values[8]}") -eq 0 ]; then if [[ ${output} != " " ]]; then echo " ${output}" - fi + fi output='{ ' output+='"'{#${JSON_ATTR[0]}}'"' output+=':' @@ -57,7 +57,7 @@ class Scripts(object): output+=' }' tmp="${output}" output="${output}," - fi + fi let "count=count+1" done <<< "${rval}" echo " ${tmp}" @@ -76,22 +76,22 @@ class Scripts(object): IFS_DEFAULT="${IFS}" # ################################################################################# - - + + while getopts "s::a:sj:uphvt:" OPTION; do case ${OPTION} in - + j) JSON=1 JSON_ATTR=(${OPTARG}) IFS="${IFS_DEFAULT}" ;; - + esac done - + ################################################################################# - + output=" " rval=`cat /proc/diskstats` if [[ ${JSON} -eq 1 ]]; then @@ -102,9 +102,9 @@ class Scripts(object): while read line; do if [[ ${line} != '' ]]; then IFS="|" values=(${line}) - - if [[ $count == 1 ]]; then # for loop0 case - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + + if [[ $count == 1 ]]; then # for loop0 case + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` new_value3=`echo "$new_value2" | cut -d " " -f 3` read_op=`echo "$new_value2" | cut -d " " -f 4` read_sc=`echo "$new_value2" | cut -d " " -f 6` @@ -112,7 +112,7 @@ class Scripts(object): write_sc=`echo "$new_value2" | cut -d " " -f 10` ticks=`echo "$new_value2" | cut -d " " -f 13` else - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` new_value3=`echo "$new_value2" | cut -d " " -f 4` read_op=`echo "$new_value2" | cut -d " " -f 5` read_sc=`echo "$new_value2" | cut -d " " -f 7` @@ -123,8 +123,8 @@ class Scripts(object): if [[ $new_value3 != *"loop"* ]] && [[ $new_value3 != *"ram"* ]] && [[ $new_value3 != *[0-9]* ]]; then if [[ ${output} != " " ]]; then echo " ${output}" - fi - value=$(($read_op+$value)) + fi + value=$(($read_op+$value)) output='{ ' output+='"'{#${JSON_ATTR[0]}}'"' output+=':' @@ -142,7 +142,7 @@ class Scripts(object): else echo "${rval:-0}" fi - + exit ${rcode} """, @@ -156,26 +156,26 @@ class Scripts(object): if [[ ${line} != '' ]]; then IFS="|" values=(${line}) - if [[ $count == 1 ]]; then # for loop0 case - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + if [[ $count == 1 ]]; then # for loop0 case + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` # echo $new_value2 new_value3=`echo "$new_value2" | cut -d " " -f 3` read_op=`echo "$new_value2" | cut -d " " -f 4` - + else - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` new_value3=`echo "$new_value2" | cut -d " " -f 4` read_op=`echo "$new_value2" | cut -d " " -f 5` - + fi re='^[0-9]+$' - has_digits='no' + has_digits='no' if [[ "${new_value3: -1}" =~ $re ]]; then has_digits='yes' fi if [[ $new_value3 != *"loop"* ]] && [[ $new_value3 != *"ram"* ]] && [[ $has_digits == 'no' ]]; then - value=$(($read_op+$value)) - + value=$(($read_op+$value)) + fi fi @@ -195,23 +195,23 @@ class Scripts(object): if [[ ${line} != '' ]]; then IFS="|" values=(${line}) - if [[ $count == 1 ]]; then # for loop0 case - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + if [[ $count == 1 ]]; then # for loop0 case + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` # echo $new_value2 - new_value3=`echo "$new_value2" | cut -d " " -f 3` + new_value3=`echo "$new_value2" | cut -d " " -f 3` read_sc=`echo "$new_value2" | cut -d " " -f 6` else - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` new_value3=`echo "$new_value2" | cut -d " " -f 4` - read_sc=`echo "$new_value2" | cut -d " " -f 7` + read_sc=`echo "$new_value2" | cut -d " " -f 7` fi re='^[0-9]+$' - has_digits='no' + has_digits='no' if [[ "${new_value3: -1}" =~ $re ]]; then has_digits='yes' fi if [[ $new_value3 != *"loop"* ]] && [[ $new_value3 != *"ram"* ]] && [[ $has_digits == 'no' ]]; then - value=$(($read_sc+$value)) + value=$(($read_sc+$value)) fi fi let "count=count+1" @@ -230,28 +230,28 @@ class Scripts(object): if [[ ${line} != '' ]]; then IFS="|" values=(${line}) - if [[ $count == 1 ]]; then # for loop0 case - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` - new_value3=`echo "$new_value2" | cut -d " " -f 3` + if [[ $count == 1 ]]; then # for loop0 case + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` + new_value3=`echo "$new_value2" | cut -d " " -f 3` write_op=`echo "$new_value2" | cut -d " " -f 8` - + else - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` new_value3=`echo "$new_value2" | cut -d " " -f 4` - + write_op=`echo "$new_value2" | cut -d " " -f 9` - + fi re='^[0-9]+$' - has_digits='no' + has_digits='no' if [[ "${new_value3: -1}" =~ $re ]]; then has_digits='yes' fi if [[ $new_value3 != *"loop"* ]] && [[ $new_value3 != *"ram"* ]] && [[ $has_digits == 'no' ]];then - #echo $write_op + #echo $write_op + + value=$(($write_op+$value)) - value=$(($write_op+$value)) - fi fi @@ -270,25 +270,25 @@ class Scripts(object): if [[ ${line} != '' ]]; then IFS="|" values=(${line}) - if [[ $count == 1 ]]; then # for loop0 case - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + if [[ $count == 1 ]]; then # for loop0 case + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` new_value3=`echo "$new_value2" | cut -d " " -f 3` write_sc=`echo "$new_value2" | cut -d " " -f 10` else - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` new_value3=`echo "$new_value2" | cut -d " " -f 4` write_sc=`echo "$new_value2" | cut -d " " -f 11` fi re='^[0-9]+$' - has_digits='no' + has_digits='no' if [[ "${new_value3: -1}" =~ $re ]]; then has_digits='yes' fi #echo $values if [[ $new_value3 != *"loop"* ]] && [[ $new_value3 != *"ram"* ]] && [[ $has_digits == 'no' ]]; then - #echo $write_sc + #echo $write_sc #echo $new_value3 - value=$(($write_sc+$value)) + value=$(($write_sc+$value)) fi fi let "count=count+1" @@ -302,7 +302,7 @@ class Scripts(object): ################################################################################# while getopts "s::a:sj:uphvt:" OPTION; do case ${OPTION} in - + j) JSON=1 JSON_ATTR=(${OPTARG}) @@ -323,7 +323,7 @@ class Scripts(object): if [[ "${values[0]}" != *"lo:"* ]] && [[ "${#values[@]}">1 ]]; then if [[ ${output} != " " ]] && [[ $count > 4 ]]; then echo " ${output}" - fi + fi output='{ ' output+='"'{#${JSON_ATTR[0]}}'"' output+=':' @@ -332,7 +332,7 @@ class Scripts(object): output+=' }' tmp="${output}" output="${output}," - fi + fi let "count=count+1" done <<< "${rval}" echo " ${tmp}" @@ -356,19 +356,19 @@ class Scripts(object): if [[ ${line} != '' ]]; then IFS="|" values=(${line}) - if [[ $count == 1 ]]; then # for loop0 case - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + if [[ $count == 1 ]]; then # for loop0 case + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` # echo $new_value2 new_value3=`echo "$new_value2" | cut -d " " -f 3` ticks=`echo "$new_value2" | cut -d " " -f 13` else - new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \+/ /gp'` + new_value2=`echo ${values[0]} | sed -n '/[0-9]/s/ \\+/ /gp'` new_value3=`echo "$new_value2" | cut -d " " -f 4` ticks=`echo "$new_value2" | cut -d " " -f 14` fi if [[ $new_value3 != *"loop"* ]] && [[ $new_value3 != *"ram"* ]]; then - #echo $ticks - value=$(($ticks+$value)) + #echo $ticks + value=$(($ticks+$value)) fi fi let "count=count+1" From 3dc18b1b9b9c5218a66c7a75d3fc7e145f542126 Mon Sep 17 00:00:00 2001 From: Maxim Styushin Date: Thu, 18 Apr 2024 22:28:03 +0400 Subject: [PATCH 5/6] cicd: add ubuntu 24.04 to the master tests --- .github/workflows/mamonsu-tests-master.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/mamonsu-tests-master.yml b/.github/workflows/mamonsu-tests-master.yml index aaf2aec6..bea887f4 100644 --- a/.github/workflows/mamonsu-tests-master.yml +++ b/.github/workflows/mamonsu-tests-master.yml @@ -42,6 +42,9 @@ jobs: - docker_os: 'ubuntu:20.04' pg_version: '15' zabbix_version: '6.4.13' + - docker_os: 'ubuntu:24.04' + pg_version: '16' + zabbix_version: '6.4.13' exclude: # excludes PG 15, 16 on CentOS - docker_os: 'centos:7' From 5e1d9558a82ac6f06263ec807d2c1070dbfb7e4a Mon Sep 17 00:00:00 2001 From: Maxim Styushin Date: Thu, 18 Apr 2024 22:53:59 +0400 Subject: [PATCH 6/6] build: upgrade to 3.5.8 --- .github/workflows/mamonsu-tests-dev.yml | 2 +- .github/workflows/mamonsu-tests-master.yml | 2 +- github-actions-tests/mamonsu_build.sh | 4 ++-- .../sources/{agent_3.5.7.conf => agent_3.5.8.conf} | 0 mamonsu/__init__.py | 2 +- packaging/debian/changelog | 3 +++ packaging/rpm/SPECS/mamonsu.spec | 5 ++++- packaging/win/mamonsu.def.nsh | 2 +- 8 files changed, 13 insertions(+), 7 deletions(-) rename github-actions-tests/sources/{agent_3.5.7.conf => agent_3.5.8.conf} (100%) diff --git a/.github/workflows/mamonsu-tests-dev.yml b/.github/workflows/mamonsu-tests-dev.yml index 58ae1120..22386fbd 100644 --- a/.github/workflows/mamonsu-tests-dev.yml +++ b/.github/workflows/mamonsu-tests-dev.yml @@ -80,7 +80,7 @@ jobs: echo "zabbix_address=$(hostname -I | awk '{print $1}')" >> $GITHUB_OUTPUT id: zabbix_address - name: Edit Zabbix address in agent.conf - run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.7.conf + run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.8.conf - name: Copy test scripts to container run: docker exec $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ) mkdir -p -m 755 /mamonsu/ diff --git a/.github/workflows/mamonsu-tests-master.yml b/.github/workflows/mamonsu-tests-master.yml index bea887f4..2cdde542 100644 --- a/.github/workflows/mamonsu-tests-master.yml +++ b/.github/workflows/mamonsu-tests-master.yml @@ -91,7 +91,7 @@ jobs: echo "zabbix_address=$(hostname -I | awk '{print $1}')" >> $GITHUB_OUTPUT id: zabbix_address - name: Edit Zabbix address in agent.conf - run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.7.conf + run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.8.conf - name: Copy test scripts to container run: docker exec $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ) mkdir -p -m 755 /mamonsu/ diff --git a/github-actions-tests/mamonsu_build.sh b/github-actions-tests/mamonsu_build.sh index ec2a427f..bc7d5e46 100644 --- a/github-actions-tests/mamonsu_build.sh +++ b/github-actions-tests/mamonsu_build.sh @@ -41,7 +41,7 @@ if [ "${OS%:*}" = "centos" ]; then python3 setup.py build && python3 setup.py install make rpm sudo rpm -i ./mamonsu*.rpm - cat /mamonsu/github-actions-tests/sources/agent_3.5.7.conf > /etc/mamonsu/agent.conf + cat /mamonsu/github-actions-tests/sources/agent_3.5.8.conf > /etc/mamonsu/agent.conf systemctl daemon-reload systemctl restart mamonsu sleep 5 @@ -64,7 +64,7 @@ elif [ "${OS%:*}" = "ubuntu" ]; then python3 setup.py build && python3 setup.py install make deb sudo dpkg -i ./mamonsu*.deb - cat /mamonsu/github-actions-tests/sources/agent_3.5.7.conf > /etc/mamonsu/agent.conf + cat /mamonsu/github-actions-tests/sources/agent_3.5.8.conf > /etc/mamonsu/agent.conf service mamonsu restart sleep 5 echo && echo && echo "mamonsu version:" diff --git a/github-actions-tests/sources/agent_3.5.7.conf b/github-actions-tests/sources/agent_3.5.8.conf similarity index 100% rename from github-actions-tests/sources/agent_3.5.7.conf rename to github-actions-tests/sources/agent_3.5.8.conf diff --git a/mamonsu/__init__.py b/mamonsu/__init__.py index 1aebc348..0a9caddf 100644 --- a/mamonsu/__init__.py +++ b/mamonsu/__init__.py @@ -1,7 +1,7 @@ __author__ = 'Dmitry Vasilyev' __author_email__ = 'info@postgrespro.ru' __description__ = 'Monitoring agent for PostgreSQL' -__version__ = '3.5.7' +__version__ = '3.5.8' __licence__ = 'BSD' __url__ = 'https://github.com/postgrespro/mamonsu' diff --git a/packaging/debian/changelog b/packaging/debian/changelog index 8b5b7c23..0a0c778c 100644 --- a/packaging/debian/changelog +++ b/packaging/debian/changelog @@ -1,3 +1,6 @@ +mamonsu (3.5.8-1) stable; urgency=low + * Prepare for python 3.12: remove deprecated distutils imports; + mamonsu (3.5.7-1) stable; urgency=low * added support for Zabbix 6.4 API: handle deprecated parameters for auth request; * removed caching of pgsql.connections[max_connections] metric; diff --git a/packaging/rpm/SPECS/mamonsu.spec b/packaging/rpm/SPECS/mamonsu.spec index 82463494..f35fbd93 100644 --- a/packaging/rpm/SPECS/mamonsu.spec +++ b/packaging/rpm/SPECS/mamonsu.spec @@ -1,5 +1,5 @@ Name: mamonsu -Version: 3.5.7 +Version: 3.5.8 Release: 1%{?dist} Summary: Monitoring agent for PostgreSQL Group: Applications/Internet @@ -73,6 +73,9 @@ chown -R mamonsu.mamonsu /var/log/mamonsu chown -R mamonsu.mamonsu /etc/mamonsu %changelog +* Thu Apr 18 2024 Maxim Styushin - 3.5.8-1 + - Prepare for python 3.12: remove deprecated distutils imports; + * Fri Apr 5 2024 Maxim Styushin - 3.5.7-1 - added support for Zabbix 6.4 API: handle deprecated parameters for auth request; - removed caching of pgsql.connections[max_connections] metric; diff --git a/packaging/win/mamonsu.def.nsh b/packaging/win/mamonsu.def.nsh index 1d638c4c..1e32c88e 100644 --- a/packaging/win/mamonsu.def.nsh +++ b/packaging/win/mamonsu.def.nsh @@ -1,5 +1,5 @@ !define NAME Mamonsu -!define VERSION 3.5.7 +!define VERSION 3.5.8 !define MAMONSU_REG_PATH "Software\PostgresPro\Mamonsu" !define MAMONSU_REG_UNINSTALLER_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall" !define EDB_REG "SOFTWARE\Postgresql"