diff options
author | nico <nico@magicbroccoli.de> | 2020-02-04 01:40:20 +0100 |
---|---|---|
committer | nico <nico@magicbroccoli.de> | 2020-02-04 01:40:20 +0100 |
commit | 5ce45fca7f5166fe1ec885a85e048b4a627eed29 (patch) | |
tree | c9970d7a26eb9990aac369d8c58a5623900fce3c | |
parent | 0145458961549b15518edb09f4e9c87c7099dbbd (diff) |
fetch_muc improvements
+ add parsed version string property
* improve fetch_muc method to not request the status string for each request
-rwxr-xr-x | ejabberdrpc.py | 20 | ||||
-rw-r--r-- | requirements.txt | 1 |
2 files changed, 19 insertions, 2 deletions
diff --git a/ejabberdrpc.py b/ejabberdrpc.py index 9bdfe1c..d90831b 100755 --- a/ejabberdrpc.py +++ b/ejabberdrpc.py @@ -1,6 +1,9 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- import ipaddress +import re + +from packaging import version # rfc6052: IPv6 Addressing of IPv4/IPv6 Translators 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 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): import requests @@ -138,8 +155,7 @@ class EjabberdMetrics: def fetch_muc(self, vhost=None): host = "global" if vhost is not None: - version = self._cmd("status", {}) - if "19.09" in version: + if self._verstring.major > 19: host = "conference." + vhost else: host = vhost diff --git a/requirements.txt b/requirements.txt index d91f184..0d3402a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ influxdb>=5.2.0 requests>=2.21.0 +packaging>=20.1
\ No newline at end of file |