diff options
Diffstat (limited to 'plugins/check_game.c')
| -rw-r--r-- | plugins/check_game.c | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/plugins/check_game.c b/plugins/check_game.c index c0193b03..974a7253 100644 --- a/plugins/check_game.c +++ b/plugins/check_game.c | |||
| @@ -77,7 +77,8 @@ int main(int argc, char **argv) { | |||
| 77 | 77 | ||
| 78 | /* create the command line to execute */ | 78 | /* create the command line to execute */ |
| 79 | char *command_line = NULL; | 79 | char *command_line = NULL; |
| 80 | xasprintf(&command_line, "%s -raw %s -%s %s", PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, config.game_type, config.server_ip); | 80 | xasprintf(&command_line, "%s -raw %s -%s %s", PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, |
| 81 | config.game_type, config.server_ip); | ||
| 81 | 82 | ||
| 82 | if (config.port) { | 83 | if (config.port) { |
| 83 | xasprintf(&command_line, "%s:%-d", command_line, config.port); | 84 | xasprintf(&command_line, "%s:%-d", command_line, config.port); |
| @@ -130,11 +131,13 @@ int main(int argc, char **argv) { | |||
| 130 | printf(_("CRITICAL - Game server timeout\n")); | 131 | printf(_("CRITICAL - Game server timeout\n")); |
| 131 | result = STATE_CRITICAL; | 132 | result = STATE_CRITICAL; |
| 132 | } else { | 133 | } else { |
| 133 | printf("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n", ret[config.qstat_game_players], ret[config.qstat_game_players_max], | 134 | printf("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n", ret[config.qstat_game_players], |
| 134 | ret[config.qstat_game_field], ret[config.qstat_map_field], ret[config.qstat_ping_field], | 135 | ret[config.qstat_game_players_max], ret[config.qstat_game_field], |
| 135 | perfdata("players", atol(ret[config.qstat_game_players]), "", false, 0, false, 0, true, 0, true, | 136 | ret[config.qstat_map_field], ret[config.qstat_ping_field], |
| 136 | atol(ret[config.qstat_game_players_max])), | 137 | perfdata("players", atol(ret[config.qstat_game_players]), "", false, 0, false, 0, |
| 137 | fperfdata("ping", strtod(ret[config.qstat_ping_field], NULL), "", false, 0, false, 0, true, 0, false, 0)); | 138 | true, 0, true, atol(ret[config.qstat_game_players_max])), |
| 139 | fperfdata("ping", strtod(ret[config.qstat_ping_field], NULL), "", false, 0, false, 0, | ||
| 140 | true, 0, false, 0)); | ||
| 138 | } | 141 | } |
| 139 | 142 | ||
| 140 | exit(result); | 143 | exit(result); |
| @@ -144,19 +147,20 @@ int main(int argc, char **argv) { | |||
| 144 | #define max_players_field_index 130 | 147 | #define max_players_field_index 130 |
| 145 | 148 | ||
| 146 | check_game_config_wrapper process_arguments(int argc, char **argv) { | 149 | check_game_config_wrapper process_arguments(int argc, char **argv) { |
| 147 | static struct option long_opts[] = {{"help", no_argument, 0, 'h'}, | 150 | static struct option long_opts[] = { |
| 148 | {"version", no_argument, 0, 'V'}, | 151 | {"help", no_argument, 0, 'h'}, |
| 149 | {"verbose", no_argument, 0, 'v'}, | 152 | {"version", no_argument, 0, 'V'}, |
| 150 | {"timeout", required_argument, 0, 't'}, | 153 | {"verbose", no_argument, 0, 'v'}, |
| 151 | {"hostname", required_argument, 0, 'H'}, | 154 | {"timeout", required_argument, 0, 't'}, |
| 152 | {"port", required_argument, 0, 'P'}, | 155 | {"hostname", required_argument, 0, 'H'}, |
| 153 | {"game-type", required_argument, 0, 'G'}, | 156 | {"port", required_argument, 0, 'P'}, |
| 154 | {"map-field", required_argument, 0, 'm'}, | 157 | {"game-type", required_argument, 0, 'G'}, |
| 155 | {"ping-field", required_argument, 0, 'p'}, | 158 | {"map-field", required_argument, 0, 'm'}, |
| 156 | {"game-field", required_argument, 0, 'g'}, | 159 | {"ping-field", required_argument, 0, 'p'}, |
| 157 | {"players-field", required_argument, 0, players_field_index}, | 160 | {"game-field", required_argument, 0, 'g'}, |
| 158 | {"max-players-field", required_argument, 0, max_players_field_index}, | 161 | {"players-field", required_argument, 0, players_field_index}, |
| 159 | {0, 0, 0, 0}}; | 162 | {"max-players-field", required_argument, 0, max_players_field_index}, |
| 163 | {0, 0, 0, 0}}; | ||
| 160 | 164 | ||
| 161 | check_game_config_wrapper result = { | 165 | check_game_config_wrapper result = { |
| 162 | .config = check_game_config_init(), | 166 | .config = check_game_config_init(), |
| @@ -216,21 +220,24 @@ check_game_config_wrapper process_arguments(int argc, char **argv) { | |||
| 216 | break; | 220 | break; |
| 217 | case 'p': /* index of ping field */ | 221 | case 'p': /* index of ping field */ |
| 218 | result.config.qstat_ping_field = atoi(optarg); | 222 | result.config.qstat_ping_field = atoi(optarg); |
| 219 | if (result.config.qstat_ping_field < 0 || result.config.qstat_ping_field > QSTAT_MAX_RETURN_ARGS) { | 223 | if (result.config.qstat_ping_field < 0 || |
| 224 | result.config.qstat_ping_field > QSTAT_MAX_RETURN_ARGS) { | ||
| 220 | result.errorcode = ERROR; | 225 | result.errorcode = ERROR; |
| 221 | return result; | 226 | return result; |
| 222 | } | 227 | } |
| 223 | break; | 228 | break; |
| 224 | case 'm': /* index on map field */ | 229 | case 'm': /* index on map field */ |
| 225 | result.config.qstat_map_field = atoi(optarg); | 230 | result.config.qstat_map_field = atoi(optarg); |
| 226 | if (result.config.qstat_map_field < 0 || result.config.qstat_map_field > QSTAT_MAX_RETURN_ARGS) { | 231 | if (result.config.qstat_map_field < 0 || |
| 232 | result.config.qstat_map_field > QSTAT_MAX_RETURN_ARGS) { | ||
| 227 | result.errorcode = ERROR; | 233 | result.errorcode = ERROR; |
| 228 | return result; | 234 | return result; |
| 229 | } | 235 | } |
| 230 | break; | 236 | break; |
| 231 | case 'g': /* index of game field */ | 237 | case 'g': /* index of game field */ |
| 232 | result.config.qstat_game_field = atoi(optarg); | 238 | result.config.qstat_game_field = atoi(optarg); |
| 233 | if (result.config.qstat_game_field < 0 || result.config.qstat_game_field > QSTAT_MAX_RETURN_ARGS) { | 239 | if (result.config.qstat_game_field < 0 || |
| 240 | result.config.qstat_game_field > QSTAT_MAX_RETURN_ARGS) { | ||
| 234 | result.errorcode = ERROR; | 241 | result.errorcode = ERROR; |
| 235 | return result; | 242 | return result; |
| 236 | } | 243 | } |
| @@ -240,14 +247,16 @@ check_game_config_wrapper process_arguments(int argc, char **argv) { | |||
| 240 | if (result.config.qstat_game_players_max == 0) { | 247 | if (result.config.qstat_game_players_max == 0) { |
| 241 | result.config.qstat_game_players_max = result.config.qstat_game_players - 1; | 248 | result.config.qstat_game_players_max = result.config.qstat_game_players - 1; |
| 242 | } | 249 | } |
| 243 | if (result.config.qstat_game_players < 0 || result.config.qstat_game_players > QSTAT_MAX_RETURN_ARGS) { | 250 | if (result.config.qstat_game_players < 0 || |
| 251 | result.config.qstat_game_players > QSTAT_MAX_RETURN_ARGS) { | ||
| 244 | result.errorcode = ERROR; | 252 | result.errorcode = ERROR; |
| 245 | return result; | 253 | return result; |
| 246 | } | 254 | } |
| 247 | break; | 255 | break; |
| 248 | case max_players_field_index: /* index of max players field */ | 256 | case max_players_field_index: /* index of max players field */ |
| 249 | result.config.qstat_game_players_max = atoi(optarg); | 257 | result.config.qstat_game_players_max = atoi(optarg); |
| 250 | if (result.config.qstat_game_players_max < 0 || result.config.qstat_game_players_max > QSTAT_MAX_RETURN_ARGS) { | 258 | if (result.config.qstat_game_players_max < 0 || |
| 259 | result.config.qstat_game_players_max > QSTAT_MAX_RETURN_ARGS) { | ||
| 251 | result.errorcode = ERROR; | 260 | result.errorcode = ERROR; |
| 252 | return result; | 261 | return result; |
| 253 | } | 262 | } |
| @@ -286,7 +295,7 @@ void print_help(void) { | |||
| 286 | printf(UT_HELP_VRSN); | 295 | printf(UT_HELP_VRSN); |
| 287 | printf(UT_EXTRA_OPTS); | 296 | printf(UT_EXTRA_OPTS); |
| 288 | printf(" -H, --hostname=ADDRESS\n" | 297 | printf(" -H, --hostname=ADDRESS\n" |
| 289 | " Host name, IP Address, or unix socket (must be an absolute path)\n"); | 298 | " Host name, IP Address, or unix socket (must be an absolute path)\n"); |
| 290 | printf(" %s\n", "-P"); | 299 | printf(" %s\n", "-P"); |
| 291 | printf(" %s\n", _("Optional port to connect to")); | 300 | printf(" %s\n", _("Optional port to connect to")); |
| 292 | printf(" %s\n", "-g"); | 301 | printf(" %s\n", "-g"); |
| @@ -300,8 +309,10 @@ void print_help(void) { | |||
| 300 | 309 | ||
| 301 | printf("\n"); | 310 | printf("\n"); |
| 302 | printf("%s\n", _("Notes:")); | 311 | printf("%s\n", _("Notes:")); |
| 303 | printf(" %s\n", _("This plugin uses the 'qstat' command, the popular game server status query tool.")); | 312 | printf(" %s\n", |
| 304 | printf(" %s\n", _("If you don't have the package installed, you will need to download it from")); | 313 | _("This plugin uses the 'qstat' command, the popular game server status query tool.")); |
| 314 | printf(" %s\n", | ||
| 315 | _("If you don't have the package installed, you will need to download it from")); | ||
| 305 | printf(" %s\n", _("https://github.com/multiplay/qstat before you can use this plugin.")); | 316 | printf(" %s\n", _("https://github.com/multiplay/qstat before you can use this plugin.")); |
| 306 | 317 | ||
| 307 | printf(UT_SUPPORT); | 318 | printf(UT_SUPPORT); |
| @@ -309,7 +320,8 @@ void print_help(void) { | |||
| 309 | 320 | ||
| 310 | void print_usage(void) { | 321 | void print_usage(void) { |
| 311 | printf("%s\n", _("Usage:")); | 322 | printf("%s\n", _("Usage:")); |
| 312 | printf(" %s [-hvV] [-P port] [-t timeout] [-g game_field] [-m map_field] [-p ping_field] [-G game-time] [-H hostname] <game> " | 323 | printf(" %s [-hvV] [-P port] [-t timeout] [-g game_field] [-m map_field] [-p ping_field] [-G " |
| 324 | "game-time] [-H hostname] <game> " | ||
| 313 | "<ip_address>\n", | 325 | "<ip_address>\n", |
| 314 | progname); | 326 | progname); |
| 315 | } | 327 | } |
