improve error handling + fix muc

This commit is contained in:
genofire 2019-12-07 16:19:36 +01:00
parent a5a39958cc
commit ee25eb6e23
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
1 changed files with 3 additions and 1 deletions

View File

@ -20,6 +20,7 @@ class EjabberdMetrics():
else: else:
self._url = url self._url = url
self._cmd = self._rest self._cmd = self._rest
@property @property
def _auth(self): def _auth(self):
if self._login is not None: if self._login is not None:
@ -29,7 +30,7 @@ class EjabberdMetrics():
def _rest(self, command, data): def _rest(self, command, data):
r = requests.post("%s/%s" % (self._url, command), auth=self._auth, json=data) r = requests.post("%s/%s" % (self._url, command), auth=self._auth, json=data)
if r is not None: if r.status_code == 200:
return r.json() return r.json()
return {} return {}
@ -141,6 +142,7 @@ class EjabberdMetrics():
result = self._cmd("muc_online_rooms", {"host": host}) result = self._cmd("muc_online_rooms", {"host": host})
if "rooms" in result: if "rooms" in result:
return len(result["rooms"]) return len(result["rooms"])
return len(result)
def update(self): def update(self):
# nodes # nodes