Forum


Notice to all users

We are migrating towards a new forum system located at community.teamspeak.com, as such this forum will become read-only on January 29, 2020

Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19

    Query script stopped working

    Since the introduction for the welcome message my script for cacti stats is broken.

    What do i have to change to get it working again?

    Thanks

    from cacti website.
    PHP Code:
    <? 
     function getSocket($host, $port, $errno, $errstr, $timeout) { 
            global $errno, $errstr; 
            $socket = fsockopen($host, $port, $errno, $errstr, $timeout); 
            if(!$socket or fread($socket, 3) != "TS3") { 
                    echo("Server error: Teamspeak server not running!\n"); 
                    return false; 
            } 
            return $socket; 
     } 

     function sendQuery($socket, $query) { 
            fputs($socket, $query."\n"); 
     }
     

     function closeSocket($socket) { 
            fputs($socket, "quit\n"); 
     fclose($socket); 
     } 

     $server = explode(":", $argv[1]); 
     $socket = getSocket($server[0], 10011, $errno, $errstr, 1); 
     if($errno != 0) exit(1); 
     sendQuery($socket, "use sid=".$server[1]);
     fread($socket, 19);
     sendQuery($socket, "serverinfo");
     $vars = fread($socket, 3000); 
     closeSocket($socket); 
     $var1 = explode(" ", $vars); 
     $now = explode("=", $var1[9]); 
     $max = explode("=", $var1[7]); 
     $n = $now[1]-4; 
     echo "max:$max[1] now:$n";
     ?>

  2. #2
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    Thanks,

    Only it is not working.

    First one gives:

    Code:
    php ts3_test2.php IP:1
    Server error: Teamspeak server not running!
    
    Warning: fputs(): supplied argument is not a valid stream resource in /usr/share/cacti/site/scripts/ts3_test2.php on line 17
    
    Warning: fread(): supplied argument is not a valid stream resource in /usr/share/cacti/site/scripts/ts3_test2.php on line 30
    
    Warning: fputs(): supplied argument is not a valid stream resource in /usr/share/cacti/site/scripts/ts3_test2.php on line 17
    
    Warning: fread(): supplied argument is not a valid stream resource in /usr/share/cacti/site/scripts/ts3_test2.php on line 32
    
    Warning: fputs(): supplied argument is not a valid stream resource in /usr/share/cacti/site/scripts/ts3_test2.php on line 22
    
    Warning: fclose(): supplied argument is not a valid stream resource in /usr/share/cacti/site/scripts/ts3_test2.php on line 23
    Second one: gives no output

    I think the error is here.

    PHP Code:
    sendQuery($socket"use sid=".$server[1]);
     
    fread($socket19);
     
    sendQuery($socket"serverinfo");
     
    $vars fread($socket3000); 
    When i change 19 to 155 the script often reply's with the serverinfo.

    I added this line before ?> to look if i get the serverinfo lines.

    PHP Code:
    print_r (explode(" "$vars)); 
    Most times this is empty and the script did not give the serverinfo command.

    Code:
    Array
    (
        [0] => error
        [1] => id=0
        [2] => msg=ok
    
    )
    When set to 19:

    Code:
    Array
    (
        [0] => amSpeak
        [1] => 3
        [2] => ServerQuery
        [3] => interface,
        [4] => type
        [5] => "help"
        [6] => for
        [7] => a
        [8] => list
        [9] => of
        [10] => commands
        [11] => and
        [12] => "help
        [13] => <command>"
        [14] => for
        [15] => information
        [16] => on
        [17] => a
        [18] => specific
        [19] => command.
    error
        [20] => id=0
        [21] => msg=ok
    
    )
    After many times executing sometimes the serverinfo commands is given but not complete.

    Code:
    Array
    (
        [0] => error
        [1] => id=0
        [2] => msg=ok
    virtualserver_unique_identifier=joZed5ZAO476F9DD7MukCTsJcFk=
        [3] => virtualserver_name=Teamspeak
        [4] => virtualserver_welcomemessage=Welkom
        [5] => virtualserver_platform=Linux
        [6] => virtualserver_version=3.0.0-beta29\s[Build:\s12473]
        [7] => virtualserver_maxclients=32
        [8] => virtualserver_password
        [9] => virtualserver_clientsonline=4
        [10] => virtualserver_channelsonline=29
        [11] => virtualserver_created=1269086753
        [12] => virtualserver_uptime=160270
        [13] => virtualserver_codec_encryption_mode=0
        [14] => virtualserver_hostmessage=
        [15] => virtualserver_hostmessage_mode=1
        [16] => virtualserver_filebase=files\/virtualserver_1
        [17] => virtualserver_default_server_group=8
        [18] => virtualserver_default_channel_group=8
        [19] => virtualserver_flag_password=0
        [20] => virtualserver_default_channel_admin_group=5
        [21] => virtualserver_max_download_total_bandwidth=18446744073709551615
        [22] => virtualserver_max_upload_total_bandwidth=18446744073709551615
        [23] => virtualserver_hostbanner_url=
        [24] => virtualserver_hostbanner_gfx_url=
        [25] => virtualserver_hostbanner_gfx_interval=0
        [26] => virtualserver_complain_autoban_count=4
        [27] => virtualserver_complain_autoban_time=1200
        [28] => virtualserver_complain_remove_time=3600
        [29] => virtualserver_min_clients_in_channel_before_forced_silence=100
        [30] => virtualserver_priority_speaker_dimm_modificator=-18.0000
        [31] => virtualserver_id=1
        [32] => virtualserver_antiflood_points_tick_reduce=5
        [33] => virtualserver_antiflood_points_needed_warning=150
        [34] => virtualserver_antiflood_points_needed_kick=250
        [35] => virtualserver_a
    )
    This is only after trial and error but im not an expert.

  3. #3
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    Quote Originally Posted by florian_fr40 View Post
    Send me your script. I modify it.
    I send you MP
    Done.

    Thanks

  4. #4
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    Quote Originally Posted by florian_fr40 View Post
    I resend you the script.

    - Be careful, you had forgot the "tcp://".$host in the fsockopen function
    - I set the timeout to 10 second. One is too little.

    Tested and ok on test server
    Ok, Thanks i will test it now.

  5. #5
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    Dont know why its empty.

    Attachment 4126

    edit:

    Working version posted on cacti forums.
    Your version is cleaner but this one is working maybe you can see what is changed and make it better if you like.

    Thanks again for your help.

    PHP Code:
    #!/usr/bin/php
    <?
    function getSocket($host, $port, $errno, $errstr, $timeout) {
            global $errno, $errstr;
            $socket = fsockopen($host, $port, $errno, $errstr, $timeout);
            if(!$socket or fread($socket, 4) != "TS3\n") {
                    echo("Server error: Teamspeak server not running!\n");
                    return false;
            }
            fread($socket, 200);
            return $socket;
    }

    function sendQuery($socket, $query) {
            fputs($socket, $query."\n");
    }

    function closeSocket($socket) {
            fputs($socket, "quit\n");
    fclose($socket);
    }

    $server = explode(":", $argv[1]);
    $socket = getSocket($server[0], 10011, $errno, $errstr, 1);
    if($errno != 0) exit(1);
    sendQuery($socket, "use sid=".$server[1]);
    fread($socket, 19);
    sendQuery($socket, "serverinfo");
    $vars = fread($socket, 3000);
    closeSocket($socket);
    $var1 = explode(" ", $vars);
    $now = explode("=", $var1[7]);
    $max = explode("=", $var1[5]);
    $n = $now[1]-1;
    echo "max:$max[1] now:$n";
    ?>
    With this one cacti is getting results.
    Attachment 4127
    Last edited by Hendrik; October 1st, 2010 at 11:38 PM.

  6. #6
    Join Date
    July 2007
    Location
    France
    Posts
    30
    The corrected script is very very slow on my cacti install (1mn to get info), could you please link your corrected version florian_fr40 please ?

  7. #7
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    This is the one from florian_fr40.

    Attachment 4140

    When i use it there are no results.

    The other from Korigon @ cacti forums does work without delay.

  8. #8
    Join Date
    July 2007
    Location
    France
    Posts
    30
    Weird, i'll go check both of them, thanks !

    EDIT : the one from florian_fr40 is working perfectly and fast for me, but there is one thing to correct

    Line 62 : $n = $now[1]-4; <-- the now is reduced by 4 you need to only reduce it by 1 to not count the script connection (i personally use -2 because i have a bot too)

    Otherwise working perfectly

  9. #9
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    Just looked at 100+ users ts and it is taking longer to give info. (old server versions)

    Do you have the latest server version? (Beta 29)
    Last edited by Hendrik; October 2nd, 2010 at 12:57 PM.

  10. #10
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    Quote Originally Posted by DaRkBoZ View Post
    Line 62 : $n = $now[1]-4; <-- the now is reduced by 4 you need to only reduce it by 1 to not count the script connection (i personally use -2 because i have a bot too)
    I have javabot logged in 3 times.

  11. #11
    Join Date
    July 2007
    Location
    France
    Posts
    30
    that's why ! , ok script working, but dunno why i now have a permission issues on my other ts3 server, sigh, maybe teamspeak team broke the serverquery a bit in the last beta, gotta check all of that.

    PS : and yup i have the latest version (beta29), the old script from cacti forums was working perfectly with beta 28.
    Last edited by DaRkBoZ; October 2nd, 2010 at 01:15 PM.

  12. #12
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    Dont know what the problem is then maybe php version or something. (Version 5.2.4-2ubuntu5.12)

  13. #13
    Join Date
    July 2007
    Location
    France
    Posts
    30
    I'am running on debian 64bit with PHP 5.3.2-2 with Suhosin-Patch

  14. #14
    Join Date
    February 2010
    Location
    somewhere
    Posts
    19
    Tested florian's script again for other servers.
    It is working for some but not all.

    All i get is:

    Code:
    [email protected]:/usr/share/cacti/site/scripts$ php ts3.php 89.18.168.62:1
    max: now:-4
    Is it a permissions problem?

    Note: Cacti installation is not on the same server.

  15. #15
    Join Date
    July 2007
    Location
    France
    Posts
    30
    add your line

    print_r (explode(" ", $vars));

    before the ?> in the script

    when you have permissions issues it show you something like that

    max: now:-2

    Array
    (
    [0] => error
    [1] => id=2568
    [2] => msg=insufficient\sclient\spermissions
    [3] => failed_permid=8470

    )

    it's the same issue i have on some of my servers. Dunno why yet since with beta 28 old script worked well on the same one.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •