check_csgo.cpp 2.16 KB
#include "check_csgo.h"

using namespace std;

char *servicename = (char*)"CS:GO";

void printVersion()
{
	cout << "check_csgo v" << VERSION << endl << endl;
}

void printHelp(bool longVersion)
{
	if(longVersion)
	{
		printVersion();
		cout << "Check Source DS instance." << endl << endl;
		printHelp(false);
		cout << "Options:" << endl;
		cout << " -h" << endl;
		cout << "    Print detailed help screen" << endl;
		cout << " -V" << endl;
		cout << "    Print version information" << endl;
		cout << " -H HOSTADDRESS" << endl;
		cout << "    Host where the Source DS is running" << endl;
		cout << " -p" << endl;
		cout << "    Port where the Source DS is listening. Default is 27015." << endl << endl;
		return;
	}
	cout << "Usage: " << endl << "check_csgo [-hV] -H HOSTADDRESS [-p PORT]" << endl << endl;
}

int check_csgo(char *hostname, uint16_t port, SERVERINFO *server_info)
{
    return 0;
}

int main(int argc, char **argv)
{
	struct itimerval timer;
	timer.it_value.tv_sec = 10;
	timer.it_value.tv_usec = 0;
	timer.it_interval.tv_sec = 0;
	timer.it_interval.tv_usec = 0;
	setitimer (ITIMER_VIRTUAL, &timer, 0);

	struct sigaction sa;
	memset (&sa, 0, sizeof (sa));
	sa.sa_handler = &timer_handler;
	sigaction (SIGVTALRM, &sa, 0);

	uint16_t port = 27015;
	char *hostname = NULL;
	int c;

	while ((c = getopt (argc, argv, "H:p:Vh")) != -1)
	{
		switch(c)
		{
			case 'H':
        			hostname = optarg;
        			break;
			case 'p':
       		 		port = str2int(optarg);
       		 		break;
			case 'V':
				printVersion();
				return 0;
			case 'h':
				printHelp(true);
				return 0;
			case '?':
				printHelp(false);
				return 3;
		}
	}

	if(hostname == NULL)
	{
		cout << "No HOSTADDRESS specified. Exiting." << endl;
		return 3;
	}

	SERVERINFO server_info;
	int returnCode = check_csgo(hostname,port,&server_info);

	cout << servicename;
	switch(returnCode)
	{
		case 0:
			cout << " OK";
			break;

		case 1:
			cout << " WARNING";
			break;

		case 2:
			cout << " CRITICAL";
			break;
	}

	cout << " - " << server_info.name << " " << server_info.ip << " " << server_info.name << " " << server_info.map << " " << server_info.players << " " << server_info.latency << endl;
	return returnCode;
}