summaryrefslogtreecommitdiffstats
path: root/plugins/check_game.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_game.c')
-rw-r--r--plugins/check_game.c44
1 files changed, 15 insertions, 29 deletions
diff --git a/plugins/check_game.c b/plugins/check_game.c
index 79abec3..f53e7a3 100644
--- a/plugins/check_game.c
+++ b/plugins/check_game.c
@@ -58,8 +58,6 @@ char *server_ip;
58char *game_type; 58char *game_type;
59int port = 0; 59int port = 0;
60 60
61int verbose;
62
63int qstat_game_players_max = -1; 61int qstat_game_players_max = -1;
64int qstat_game_players = -1; 62int qstat_game_players = -1;
65int qstat_game_field = -1; 63int qstat_game_field = -1;
@@ -76,6 +74,7 @@ main (int argc, char **argv)
76 size_t i = 0; 74 size_t i = 0;
77 output chld_out; 75 output chld_out;
78 76
77 np_set_mymanes(argv[0], "GAME");
79 setlocale (LC_ALL, ""); 78 setlocale (LC_ALL, "");
80 bindtextdomain (PACKAGE, LOCALEDIR); 79 bindtextdomain (PACKAGE, LOCALEDIR);
81 textdomain (PACKAGE); 80 textdomain (PACKAGE);
@@ -92,8 +91,7 @@ main (int argc, char **argv)
92 if (port) 91 if (port)
93 asprintf (&command_line, "%s:%-d", command_line, port); 92 asprintf (&command_line, "%s:%-d", command_line, port);
94 93
95 if (verbose > 0) 94 np_verbatim(command_line);
96 printf ("%s\n", command_line);
97 95
98 /* run the command. historically, this plugin ignores output on stderr, 96 /* run the command. historically, this plugin ignores output on stderr,
99 * as well as return status of the qstat program */ 97 * as well as return status of the qstat program */
@@ -109,11 +107,8 @@ main (int argc, char **argv)
109 In the end, I figured I'd simply let an error occur & then trap it 107 In the end, I figured I'd simply let an error occur & then trap it
110 */ 108 */
111 109
112 if (!strncmp (chld_out.line[0], "unknown option", 14)) { 110 if (!strncmp (chld_out.line[0], "unknown option", 14))
113 printf (_("CRITICAL - Host type parameter incorrect!\n")); 111 np_die(STATE_CRITICAL, _("CRITICAL - Host type parameter incorrect!"));
114 result = STATE_CRITICAL;
115 return result;
116 }
117 112
118 p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER); 113 p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER);
119 while (p != NULL) { 114 while (p != NULL) {
@@ -124,20 +119,14 @@ main (int argc, char **argv)
124 break; 119 break;
125 } 120 }
126 121
127 if (strstr (ret[2], QSTAT_HOST_ERROR)) { 122 if (strstr (ret[2], QSTAT_HOST_ERROR))
128 printf (_("CRITICAL - Host not found\n")); 123 np_die(STATE_CRITICAL, _("CRITICAL - Host not found"));
129 result = STATE_CRITICAL; 124 else if (strstr (ret[2], QSTAT_HOST_DOWN))
130 } 125 np_die(STATE_CRITICAL, _("CRITICAL - Game server down or unavailable"));
131 else if (strstr (ret[2], QSTAT_HOST_DOWN)) { 126 else if (strstr (ret[2], QSTAT_HOST_TIMEOUT))
132 printf (_("CRITICAL - Game server down or unavailable\n")); 127 np_die(STATE_CRITICAL, _("CRITICAL - Game server timeout\n"));
133 result = STATE_CRITICAL; 128 else
134 } 129 np_die(STATE_OK, "%s/%s %s (%s), Ping: %s ms|%s %s\n",
135 else if (strstr (ret[2], QSTAT_HOST_TIMEOUT)) {
136 printf (_("CRITICAL - Game server timeout\n"));
137 result = STATE_CRITICAL;
138 }
139 else {
140 printf ("OK: %s/%s %s (%s), Ping: %s ms|%s %s\n",
141 ret[qstat_game_players], 130 ret[qstat_game_players],
142 ret[qstat_game_players_max], 131 ret[qstat_game_players_max],
143 ret[qstat_game_field], 132 ret[qstat_game_field],
@@ -149,9 +138,6 @@ main (int argc, char **argv)
149 fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "", 138 fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "",
150 FALSE, 0, FALSE, 0, 139 FALSE, 0, FALSE, 0,
151 TRUE, 0, FALSE, 0)); 140 TRUE, 0, FALSE, 0));
152 }
153
154 return result;
155} 141}
156 142
157 143
@@ -203,14 +189,14 @@ process_arguments (int argc, char **argv)
203 print_revision (progname, revision); 189 print_revision (progname, revision);
204 exit (STATE_OK); 190 exit (STATE_OK);
205 case 'v': /* version */ 191 case 'v': /* version */
206 verbose = TRUE; 192 np_increase_verbosity(1);
207 break; 193 break;
208 case 't': /* timeout period */ 194 case 't': /* timeout period */
209 timeout_interval = atoi (optarg); 195 timeout_interval = atoi (optarg);
210 break; 196 break;
211 case 'H': /* hostname */ 197 case 'H': /* hostname */
212 if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH) 198 if (strlen (optarg) >= MAX_HOST_ADDRESS_LENGTH)
213 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 199 np_die(STATE_UNKNOWN, _("Input buffer overflow"));
214 server_ip = optarg; 200 server_ip = optarg;
215 break; 201 break;
216 case 'P': /* port */ 202 case 'P': /* port */
@@ -218,7 +204,7 @@ process_arguments (int argc, char **argv)
218 break; 204 break;
219 case 'G': /* hostname */ 205 case 'G': /* hostname */
220 if (strlen (optarg) >= MAX_INPUT_BUFFER) 206 if (strlen (optarg) >= MAX_INPUT_BUFFER)
221 die (STATE_UNKNOWN, _("Input buffer overflow\n")); 207 np_die(STATE_UNKNOWN, _("Input buffer overflow"));
222 game_type = optarg; 208 game_type = optarg;
223 break; 209 break;
224 case 'p': /* index of ping field */ 210 case 'p': /* index of ping field */