Code

return of process_arguments() is TRUE not OK !
[nagiosplug.git] / plugins / check_game.c
index dd16777322a7e10a2b5d82e104775863b08c2fa0..c8492d8f172aa846eedbbb17cdc7bad73492fe67 100644 (file)
@@ -14,6 +14,7 @@
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
+* $Id$
 *****************************************************************************/
 
 const char *progname = "check_game";
@@ -43,11 +44,11 @@ int port = 0;
 
 int verbose;
 
-int qstat_game_players_max = 4;
-int qstat_game_players = 5;
-int qstat_game_field = 2;
-int qstat_map_field = 3;
-int qstat_ping_field = 5;
+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;
 
 
 int
@@ -64,17 +65,21 @@ main (int argc, char **argv)
        bindtextdomain (PACKAGE, LOCALEDIR);
        textdomain (PACKAGE);
 
-       result = process_arguments (argc, argv);
+//     result = process_arguments (argc, argv);
+       
+       if (process_arguments (argc, argv) != TRUE)
+               usage (_("check_game: could not parse arguments\n"));
 
-       if (result != OK) {
+/*     if (result != OK) {
                printf (_("Incorrect arguments supplied\n"));
                printf ("\n");
                print_revision (progname, revision);
-               printf (_("Copyright (c) 1999 Ian Cass, Knowledge Matters Limited\n"));
+               printf ("Copyright (c) 1999 Ian Cass, Knowledge Matters Limited\n");
                printf (_("License: GPL\n"));
                printf ("\n");
                return STATE_UNKNOWN;
        }
+*/
 
        result = STATE_OK;
 
@@ -91,7 +96,7 @@ main (int argc, char **argv)
        /* run the command */
        fp = spopen (command_line);
        if (fp == NULL) {
-               printf (_("Error - Could not open pipe: %s\n"), command_line);
+               printf (_("Could not open pipe: %s\n"), command_line);
                return STATE_UNKNOWN;
        }
 
@@ -111,7 +116,7 @@ main (int argc, char **argv)
         */
 
        if (!strncmp (input_buffer, "unknown option", 14)) {
-               printf (_("ERROR: Host type parameter incorrect!\n"));
+               printf (_("CRITICAL - Host type parameter incorrect!\n"));
                result = STATE_CRITICAL;
                return result;
        }
@@ -131,24 +136,30 @@ main (int argc, char **argv)
        }
 
        if (strstr (ret[2], QSTAT_HOST_ERROR)) {
-               printf ("ERROR: Host not found\n");
+               printf ("CRITICAL - Host not found\n");
                result = STATE_CRITICAL;
        }
        else if (strstr (ret[2], QSTAT_HOST_DOWN)) {
-               printf ("ERROR: Game server down or unavailable\n");
+               printf ("CRITICAL - Game server down or unavailable\n");
                result = STATE_CRITICAL;
        }
        else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) {
-               printf ("ERROR: Game server timeout\n");
+               printf ("CRITICAL - Game server timeout\n");
                result = STATE_CRITICAL;
        }
        else {
-               printf ("OK: %s/%s %s (%s), Ping: %s ms\n", 
+               printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n", 
                        ret[qstat_game_players],
                        ret[qstat_game_players_max],
                        ret[qstat_game_field], 
                        ret[qstat_map_field],
-                       ret[qstat_ping_field]);
+                       ret[qstat_ping_field],
+                                               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));
        }
 
        /* close the pipe */
@@ -246,6 +257,8 @@ process_arguments (int argc, char **argv)
                        break;
                case 129: /* index of player count field */
                        qstat_game_players = atoi (optarg);
+                       if (qstat_game_players_max == 0)
+                               qstat_game_players_max = qstat_game_players - 1;
                        if (qstat_game_players < 0 || qstat_game_players > QSTAT_MAX_RETURN_ARGS)
                                return ERROR;
                        break;
@@ -272,14 +285,28 @@ process_arguments (int argc, char **argv)
 int
 validate_arguments (void)
 {
-               return OK;
+       if (qstat_game_players_max < 0)
+               qstat_game_players_max = 4;
+
+       if (qstat_game_players < 0)
+               qstat_game_players = 5;
+
+       if (qstat_game_field < 0)
+               qstat_game_field = 2;
+
+       if (qstat_map_field < 0)
+               qstat_map_field = 3;
+
+       if (qstat_ping_field < 0)
+               qstat_ping_field = 5;
+
+       return OK;
 }
 
 
 
 
 
-\f
 void
 print_help (void)
 {
@@ -323,3 +350,18 @@ Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\
   [-pf ping_field]\n"), progname);
        printf (_(UT_HLP_VRS), progname, progname);
 }
+
+/******************************************************************************
+ *
+ * Test Cases:
+ *
+ * ./check_game --players 7 -p 8 --map 5 qs 67.20.190.61 26000
+ * 
+ * qstat -raw , -qs 67.20.190.61
+ *  ==> QS,67.20.190.61,Nightmare.fintek.ca,67.20.190.61:26000,3,e2m1,6,0,83,0
+ *
+ * qstat -qs 67.20.190.61
+ *  ==> ADDRESS           PLAYERS      MAP   RESPONSE TIME    NAME
+ *  ==> 67.20.190.61            0/ 6     e2m1     79 / 0   Nightmare.fintek.ca
+ *
+ ******************************************************************************/