#!/usr/bin/env python # # Plugin to monitor the number of TeamSpeak3 users. # #e.g. # ln -s /path/ts3_ /etc/munin/plugins/ts3_1 # #%# family=auto #%# capabilities=autoconf #config ip = '127.0.0.1' port = 10011 # #key to get the number of online clients. clientkey = 'virtualserver_password virtualserver_clientsonline' #key to get the number of online query clients. qclientkey = 'virtualserver_hostbutton_tooltip virtualserver_hostbutton_url virtualserver_queryclientsonline' #name of server. srvnamekey = 'virtualserver_name' import sys,os,string,PyTS3 sid = string.replace(os.path.basename(sys.argv[0]), 'ts3_', '') sid = 1 if sid == '' else int(sid) def get_info(ip, port): q_srv = PyTS3.ServerQuery(ip, port) if q_srv.connect()[1] != 0: return None if q_srv.command('use', {'sid':sid})[1] != "0": return None srv_prop = q_srv.command('serverinfo')[4][0] q_srv.disconnect() return srv_prop if len(sys.argv) > 1 and sys.argv[1] == 'autoconf': if get_info(ip, port) is not None: print 'yes' sys.exit(0) else: print 'no' sys.exit(1) if len(sys.argv) > 1 and sys.argv[1] == 'config': srv_name = get_info(ip, port)[srvnamekey] print "graph_title Number of TeamSpeak3 Users [" + srv_name + "]" print "graph_args --base 1000 -l 0" print "graph_vlabel number of users" print "graph_category TeamSpeak3" print "graph_info The graph shows the number of users in the TeamSpeak3 server [" + srv_name+ "]." print "TeamSpeak3.label users" print "TeamSpeak3.draw LINE2" print "The current number of users." sys.exit(0) srv_prop = get_info(ip, port) print "TeamSpeak3.value " + str(int(srv_prop[clientkey]) - int(srv_prop[qclientkey]))