2010-04-14 00:00:01 +02:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
# ts3v2_ (perl)
|
|
|
|
# Munin Plugin for Teamspeak3 Servers
|
|
|
|
# displays the number of connected users on TS3 servers
|
|
|
|
# and average transferrate per second over 5 min.
|
|
|
|
#
|
|
|
|
# You can use it with symlinks for overview and explicit ids.
|
|
|
|
# Also you can configure the following variables:
|
|
|
|
# host
|
|
|
|
# port
|
|
|
|
#
|
|
|
|
# by Marc Urben, www.oxi.ch or www.oom.ch
|
|
|
|
#
|
|
|
|
# Based on Tim Wulkau's script. Thank you!
|
|
|
|
# www.wulkau.de
|
|
|
|
#
|
|
|
|
#######################################################
|
2010-10-02 15:49:40 +02:00
|
|
|
# 02.10.10 - v0.3
|
2018-08-02 02:03:42 +02:00
|
|
|
# -now works again with 3.0.0-beta29
|
2010-04-14 00:00:01 +02:00
|
|
|
#
|
|
|
|
# 18.04.10 - v0.2
|
|
|
|
# -transfer mode added
|
|
|
|
#
|
|
|
|
# 13.04.10 - v0.1
|
|
|
|
# -initial release
|
|
|
|
#
|
|
|
|
######################################################
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf suggest
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
use strict;
|
|
|
|
use Net::Telnet;
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
# CONFIG HERE!
|
2014-02-06 16:29:17 +01:00
|
|
|
my $hostname = $ENV{host} || "localhost"; # serveraddress
|
2010-04-14 00:00:01 +02:00
|
|
|
my $port = $ENV{port} || 10011; # querryport
|
2014-02-06 16:29:17 +01:00
|
|
|
my $user = $ENV{user} || "serveradmin";
|
|
|
|
my $password = $ENV{password} || "";
|
2010-04-14 00:00:01 +02:00
|
|
|
my $filename = "ts3v2_";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
# SCRIPT START!
|
|
|
|
#init telnet connection
|
|
|
|
my $name = ""; my $server = ""; my @num; my $id = 0; my $i = 0; my $myserver; my $transfer;
|
|
|
|
my $telnet = new Net::Telnet(Timeout=>1, Errmode=>"return", Prompt=>"/\r/");
|
|
|
|
if (!$telnet->open(Host=>$hostname, Port=>$port)) {
|
|
|
|
die "Server could not be reached, please check your config!";
|
|
|
|
}
|
2014-02-06 16:29:17 +01:00
|
|
|
|
|
|
|
$telnet->waitfor("/Welcome/");
|
|
|
|
|
|
|
|
if ($password ne "") {
|
|
|
|
$telnet->cmd("login client_login_name=".$user." client_login_password=".$password);
|
|
|
|
my $response = $telnet->getline(Timeout=>1);
|
|
|
|
if ($response !~ "error id=0 msg=ok") {
|
|
|
|
$telnet->close;
|
|
|
|
die "ServerQuery login failed: ".$response;
|
|
|
|
}
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
#get argument
|
|
|
|
my $argument = "";
|
|
|
|
if ($0 =~ /$filename(\w+)$/i) {
|
|
|
|
$argument = $1;
|
|
|
|
} elsif ($ARGV[0] ne "suggest" and $ARGV[0] ne "autoconf") {
|
|
|
|
die "Error: We need to know what serverid you want, so link this plugin as "
|
|
|
|
.$filename."1, ".$filename."2 or ".$filename."overview.\n";
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
#check for overview, transfer or single server mode
|
|
|
|
my $mode = "";
|
2012-08-01 16:41:57 +02:00
|
|
|
if ($argument eq "overview" or $argument eq "transfer" or (defined $ARGV[0] and ($ARGV[0] eq "suggest" or $ARGV[0] eq "autoconf"))) {
|
2010-04-14 00:00:01 +02:00
|
|
|
if ($argument eq "overview") {
|
|
|
|
$mode = "o";
|
|
|
|
} elsif($argument eq "transfer") {
|
|
|
|
$mode = "t";
|
|
|
|
}
|
|
|
|
$telnet->cmd("serverlist");
|
|
|
|
my $line = $telnet->getline(Timeout=>1);
|
|
|
|
my @servers = split(/\|/, $line);
|
|
|
|
foreach (@servers) {
|
|
|
|
if ($_ =~ m/virtualserver_id=(\d+) virtual/) {
|
|
|
|
push(@num, $1);
|
|
|
|
} else {
|
|
|
|
die "ERROR: server string not recognized!\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
|
|
|
} elsif ($argument =~ /^[+-]?\d+$/ ) {
|
|
|
|
$mode = "s";
|
|
|
|
$server = $argument;
|
|
|
|
} else {
|
|
|
|
die "ERROR: unknown plugin mode: $argument\n";
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
#check for config mode
|
|
|
|
if (exists $ARGV[0] and $ARGV[0] eq "autoconf") {
|
|
|
|
print "yes";
|
|
|
|
exit 0;
|
|
|
|
} elsif (exists $ARGV[0] and $ARGV[0] eq "suggest") {
|
|
|
|
print "overview\n";
|
|
|
|
print "transfer\n";
|
|
|
|
foreach (@num) {
|
|
|
|
print $_."\n";
|
|
|
|
}
|
|
|
|
exit 0;
|
|
|
|
} elsif (exists $ARGV[0] and $ARGV[0] eq "config") {
|
|
|
|
if ($mode eq "s") {
|
|
|
|
#single server mode
|
|
|
|
$telnet->cmd("use sid=".$server);
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
|
|
|
$telnet->cmd("serverinfo");
|
|
|
|
my $line = $telnet->getline(Timeout=>1);
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
if ($line =~ m/virtualserver_id=(\d+) virtual/) {
|
|
|
|
my $id = $1;
|
|
|
|
} else {
|
|
|
|
die "ERROR: server string not recognized!\n";
|
|
|
|
}
|
|
|
|
if ($line =~ m/virtualserver_name=(.*) virtualserver_welcomemessage/) {
|
|
|
|
$name = $1;
|
|
|
|
$name =~ s/\\s/ /g;
|
|
|
|
} else {
|
|
|
|
die "ERROR: server string not recognized!\n";
|
|
|
|
}
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
print "graph_title Teamspeak Users ".$name."\n";
|
|
|
|
print "graph_vlabel Connected Teamspeak Users\n";
|
2017-02-23 21:50:22 +01:00
|
|
|
print "graph_category voip\n";
|
2010-04-14 00:00:01 +02:00
|
|
|
print "graph_info This graph shows the number of connected users on a Teamspeak3 server\n";
|
|
|
|
print "users.label Users\n";
|
|
|
|
print "users.info Connected users to ".$name."\n";
|
|
|
|
print "users.type GAUGE\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
exit 0;
|
|
|
|
} elsif ($mode eq "o") {
|
|
|
|
#overview mode
|
|
|
|
print "graph_title Teamspeak Users Overview\n";
|
|
|
|
print "graph_vlabel Connected Teamspeak Users\n";
|
2017-02-23 21:50:22 +01:00
|
|
|
print "graph_category voip\n";
|
2010-04-14 00:00:01 +02:00
|
|
|
print "graph_info This graph shows the number of connected users on a Teamspeak3 server\n";
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
foreach (@num) {
|
|
|
|
$telnet->cmd("use sid=".$_);
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
|
|
|
$telnet->cmd("serverinfo");
|
|
|
|
my $line = $telnet->getline(Timeout=>1);
|
|
|
|
if ($line =~ m/virtualserver_name=(.*) virtualserver_welcomemessage/) {
|
|
|
|
$name = $1;
|
|
|
|
$name =~ s/\\s/ /g;
|
|
|
|
} else {
|
|
|
|
die "ERROR: server string not recognized!\n";
|
|
|
|
}
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
|
|
|
print $_.".label ".$name."\n";
|
|
|
|
print $_.".info Users connected on ".$name."\n";
|
|
|
|
print $_.".type GAUGE\n";
|
|
|
|
}
|
|
|
|
exit 0;
|
|
|
|
} elsif ($mode eq "t") {
|
|
|
|
#transfer mode
|
|
|
|
print "graph_title Teamspeak Transfer Overview\n";
|
|
|
|
print "graph_vlabel Teamspeak Transfer\n";
|
2017-02-23 21:50:22 +01:00
|
|
|
print "graph_category voip\n";
|
2010-04-14 00:00:01 +02:00
|
|
|
print "graph_info This graph shows the Teamspeak3 Transfer Overview\n";
|
|
|
|
print "transfer.label ~ Transfer per second\n";
|
|
|
|
print "transfer.info Transfer per second over 5 min\n";
|
|
|
|
print "transfer.type DERIVE\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
#go go magic, go!
|
|
|
|
if ($mode eq "s") {
|
|
|
|
#single mode
|
|
|
|
$telnet->cmd("use sid=".$server);
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
|
|
|
$telnet->cmd("serverinfo");
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
my $line = $telnet->getline(Timeout=>1);
|
|
|
|
if ($line =~ m/virtualserver_clientsonline=(\d+) /) {
|
|
|
|
print "users.value ".($1-1)."\n";
|
|
|
|
} else {
|
|
|
|
print "users.value 0\n";
|
|
|
|
}
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
|
|
|
} elsif ($mode eq "o") {
|
|
|
|
#overview mode
|
|
|
|
for (@num) {
|
2010-10-02 15:49:40 +02:00
|
|
|
$telnet->waitfor("/Welcome/");
|
2010-04-14 00:00:01 +02:00
|
|
|
$telnet->cmd("use sid=".$_);
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
|
|
|
$telnet->cmd("serverinfo");
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
my $line = $telnet->getline(Timeout=>1);
|
|
|
|
if ($line =~ m/virtualserver_clientsonline=(\d+) /) {
|
|
|
|
print $_.".value ".($1-1)."\n";
|
|
|
|
} else {
|
|
|
|
print $_.".value 0\n";
|
|
|
|
}
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
|
|
|
}
|
|
|
|
} elsif ($mode eq "t") {
|
|
|
|
$telnet->cmd("hostinfo");
|
|
|
|
my @tsave;
|
|
|
|
my $line = $telnet->getline(Timeout=>1);
|
|
|
|
if ($line =~ m/connection_bytes_received_total=(\d+) connection_bandwidth_sent_last_second_total/) {
|
|
|
|
$transfer = $1;
|
|
|
|
print "transfer.value ".(($transfer-($transfer%300))/300)."\n";
|
|
|
|
} else {
|
|
|
|
die "ERROR: server string not recognized!\n";
|
|
|
|
}
|
|
|
|
$telnet->waitfor("/error id=0 msg=ok/");
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
}
|
|
|
|
}
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2010-04-14 00:00:01 +02:00
|
|
|
#close telnet connection
|
|
|
|
$telnet->close;
|
2010-10-02 15:49:40 +02:00
|
|
|
exit;
|