fetch_muc improvements

+ add parsed version string property
* improve fetch_muc method to not request the status string for each request
This commit is contained in:
nico 2020-02-04 01:40:20 +01:00
parent 0145458961
commit 5ce45fca7f
Signed by: mightyBroccoli
GPG Key ID: EA7C31AAB1BDC1A2
2 changed files with 19 additions and 2 deletions

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import ipaddress import ipaddress
import re
from packaging import version
# rfc6052: IPv6 Addressing of IPv4/IPv6 Translators # rfc6052: IPv6 Addressing of IPv4/IPv6 Translators
nat64 = ipaddress.ip_network("64:ff9b::/96") nat64 = ipaddress.ip_network("64:ff9b::/96")
@ -25,6 +28,20 @@ class EjabberdMetrics:
return f"{self._login['user']}@{self._login['server']}", self._login['password'] return f"{self._login['user']}@{self._login['server']}", self._login['password']
return None return None
@property
def _verstring(self):
if self._login is not None:
ver_str = re.compile('([1-9][0-9.-]*)')
status = self._cmd('status', {})
# matches
tmp = ver_str.findall(status)[0]
# return parsed version string
return version.parse(tmp)
return None
def _rest(self, command: str, data): def _rest(self, command: str, data):
import requests import requests
@ -138,8 +155,7 @@ class EjabberdMetrics:
def fetch_muc(self, vhost=None): def fetch_muc(self, vhost=None):
host = "global" host = "global"
if vhost is not None: if vhost is not None:
version = self._cmd("status", {}) if self._verstring.major > 19:
if "19.09" in version:
host = "conference." + vhost host = "conference." + vhost
else: else:
host = vhost host = vhost

View File

@ -1,2 +1,3 @@
influxdb>=5.2.0 influxdb>=5.2.0
requests>=2.21.0 requests>=2.21.0
packaging>=20.1