-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhlds1check.py
31 lines (27 loc) · 999 Bytes
/
hlds1check.py
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
#!/usr/bin/env python3
#pip install rHLDS
from rHLDS import Console
import re
try:
checkname = "Ricochet"
host = '192.168.254.194'
port = '27015'
rconpass = 'trololo'
# Default port 27015
srv = Console(host=host, port=port, password=rconpass)
# Connect to server
srv.connect()
#Execute Status command and save result in variable
out = srv.execute("status")
p = re.compile('players[^\n]*')
m = p.search(out)
#Group Text to have only one Line
serverstats=m.group()
#Regex to extract only the numbers
players = re.findall(r'\d+', serverstats)
#Print line to parse it for CheckMK
print('P {} Spieler= {};{};{};{};{} {} {} von {} Spieler auf dem Server'.format(checkname, str(players[0]), str(int(players[1])-2), str(players[1]), 0, str(players[1]), checkname, str(players[0]), str(players[1])))
# Сlose connection
srv.disconnect()
except Exception as e:
print('2 {} - Server nicht erreichbar!'.format(checkname))