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:
		
							parent
							
								
									0145458961
								
							
						
					
					
						commit
						5ce45fca7f
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,2 +1,3 @@
 | 
			
		|||
influxdb>=5.2.0
 | 
			
		||||
requests>=2.21.0
 | 
			
		||||
packaging>=20.1
 | 
			
		||||
		Loading…
	
		Reference in New Issue