aboutsummaryrefslogtreecommitdiffstats
path: root/control.py
diff options
context:
space:
mode:
authorgenofire <geno+dev@fireorbit.de>2020-06-10 07:22:42 +0200
committergenofire <geno+dev@fireorbit.de>2020-06-10 07:24:35 +0200
commit38a7b171808c5a1525da5452b338fac0a9bf2c6b (patch)
tree45f64e59e4d433efb2a4b1d4172e6ad7fe341fee /control.py
parent893f68497de1ace6abfede0de4f70d11f6801a8b (diff)
add cleanup.py
Diffstat (limited to 'control.py')
-rw-r--r--control.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/control.py b/control.py
new file mode 100644
index 0000000..3bbf3c7
--- /dev/null
+++ b/control.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+import re
+import logging
+
+from packaging import version
+from api import EjabberdApi
+
+class EjabberdCtl(EjabberdApi):
+
+
+ @property
+ def verstring(self):
+ if self._login is not None:
+ ver_str = re.compile('([1-9][0-9.]+(?![.a-z]))\\b')
+ status = self.cmd('status', {})
+
+ # matches
+ try:
+ tmp = ver_str.findall(status)[0]
+ # raise SystemExit code 17 if no status message is received
+ except TypeError:
+ raise SystemExit(17)
+
+ # return parsed version string
+ logging.debug(f"fetch version: {tmp}")
+ return version.parse(tmp)
+
+ return None
+
+ def fetch_onlineuser(self):
+ tmp = self.cmd("connected_users_info", {})
+ if "connected_users_info" not in tmp:
+ return tmp
+ data = []
+ for c in tmp["connected_users_info"]:
+ if "session" not in c:
+ continue
+ user = {}
+ for attrs in c["session"]:
+ for k, v in attrs.items():
+ user[k] = v
+ data.append(user)
+ return data
+
+ def fetch_nodes(self):
+ result = self.cmd("list_cluster", {})
+ if "nodes" not in result:
+ return result
+ data = []
+ for node in result["nodes"]:
+ data.append(node["node"])
+ return data
+
+ def fetch_vhosts(self):
+ result = self.cmd("registered_vhosts", {})
+ if "vhosts" not in result:
+ return result
+ data = []
+ for vhost in result["vhosts"]:
+ data.append(vhost["vhost"])
+ return data
+
+ def fetch_s2s_in(self):
+ result = self.cmd("incoming_s2s_number", {})
+ if "s2s_incoming" not in result:
+ return result
+ return result["s2s_incoming"]
+
+ def fetch_s2s_out(self):
+ result = self.cmd("outgoing_s2s_number", {})
+ if "s2s_outgoing" not in result:
+ return result
+ return result["s2s_outgoing"]
+
+ def fetch_registered(self, vhost=None):
+ if vhost is None:
+ result = self.cmd("stats", {"name":"registeredusers"})
+ if "stat" in result:
+ return result["stat"]
+ else:
+ result = self.cmd("stats_host", {"name":"registeredusers", "host": vhost})
+ if "stat" in result:
+ return result["stat"]