Unverified Commit 3e47f393 authored by genofire's avatar genofire

safe for multiline status-message

parent 182612d8
......@@ -3,49 +3,51 @@
from subprocess import check_output
def call_count(args):
res = check_output(args)
return res.decode("utf-8").count('\n')
res = check_output(args)
return res.decode("utf-8").count('\n')
def call_lines(args):
res = check_output(args)
return res.decode("utf-8").split('\n')[:-1]
res = check_output(args)
return res.decode("utf-8").split('\n')[:-1]
def call_value(args):
res = check_output(args)
return int(res.decode("utf-8"))
res = check_output(args)
return int(res.decode("utf-8"))
def writeglobal(ejabberdctl):
muc = call_count(ejabberdctl+["muc_online_rooms","global"])
registered_users = call_value(ejabberdctl+["stats", "registeredusers"])
connected_users = call_value(ejabberdctl+["connected_users_number"])
incoming_s2s = call_value(ejabberdctl+["incoming_s2s_number"])
outgoing_s2s = call_value(ejabberdctl+["outgoing_s2s_number"])
client_ipv4 = 0
client_ipv6 = 0
client_hybrid = 0
connected_users_info = call_lines(ejabberdctl+["connected_users_info"])
for connected_user in connected_users_info:
address = connected_user.split('\t')[2]
if ':' in address and '.' in address:
client_hybrid += 1
elif ':' in address:
client_ipv6 += 1
elif '.' in address:
client_ipv4 += 1
return "ejabberd muc_online_rooms=%di,registered_users=%di,connected_users=%di,incoming_s2s=%di,outgoing_s2s=%di,client_hybrid=%di,client_ipv6=%di,client_ipv4=%di" % (muc, registered_users,connected_users, incoming_s2s, outgoing_s2s, client_hybrid, client_ipv6, client_ipv4)
muc = call_count(ejabberdctl+["muc_online_rooms","global"])
registered_users = call_value(ejabberdctl+["stats", "registeredusers"])
connected_users = call_value(ejabberdctl+["connected_users_number"])
incoming_s2s = call_value(ejabberdctl+["incoming_s2s_number"])
outgoing_s2s = call_value(ejabberdctl+["outgoing_s2s_number"])
client_ipv4 = 0
client_ipv6 = 0
client_hybrid = 0
connected_users_info = call_lines(ejabberdctl+["connected_users_info"])
for connected_user in connected_users_info:
suser =connected_user.split('\t')
if len(suser) < 3:
continue
address = suser[2]
if ':' in address and '.' in address:
client_hybrid += 1
elif ':' in address:
client_ipv6 += 1
elif '.' in address:
client_ipv4 += 1
return "ejabberd muc_online_rooms=%di,registered_users=%di,connected_users=%di,incoming_s2s=%di,outgoing_s2s=%di,client_hybrid=%di,client_ipv6=%di,client_ipv4=%di" % (muc, registered_users,connected_users, incoming_s2s, outgoing_s2s, client_hybrid, client_ipv6, client_ipv4)
def writedomain(ejabberdctl, domain):
muc = call_count(ejabberdctl+["muc_online_rooms",domain])
registered_users = call_count(ejabberdctl+["registered_users", domain])
connected_users = call_count(ejabberdctl+["connected_users_vhost", domain])
return "ejabberd_vhost,domain=%s muc_online_rooms=%di,registered_users=%di,connected_users=%di" % (domain, muc, registered_users, connected_users)
muc = call_count(ejabberdctl+["muc_online_rooms",domain])
registered_users = call_count(ejabberdctl+["registered_users", domain])
connected_users = call_count(ejabberdctl+["connected_users_vhost", domain])
return "ejabberd_vhost,domain=%s muc_online_rooms=%di,registered_users=%di,connected_users=%di" % (domain, muc, registered_users, connected_users)
if __name__ == "__main__":
ejabberdctl = ["ejabberdctl"]
print(writeglobal(ejabberdctl))
for domain in call_lines(ejabberdctl+["registered_vhosts"]):
print(writedomain(ejabberdctl, domain))
ejabberdctl = ["ejabberdctl"]
print(writeglobal(ejabberdctl))
for domain in call_lines(ejabberdctl+["registered_vhosts"]):
print(writedomain(ejabberdctl, domain))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment