Back to index

nagios-plugins  1.4.16
Defines | Functions | Variables
check_game.c File Reference
#include "common.h"
#include "utils.h"
#include "runcmd.h"

Go to the source code of this file.




int process_arguments (int, char **)
int validate_arguments (void)
void print_help (void)
void print_usage (void)
int main (int argc, char **argv)


const char * progname = "check_game"
const char * copyright = "2002-2007"
const char * email = ""
char * server_ip
char * game_type
int port = 0
int verbose
int qstat_game_players_max = -1
int qstat_game_players = -1
int qstat_game_field = -1
int qstat_map_field = -1
int qstat_ping_field = -1

Define Documentation


Definition at line 45 of file check_game.c.


Definition at line 48 of file check_game.c.


Definition at line 47 of file check_game.c.


Definition at line 49 of file check_game.c.


Definition at line 50 of file check_game.c.

Function Documentation

int main ( int  argc,
char **  argv 

Definition at line 66 of file check_game.c.

  char *command_line;
  int result = STATE_UNKNOWN;
  char *p, *ret[QSTAT_MAX_RETURN_ARGS];
  size_t i = 0;
  output chld_out;

  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEDIR);
  textdomain (PACKAGE);

  /* Parse extra opts if any */
  argv=np_extra_opts (&argc, argv, progname);

  if (process_arguments (argc, argv) == ERROR)
    usage_va(_("Could not parse arguments"));

  result = STATE_OK;

  /* create the command line to execute */
  asprintf (&command_line, "%s -raw %s -%s %s",
            PATH_TO_QSTAT, QSTAT_DATA_DELIMITER, game_type, server_ip);

  if (port)
    asprintf (&command_line, "%s:%-d", command_line, port);

  if (verbose > 0)
    printf ("%s\n", command_line);

  /* run the command. historically, this plugin ignores output on stderr,
   * as well as return status of the qstat program */
  (void)np_runcmd(command_line, &chld_out, NULL, 0);

  /* sanity check */
  /* was thinking about running qstat without any options, capturing the
     -default line, parsing it & making an array of all know server types
     but thought this would be too much hassle considering this is a tool
     for intelligent sysadmins (ha). Could put a static array of known
     server types in a header file but then we'd be limiting ourselves

     In the end, I figured I'd simply let an error occur & then trap it

  if (!strncmp (chld_out.line[0], "unknown option", 14)) {
    printf (_("CRITICAL - Host type parameter incorrect!\n"));
    result = STATE_CRITICAL;
    return result;

  p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER);
  while (p != NULL) {
    ret[i] = p;
    p = (char *) strtok (NULL, QSTAT_DATA_DELIMITER);

  if (strstr (ret[2], QSTAT_HOST_ERROR)) {
    printf (_("CRITICAL - Host not found\n"));
    result = STATE_CRITICAL;
  else if (strstr (ret[2], QSTAT_HOST_DOWN)) {
    printf (_("CRITICAL - Game server down or unavailable\n"));
    result = STATE_CRITICAL;
  else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) {
    printf (_("CRITICAL - Game server timeout\n"));
    result = STATE_CRITICAL;
  else {
    printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n",
            perfdata ("players", atol(ret[qstat_game_players]), "",
                      FALSE, 0, FALSE, 0,
                      TRUE, 0, TRUE, atol(ret[qstat_game_players_max])),
            fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "",
                      FALSE, 0, FALSE, 0,
                      TRUE, 0, FALSE, 0));

  return result;

Here is the call graph for this function:

void print_help ( void  )
void print_usage ( void  )

Definition at line 389 of file check_cpqarray.c.

  printf("cpqarrayd [options]\n");
  printf("   -h         prints this text\n");
  printf("   -d         enables debugging\n");
int process_arguments ( int  argc,
char **  argv 
int validate_arguments ( void  )

Variable Documentation

const char* copyright = "2002-2007"

Definition at line 33 of file check_game.c.

const char* email = ""

Definition at line 34 of file check_game.c.

char* game_type

Definition at line 53 of file check_game.c.

int port = 0

Definition at line 54 of file check_game.c.

const char* progname = "check_game"

Definition at line 32 of file check_game.c.

int qstat_game_field = -1

Definition at line 60 of file check_game.c.

Definition at line 59 of file check_game.c.

Definition at line 58 of file check_game.c.

int qstat_map_field = -1

Definition at line 61 of file check_game.c.

int qstat_ping_field = -1

Definition at line 62 of file check_game.c.

char* server_ip

Definition at line 52 of file check_game.c.

int verbose

Definition at line 56 of file check_game.c.