Creating Plugin for Counter-Strike Server Status including perfdata - How could be the best way?

Hello everybody,

just in the beginning. I’m not a developer, I’m just someone with a bit of PHP knowledge, Bash scripting and can read some tutorials and make it work :smiley:

After getting awesome help with a teamspeak plugin I’m reaching out to you again to get some help regards a plugin I would need to write complete on my own. In addition I would need to monitor all the gameserver, that are running on a weekend. The good news with this: Everything is Half Life Based, which means every server uses the RCON Protocol: https://developer.valvesoftware.com/wiki/Source_RCON_Protocol

My problem is now, I don’t know the best practice to begin with it. The endgoal is: See if the server is online and record the perfdata of the connected players to have at the end an great RRD graph and see how many users were connected on the server.

Since I got a bit of knowledge in PHP my first Idea was, using the following library: (click), let it run from the CheckMK Server (since there is a variable to set the destination IP) and then collect everything. Another idea would be, using one of the python libs and let it run on the servers localy.

And my last struggle: How can I write everything for WATO, that I can define Host & Service Parameters, since everyserver has a different IP and a different password.

I thank everyone in advance for helping me with that! :slight_smile:

Cheers,
Gamie

IMHO I would not use PHP within the checkmk system. There seems to be a decent Python library available here: https://python-valve.readthedocs.io/en/latest/rcon.html

You need to first decide if an agent plugin is sufficient (i.e. you can install the checkmk agent on the host running your game server) or if you need a special agent as datasource program running on the monitoring server.

It looks like this is a great task for you to learn many of the checkmk internals. Have fun!

https://checkmk.com/cms_devel_check_plugins.html

https://checkmk.com/cms_legacy_writing_checks.html

Hello again :smiley:

After sawing the email I remembered you :smiley:

I experiemented with an Bash library too of rcon, but after some digging and trying out I was able to write the agent in Python3 for it and got an great output:

<<<rconcheck>>>
[b'hostname: W2TJ Competitive Server
version : 1.37.5.3/13753 1119/7863 insecure  [INVALID_STEAMID]
udp/ip  : 10.0.7.13:27015
os      :  Linux
type    :  community dedicated
map     : de_dust2
players : 0 humans, 0 bots (30/0 max) (hibernating)

# userid name uniqueid connected ping loss state rate adr
#end
\x00\x00']

What I’m now struggeling with is, that I hard code the RCON Password:

#!/usr/bin/env python3
from srcds.rcon import RconConnection
import socket
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
print ("<<<rconcheck>>>")
try:
    conn = RconConnection(ip, port=27015, password='Strongpasswd')
    response = conn.exec_command('status')
    print (response.replace("\\n","\n"))
except:
    print("Something went wrong")

I guess in your checks you were able to put in some placeholders and write the credentials in WATO, didn’t you?

And again, like in TeamSpeak3 I’m stuck at the Check Plugin. I read the docu and read a lot of the check plugin that you wrote for me. Well, It seems that I did something wrong, because my CheckMK doesn’t recognize this check :frowning:

#!/usr/bin/env python
#<<<rconcheck>>>
#[b'hostname: W2TJ Competitive Server
#version : 1.37.5.3/13753 1119/7863 insecure  [INVALID_STEAMID]
#udp/ip  : 10.0.7.13:27015
#os      :  Linux
#type    :  community dedicated
#map     : de_dust2
#players : 0 humans, 0 bots (30/0 max) (hibernating)

def parse_rconcheck(info):
    parsed = {u'players': {}}
    for line in info:
        if line[0][:-1] == "players":
            data = {u'clientsonline': int(line[1][1:]),
                    u'humans': line[2],
                    u'botsonline': int(line[3]),
                    u'bots': line[4],
                    u'maxnumber': line[5],
                    u'maxtext': line[6],
                    u'hibernating': int(line[7][:-1])}
            parsed[u'players'][data['clientsonline']] = data
        else:
            parsed[line[0][:-1]] = " ".join(line[1:])
    return parsed

def inventory_rconcheck(parsed):
    if parsed.get(u'version'):
        yield u'Global', {}
    for port, vs in parsed['players'].iteritems():
        yield port, {u'humans': vs[u'humans'], u'humans': vs[u'humans']}

def check_rconcheck(item, params, parsed):
    if 'wrong' in parsed:
        return 1, "Something went wrong"
    if item in parsed[u'players']:
        vs = parsed[u'players'][item]
        state = 0
        text = vs[u'clientsonline']
        if vs[u'clientsonline'] != params[u'clientsonline']:
            text += '(!!)'
            state = max(state, 2)
        text += " (%d players, %d bots), max %s" % (vs[u'clientsonline'], vs[u'botsonline'], vs[u'maxnumber'])
        now = time.time()
#        in_rate = get_rate('teamspeak3.%d.if_in_octets' % item, now, vs[u'ingress'])
#        out_rate = get_rate('teamspeak3.%d.if_out_octets' % item, now, vs[u'egress'])
#        perfdata = [ (u'current_users', vs[u'clientsonline'], None, None, 0, vs[u'clientsmax']),
#                     (u'channels', vs[u'channels']),
#                     (u'if_in_octets', in_rate),
#                     (u'if_out_octets', out_rate) ]
        return state, text#, perfdata
    if item == u'Global':
        return 0, "Spieler: %s, Bots: %s" % (parsed[u'clientsonline'], parsed[u'botsonline'])

check_info['rconcheck'] = {
    'parse_function':      parse_rconcheck,
    'inventory_function':  inventory_rconcheck,
    'check_function':      check_rconcheck,
    'service_description': "RCONCheck %s",
    'has_perfdata':        True,
}

Do you got the time and an idea what went wrong with the CheckPlugin?

Thank in advance!

Cheers,
Gamie

After a couple of days and with the help of my friend he was able to write the Check. We comitted it to Github:

I still have to create the package and we need to make a different Check for Games that are in the GoldSrc Engine (CS 1.6, Half-Life 1, Ricochet etc) but that shoudl be doable. Thanks again for you help!

Cheers,

Gamie

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.