Plugin prosody_: fix style issues
This commit is contained in:
parent
585f6f1539
commit
9810644390
|
@ -25,6 +25,7 @@ import os
|
|||
import telnetlib
|
||||
import re
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
mode = sys.argv[1]
|
||||
|
@ -35,56 +36,50 @@ def main():
|
|||
port = int(os.environ.get('port', 5582))
|
||||
|
||||
if mode == "suggest":
|
||||
print "c2s"
|
||||
print "s2s"
|
||||
print "presence"
|
||||
print "uptime"
|
||||
print "users"
|
||||
print("c2s")
|
||||
print("s2s")
|
||||
print("presence")
|
||||
print("uptime")
|
||||
print("users")
|
||||
sys.exit(0)
|
||||
|
||||
if wildcard == "c2s":
|
||||
if mode == "config":
|
||||
print "graph_title Prosody C2S Connections"
|
||||
print "graph_vlabel users"
|
||||
print "graph_category chat"
|
||||
print("graph_title Prosody C2S Connections")
|
||||
print("graph_vlabel users")
|
||||
print("graph_category chat")
|
||||
|
||||
print "all_client_connections.label client connections"
|
||||
print "secure_client_connections.label secure client connections"
|
||||
print "insecure_client_connections.label insecure client " \
|
||||
"connections"
|
||||
print("all_client_connections.label client connections")
|
||||
print("secure_client_connections.label secure client connections")
|
||||
print("insecure_client_connections.label insecure client connections")
|
||||
sys.exit(0)
|
||||
|
||||
else:
|
||||
connection_count_re = re.compile(r"Total:\s(\d+)\s")
|
||||
telnet = telnetlib.Telnet(host, port)
|
||||
telnet.write("c2s:show_secure()\n")
|
||||
telnet_response = telnet.read_until("secure client connections",
|
||||
5)
|
||||
telnet_response = telnet.read_until("secure client connections", 5)
|
||||
parsed_info = connection_count_re.findall(telnet_response)
|
||||
secure_client_connections = int(parsed_info[0])
|
||||
print "secure_client_connections.value %s" % \
|
||||
(secure_client_connections)
|
||||
print("secure_client_connections.value %s" % secure_client_connections)
|
||||
|
||||
telnet.write("c2s:show_insecure()\n")
|
||||
telnet_response = telnet.read_until("insecure client connections",
|
||||
5)
|
||||
telnet_response = telnet.read_until("insecure client connections", 5)
|
||||
parsed_info = connection_count_re.findall(telnet_response)
|
||||
insecure_client_connections = int(parsed_info[0])
|
||||
print "insecure_client_connections.value %s" % \
|
||||
(insecure_client_connections)
|
||||
all_client_connections = secure_client_connections + \
|
||||
insecure_client_connections
|
||||
print "all_client_connections.value %s" % (all_client_connections)
|
||||
print("insecure_client_connections.value %s" % insecure_client_connections)
|
||||
all_client_connections = secure_client_connections + insecure_client_connections
|
||||
print("all_client_connections.value %s" % (all_client_connections))
|
||||
telnet.write("quit\n")
|
||||
|
||||
elif wildcard == "s2s":
|
||||
if mode == "config":
|
||||
print "graph_title Prosody S2S Connections"
|
||||
print "graph_vlabel servers"
|
||||
print "graph_category chat"
|
||||
print("graph_title Prosody S2S Connections")
|
||||
print("graph_vlabel servers")
|
||||
print("graph_category chat")
|
||||
|
||||
print "outgoing_connections.label outgoing connections"
|
||||
print "incoming_connections.label incoming connections"
|
||||
print("outgoing_connections.label outgoing connections")
|
||||
print("incoming_connections.label incoming connections")
|
||||
sys.exit(0)
|
||||
|
||||
else:
|
||||
|
@ -93,21 +88,21 @@ def main():
|
|||
telnet.write("s2s:show()\n")
|
||||
telnet_response = telnet.read_until("connections", 5)
|
||||
parsed_info = server_connections_re.findall(telnet_response)
|
||||
print "outgoing_connections.value %s" % (parsed_info[0][0])
|
||||
print "incoming_connections.value %s" % (parsed_info[0][1])
|
||||
print("outgoing_connections.value %s" % (parsed_info[0][0]))
|
||||
print("incoming_connections.value %s" % (parsed_info[0][1]))
|
||||
telnet.write("quit\n")
|
||||
|
||||
elif wildcard == "presence":
|
||||
if mode == "config":
|
||||
print "graph_title Prosody Client Presence"
|
||||
print "graph_vlabel clients"
|
||||
print "graph_category chat"
|
||||
print("graph_title Prosody Client Presence")
|
||||
print("graph_vlabel clients")
|
||||
print("graph_category chat")
|
||||
|
||||
print "available.label Avaible Clients"
|
||||
print "chat.label Ready for Chat Clients"
|
||||
print "away.label Away Clients"
|
||||
print "xa.label Extended Away Clients"
|
||||
print "dnd.label Do Not Disturb Clients"
|
||||
print("available.label Avaible Clients")
|
||||
print("chat.label Ready for Chat Clients")
|
||||
print("away.label Away Clients")
|
||||
print("xa.label Extended Away Clients")
|
||||
print("dnd.label Do Not Disturb Clients")
|
||||
sys.exit(0)
|
||||
|
||||
else:
|
||||
|
@ -116,26 +111,26 @@ def main():
|
|||
telnet.write("c2s:show()\n")
|
||||
telnet_response = telnet.read_until("clients", 5)
|
||||
parsed_info = client_presence_re.findall(telnet_response)
|
||||
print "available.value %s" % (parsed_info.count("available"))
|
||||
print "chat.value %s" % (parsed_info.count("chat"))
|
||||
print "away.value %s" % (parsed_info.count("away"))
|
||||
print "xa.value %s" % (parsed_info.count("xa"))
|
||||
print "dnd.value %s" % (parsed_info.count("dnd"))
|
||||
print("available.value %s" % parsed_info.count("available"))
|
||||
print("chat.value %s" % (parsed_info.count("chat")))
|
||||
print("away.value %s" % (parsed_info.count("away")))
|
||||
print("xa.value %s" % (parsed_info.count("xa")))
|
||||
print("dnd.value %s" % (parsed_info.count("dnd")))
|
||||
telnet.write("quit\n")
|
||||
|
||||
elif wildcard == "uptime":
|
||||
if mode == "config":
|
||||
print "graph_title Prosody Uptime"
|
||||
print "graph_args --base 1000 -l 0"
|
||||
print "graph_scale no"
|
||||
print "graph_vlabel uptime in days"
|
||||
print "graph_category chat"
|
||||
print "graph_order uptime"
|
||||
print "uptime.draw AREA"
|
||||
print "uptime.min U"
|
||||
print "uptime.max U"
|
||||
print "uptime.label uptime"
|
||||
print "uptime.type GAUGE"
|
||||
print("graph_title Prosody Uptime")
|
||||
print("graph_args --base 1000 -l 0")
|
||||
print("graph_scale no")
|
||||
print("graph_vlabel uptime in days")
|
||||
print("graph_category chat")
|
||||
print("graph_order uptime")
|
||||
print("uptime.draw AREA")
|
||||
print("uptime.min U")
|
||||
print("uptime.max U")
|
||||
print("uptime.label uptime")
|
||||
print("uptime.type GAUGE")
|
||||
sys.exit(0)
|
||||
|
||||
else:
|
||||
|
@ -144,16 +139,16 @@ def main():
|
|||
telnet.write("server:uptime()\n")
|
||||
telnet_response = telnet.read_until("minutes (", 5)
|
||||
parsed_info = uptime_re.findall(telnet_response)
|
||||
uptime_value = float(parsed_info[0]) + float(parsed_info[1])/24 +\
|
||||
float(parsed_info[2])/60/24
|
||||
print "uptime.value %s" % (uptime_value)
|
||||
uptime_value = (float(parsed_info[0]) + float(parsed_info[1])/24
|
||||
+ float(parsed_info[2])/60/24)
|
||||
print("uptime.value %s" % (uptime_value))
|
||||
telnet.write("quit\n")
|
||||
|
||||
elif wildcard == "users":
|
||||
if mode == "config":
|
||||
print "graph_title Prosody Registered Users"
|
||||
print "graph_vlabel users"
|
||||
print "graph_category chat"
|
||||
print("graph_title Prosody Registered Users")
|
||||
print("graph_vlabel users")
|
||||
print("graph_category chat")
|
||||
|
||||
base_dir = os.environ.get('internal_storage_path', "/var/lib/prosody")
|
||||
if os.path.isdir(base_dir):
|
||||
|
@ -161,35 +156,40 @@ def main():
|
|||
for vhost in vhosts:
|
||||
account_dir = os.path.join(base_dir, vhost, "accounts")
|
||||
if os.path.isdir(account_dir):
|
||||
vhost = vhost.replace("%2e",".")
|
||||
munin_var = vhost.replace(".","_")
|
||||
vhost = vhost.replace("%2e", ".")
|
||||
munin_var = vhost.replace(".", "_")
|
||||
if mode == "config":
|
||||
print "%s.label %s" % (munin_var, vhost)
|
||||
print("%s.label %s" % (munin_var, vhost))
|
||||
else:
|
||||
accounts = len(list(listfiles(account_dir)))
|
||||
print "%s.value %s" % (munin_var, accounts)
|
||||
print("%s.value %s" % (munin_var, accounts))
|
||||
|
||||
|
||||
def listdirs(folder):
|
||||
for x in os.listdir(folder):
|
||||
if os.path.isdir(os.path.join(folder, x)):
|
||||
yield x
|
||||
|
||||
|
||||
def listfiles(folder):
|
||||
for x in os.listdir(folder):
|
||||
if os.path.isfile(os.path.join(folder, x)):
|
||||
yield x
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
### Here starts the prosody_ plugin documentation, intended to be used with munindoc and in plugin gallery
|
||||
# Here starts the prosody_ plugin documentation, intended to be used with munindoc and in
|
||||
# plugin gallery.
|
||||
"""
|
||||
=head1 NAME
|
||||
|
||||
prosody_ - Munin wildcard-plugin to monitor a L<Prosody|http://prosody.im> xmpp server.
|
||||
|
||||
This wildcard plugin provides at the moment only the suffixes C<c2s>, C<s2s>, C<presence>, C<uptime> and C<users> suffixes.
|
||||
This wildcard plugin provides at the moment only the suffixes C<c2s>, C<s2s>, C<presence>,
|
||||
C<uptime> and C<users> suffixes.
|
||||
|
||||
=head1 INSTALLATION
|
||||
|
||||
|
@ -230,7 +230,8 @@ placed in the directory /etc/munin/plugin-conf.d/ with a config like this:
|
|||
|
||||
=back
|
||||
|
||||
If you want to get the number of registered users, add the following lines to /etc/munin/plugin-conf.d/prosody:
|
||||
If you want to get the number of registered users, add the following lines to
|
||||
/etc/munin/plugin-conf.d/prosody:
|
||||
|
||||
=over 2
|
||||
|
||||
|
|
Loading…
Reference in New Issue