This repository has been archived by the owner on Sep 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
teamspeak.go
72 lines (55 loc) · 2.98 KB
/
teamspeak.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"fmt"
"github.com/thannaske/go-ts3"
"os"
)
const (
VERSION = "1.0.0"
)
func main() {
serverPtr := flag.String("server", "127.0.0.1:10011", "IP address or hostname of Teamspeak 3 server query (default: 127.0.0.1)")
usernamePtr := flag.String("username", "serveradmin", "Teamspeak 3 server query user (default: serveradmin)")
passwordPtr := flag.String("password", "", "Teamspeak 3 server query password (default: none)")
flag.Parse()
c, err := ts3.NewClient(*serverPtr)
if err != nil {
fmt.Println(os.Stderr, "[Error] Could not establish server query connection to", *serverPtr)
os.Exit(1)
}
defer c.Close()
if err := c.Login(*usernamePtr, *passwordPtr); err != nil {
fmt.Println(os.Stderr, "[Error] Authentication failure")
os.Exit(1)
}
if serverList, err := c.Server.ExtendedList(); err != nil {
fmt.Println(os.Stderr, "[Error] Could not iterate through Teamspeak 3 server instances")
os.Exit(1)
} else {
for _, server := range serverList {
err := c.Use(server.ID)
if err != nil {
if err.Error() == "server is not running (1033)" {
continue // ignore offline servers
} else {
fmt.Println(os.Stderr, "[Error] Could not select Teamspeak 3 server instance by ID")
os.Exit(1)
}
}
var serverAutoStart int = 0
if server.AutoStart == true {
serverAutoStart = 1
}
var voice_clients = server.ClientsOnline - server.QueryClientsOnline
var serverStatus int = 0
if server.Status == "online" {
serverStatus = 1
} else {
serverStatus = 2
}
var format string = "teamspeak_server,port=%d,id=%d online=%d,v_clients=%d,q_clients=%d,m_clients=%d,autostart=%d,bytes_out=%d,bytes_in=%d,channels=%d,reserved_slots=%d,uptime=%d,packets_in=%d,packets_out=%d,ft_bytes_in_total=%d,ft_bytes_out_total=%d,pl_control=%f,pl_speech=%f,pl_keepalive=%f,pl_total=%f,bytes_out_speech=%d,bytes_in_speech=%d,bytes_out_control=%d,bytes_in_control=%d,bytes_out_keepalive=%d,bytes_in_keepalive=%d,packets_out_speech=%d,packets_in_speech=%d,packets_out_control=%d,packets_in_control=%d,packets_keepalive_out=%d,packets_keepalive_in=%d,avg_ping=%f\n"
fmt.Printf(format, server.Port, server.ID, serverStatus, voice_clients, server.QueryClientsOnline, server.MaxClients, serverAutoStart, server.BytesSentTotal, server.BytesReceivedTotal, server.ChannelsOnline, server.ReservedSlots, server.Uptime, server.PacketsReceivedTotal, server.PacketsSentTotal, server.TotalBytesUploaded, server.TotalBytesDownloaded, server.TotalPacketLossControl, server.TotalPacketLossSpeech, server.TotalPacketLossKeepalive, server.TotalPacketLossTotal, server.SpeechBytesSent, server.SpeechBytesReceived, server.ControlBytesSent, server.ControlBytesReceived, server.KeepaliveBytesSent, server.KeepaliveBytesReceived, server.SpeechPacketsSent, server.SpeechPacketsReceived, server.ControlPacketsSent, server.ControlPacketsReceived, server.KeepalivePacketsSent, server.KeepalivePacketsReceived, server.TotalPing)
}
}
}