root / plugins / other / tsuser @ 08b6b881
Historique | Voir | Annoter | Télécharger (2,54 ko)
| 1 | 82e564f2 | tuni/bernd | #!/usr/bin/perl |
|---|---|---|---|
| 2 | # |
||
| 3 | # This program is free software; you can redistribute it and/or |
||
| 4 | # modify it under the terms of the GNU General Public License |
||
| 5 | # as published by the Free Software Foundation; version 2 dated June, |
||
| 6 | # 1991. |
||
| 7 | # |
||
| 8 | # This program is distributed in the hope that it will be useful, |
||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 11 | # GNU General Public License for more details. |
||
| 12 | # |
||
| 13 | # You should have received a copy of the GNU General Public License |
||
| 14 | # along with this program; if not, write to the Free Software |
||
| 15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
||
| 16 | # |
||
| 17 | # If you modify this plugin please be kind and send a copy to mailto@cot.ath.cx |
||
| 18 | # Thanks |
||
| 19 | # |
||
| 20 | # This plugin counts the number of connected users on your teamspeak2 server. |
||
| 21 | # You have to configure the variables below. |
||
| 22 | |||
| 23 | use strict; |
||
| 24 | use Socket; |
||
| 25 | |||
| 26 | ################## |
||
| 27 | # Config Section # |
||
| 28 | ################## |
||
| 29 | |||
| 30 | # The Host where your teamspeak server is running on. |
||
| 31 | my $host = 'localhost'; |
||
| 32 | # The tcp query port. |
||
| 33 | my $port = 51234; |
||
| 34 | # The udp ports of the servers you wish to monitor. |
||
| 35 | # Enter comma seperated values. e.g. (8767, 8766, 8876) |
||
| 36 | my @uports = (8767); |
||
| 37 | |||
| 38 | ######################### |
||
| 39 | # End of Config Section # |
||
| 40 | ######################### |
||
| 41 | |||
| 42 | my $string = "server_currentusers"; |
||
| 43 | |||
| 44 | if ( exists $ARGV[0] and $ARGV[0] eq "config" ) |
||
| 45 | {
|
||
| 46 | print "graph_title Teamspeak User\n"; |
||
| 47 | print "graph_vlabel Connected Teamspeak Users\n"; |
||
| 48 | print "graph_category Teamspeak\n"; |
||
| 49 | #print "graph_args --base 1000 -l 0\n"; |
||
| 50 | print "graph_info This graph shows the number of connected users on a teamspeak2 server\n"; |
||
| 51 | foreach my $server (@uports) |
||
| 52 | {
|
||
| 53 | print "$server.label Users on $server\n"; |
||
| 54 | print "$server.type GAUGE\n"; |
||
| 55 | #print "$server.draw AREA\n"; |
||
| 56 | } |
||
| 57 | exit 0; |
||
| 58 | } |
||
| 59 | elsif ( exists $ARGV[0] and $ARGV[0] eq "autoconf" ) |
||
| 60 | {
|
||
| 61 | my $TSTCON = &tcpConnect($port, $host); |
||
| 62 | while(<$TSTCON>) |
||
| 63 | {
|
||
| 64 | if ( $_ =~ /[TS]/ ) |
||
| 65 | {
|
||
| 66 | print "Yes\n"; |
||
| 67 | exit 0; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | else |
||
| 72 | {
|
||
| 73 | foreach my $server (@uports) |
||
| 74 | {
|
||
| 75 | my $FS = &tcpConnect($port, $host); |
||
| 76 | print $FS "si ".$server, "\n\n"; |
||
| 77 | my $MASK = $string."=*"; |
||
| 78 | |||
| 79 | while(<$FS>) |
||
| 80 | {
|
||
| 81 | my $input_line = $_; |
||
| 82 | if ( $input_line =~ m/($MASK)/ ) |
||
| 83 | {
|
||
| 84 | $input_line =~ /(\d+)/; |
||
| 85 | print "$server.value $1\n"; |
||
| 86 | close $FS; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | sub tcpConnect() |
||
| 92 | {
|
||
| 93 | my $proto = getprotobyname('tcp');
|
||
| 94 | my $port = shift; |
||
| 95 | my $host = shift; |
||
| 96 | |||
| 97 | socket(my $FS, PF_INET, SOCK_STREAM, $proto); |
||
| 98 | my $sin = sockaddr_in($port, inet_aton($host)); |
||
| 99 | |||
| 100 | connect($FS, $sin) or die exit; |
||
| 101 | my $old_fh = select($FS); $| = 1; select($old_fh); |
||
| 102 | |||
| 103 | return($FS); |
||
| 104 | } |
