Some Code - Counter Strike Source Server Administration
On Apr 23rd, 22:37
There are several scripts that I've written and have been using for quite some time to automate some auditing tasks. I've decided to share some of these scripts in hopes that it helps you manage your own Source Dedicated server.
I get daily e-mails that show any commands used by the admins on my server. If someone swaps teams, burns a user, kicks or bans someone, it will show up in your e-mail every morning. This can be useful to track anybody who may be abusing their powers. Use this information with caution; logs only tell half the story.
First part is the scrubbing script. The Mani Admin logs do generate a ton of noise so this script will clean some of that up to make them a bit more readable. My server runs as a unprivileged user. If this is the case on your server, you will need to stick the user in the /etc/cron.allow file in order to allow the user to take advantage as cron.
Last thing is that this script requires a python interpreter.
This script is actually a one-liner that is called by crontab several hours after the logs are rolled over. The reason for this is crontab has a line length limit.
Finally, this is how I have my cron configured. I generate the logs at 3am since the server is generally empty around that time. I chose not to send the e-mail shortly after the logs have rolled over since at the time I was receiving e-mails on my phone and it would cause my phone to buzz at 3am. Instead I send the mail at 8am. It's convenient for me to quickly glance at the logs when it comes in at that time.
If you have any questions, feel free to contact me!
vsrz
I get daily e-mails that show any commands used by the admins on my server. If someone swaps teams, burns a user, kicks or bans someone, it will show up in your e-mail every morning. This can be useful to track anybody who may be abusing their powers. Use this information with caution; logs only tell half the story.
First part is the scrubbing script. The Mani Admin logs do generate a ton of noise so this script will clean some of that up to make them a bit more readable. My server runs as a unprivileged user. If this is the case on your server, you will need to stick the user in the /etc/cron.allow file in order to allow the user to take advantage as cron.
Last thing is that this script requires a python interpreter.
#!/usr/bin/python
# scrubs any logs from CONSOLE in mani_admin_plugin and also archives the copy
# with yesterday's date. Should be run via cron every day
#
# This file is called from steam's crontab
#
# By vsrz - vsritual.com 03/23/2011
MANI_ADMLOG_PATH = '/home/steam/css/cstrike/cfg/mani_admin_plugin/mani_logs'
import datetime, os
from datetime import timedelta,date
# open admin log from local folder
f = open(MANI_ADMLOG_PATH + '/adminlog.log', 'r')
# grab yesterday's date and formulate new filename
y = date.today() - timedelta(days=1)
ystr = str(y.year) + str(y.month).zfill(2) + str(y.day).zfill(2)
newfn = MANI_ADMLOG_PATH + '/adminlog-' + ystr + '.txt'
# open new file for appending, in case we are overwriting another file
newf = open(newfn, 'a')
# loop through each and only copy stuff that doesn't have CONSOLE in it
for each in f:
if each.find("CONSOLE") < 0 and each.find("bot_") < 0:
newf.write(each)
# close both files
f.close()
newf.close()
# delete old adminlog file
os.system('cat /dev/null > ' + MANI_ADMLOG_PATH + '/adminlog.log')
This script is actually a one-liner that is called by crontab several hours after the logs are rolled over. The reason for this is crontab has a line length limit.
#!/bin/bash # # send mail with mani log. # # this file is called from crontab # EMAIL_DST='your@email.com' EMAIL_SUBJECT='Adminlog for vsrc `date -d yesterday +%m/%d/%Y`' cat mani_logs/adminlog-`date -d yesterday +%Y%m%d`.txt | mail -s $EMAIL_SUBJECT $EMAIL_DST
Finally, this is how I have my cron configured. I generate the logs at 3am since the server is generally empty around that time. I chose not to send the e-mail shortly after the logs have rolled over since at the time I was receiving e-mails on my phone and it would cause my phone to buzz at 3am. Instead I send the mail at 8am. It's convenient for me to quickly glance at the logs when it comes in at that time.
steam@vsrz:~$ crontab -l # m h dom mon dow command # rotate mani logs every morning at 3am 0 3 * * * /usr/bin/python ~/scrub_mani_logs.py # e-mail copy of rotated logs every morning at 8am # -- change to a decent hour so my phone doesn't go off every morning at 3am 0 8 * * * /home/steam/mail_send.sh
If you have any questions, feel free to contact me!
vsrz