check_csgo.cpp
2.16 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#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;
}