summaryrefslogtreecommitdiffstats
path: root/plugins/check_game.c
diff options
context:
space:
mode:
authorM. Sean Finney <seanius@users.sourceforge.net>2005-10-24 11:10:29 (GMT)
committerM. Sean Finney <seanius@users.sourceforge.net>2005-10-24 11:10:29 (GMT)
commitceebd58040b1688749d58dd76963af639cf8c803 (patch)
tree972deca448413addc597ce7ba3a1a4edefa8c5a5 /plugins/check_game.c
parent19100c883d72e6ebfd3f15b3171ade2a78345c73 (diff)
downloadmonitoring-plugins-ceebd58040b1688749d58dd76963af639cf8c803.tar.gz
initial merging of ae's np_runcmd code into selected plugins.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1260 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_game.c')
-rw-r--r--plugins/check_game.c46
1 files changed, 15 insertions, 31 deletions
diff --git a/plugins/check_game.c b/plugins/check_game.c
index 08b04d6..912072c 100644
--- a/plugins/check_game.c
+++ b/plugins/check_game.c
@@ -23,8 +23,8 @@ const char *copyright = "2002-2004";
23const char *email = "nagiosplug-devel@lists.sourceforge.net"; 23const char *email = "nagiosplug-devel@lists.sourceforge.net";
24 24
25#include "common.h" 25#include "common.h"
26#include "popen.h"
27#include "utils.h" 26#include "utils.h"
27#include "runcmd.h"
28 28
29int process_arguments (int, char **); 29int process_arguments (int, char **);
30int validate_arguments (void); 30int validate_arguments (void);
@@ -57,16 +57,16 @@ main (int argc, char **argv)
57 char *command_line; 57 char *command_line;
58 int result = STATE_UNKNOWN; 58 int result = STATE_UNKNOWN;
59 FILE *fp; 59 FILE *fp;
60 char input_buffer[MAX_INPUT_BUFFER];
61 char *p, *ret[QSTAT_MAX_RETURN_ARGS]; 60 char *p, *ret[QSTAT_MAX_RETURN_ARGS];
62 int i; 61 size_t i = 0;
62 output chld_out;
63 63
64 setlocale (LC_ALL, ""); 64 setlocale (LC_ALL, "");
65 bindtextdomain (PACKAGE, LOCALEDIR); 65 bindtextdomain (PACKAGE, LOCALEDIR);
66 textdomain (PACKAGE); 66 textdomain (PACKAGE);
67 67
68 if (process_arguments (argc, argv) == ERROR) 68 if (process_arguments (argc, argv) == ERROR)
69 usage4 (_("Could not parse arguments")); 69 usage_va(_("Could not parse arguments"));
70 70
71 result = STATE_OK; 71 result = STATE_OK;
72 72
@@ -80,17 +80,9 @@ main (int argc, char **argv)
80 if (verbose > 0) 80 if (verbose > 0)
81 printf ("%s\n", command_line); 81 printf ("%s\n", command_line);
82 82
83 /* run the command */ 83 /* run the command. historically, this plugin ignores output on stderr,
84 fp = spopen (command_line); 84 * as well as return status of the qstat program */
85 if (fp == NULL) { 85 (void)np_runcmd(command_line, &chld_out, NULL, 0);
86 printf (_("Could not open pipe: %s\n"), command_line);
87 return STATE_UNKNOWN;
88 }
89
90 fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp); /* Only interested in the first line */
91
92 /* strip the newline character from the end of the input */
93 input_buffer[strlen (input_buffer) - 1] = 0;
94 86
95 /* sanity check */ 87 /* sanity check */
96 /* was thinking about running qstat without any options, capturing the 88 /* was thinking about running qstat without any options, capturing the
@@ -102,18 +94,13 @@ main (int argc, char **argv)
102 In the end, I figured I'd simply let an error occur & then trap it 94 In the end, I figured I'd simply let an error occur & then trap it
103 */ 95 */
104 96
105 if (!strncmp (input_buffer, "unknown option", 14)) { 97 if (!strncmp (chld_out.line[0], "unknown option", 14)) {
106 printf (_("CRITICAL - Host type parameter incorrect!\n")); 98 printf (_("CRITICAL - Host type parameter incorrect!\n"));
107 result = STATE_CRITICAL; 99 result = STATE_CRITICAL;
108 return result; 100 return result;
109 } 101 }
110 102
111 /* initialize the returned data buffer */ 103 p = (char *) strtok (chld_out.line[0], QSTAT_DATA_DELIMITER);
112 for (i = 0; i < QSTAT_MAX_RETURN_ARGS; i++)
113 ret[i] = strdup("");
114
115 i = 0;
116 p = (char *) strtok (input_buffer, QSTAT_DATA_DELIMITER);
117 while (p != NULL) { 104 while (p != NULL) {
118 ret[i] = p; 105 ret[i] = p;
119 p = (char *) strtok (NULL, QSTAT_DATA_DELIMITER); 106 p = (char *) strtok (NULL, QSTAT_DATA_DELIMITER);
@@ -141,17 +128,14 @@ main (int argc, char **argv)
141 ret[qstat_game_field], 128 ret[qstat_game_field],
142 ret[qstat_map_field], 129 ret[qstat_map_field],
143 ret[qstat_ping_field], 130 ret[qstat_ping_field],
144 perfdata ("players", atol(ret[qstat_game_players]), "", 131 perfdata ("players", atol(ret[qstat_game_players]), "",
145 FALSE, 0, FALSE, 0, 132 FALSE, 0, FALSE, 0,
146 TRUE, 0, TRUE, atol(ret[qstat_game_players_max])), 133 TRUE, 0, TRUE, atol(ret[qstat_game_players_max])),
147 fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "", 134 fperfdata ("ping", strtod(ret[qstat_ping_field], NULL), "",
148 FALSE, 0, FALSE, 0, 135 FALSE, 0, FALSE, 0,
149 TRUE, 0, FALSE, 0)); 136 TRUE, 0, FALSE, 0));
150 } 137 }
151 138
152 /* close the pipe */
153 spclose (fp);
154
155 return result; 139 return result;
156} 140}
157 141
@@ -197,8 +181,6 @@ process_arguments (int argc, char **argv)
197 break; 181 break;
198 182
199 switch (c) { 183 switch (c) {
200 case '?': /* args not parsable */
201 usage2 (_("Unknown argument"), optarg);
202 case 'h': /* help */ 184 case 'h': /* help */
203 print_help (); 185 print_help ();
204 exit (STATE_OK); 186 exit (STATE_OK);
@@ -251,6 +233,8 @@ process_arguments (int argc, char **argv)
251 if (qstat_game_players_max < 0 || qstat_game_players_max > QSTAT_MAX_RETURN_ARGS) 233 if (qstat_game_players_max < 0 || qstat_game_players_max > QSTAT_MAX_RETURN_ARGS)
252 return ERROR; 234 return ERROR;
253 break; 235 break;
236 default: /* args not parsable */
237 usage_va(_("Unknown argument - %s"), optarg);
254 } 238 }
255 } 239 }
256 240
@@ -328,8 +312,8 @@ void
328print_usage (void) 312print_usage (void)
329{ 313{
330 printf ("\ 314 printf ("\
331Usage: %s [-hvV] [-P port] [-t timeout] [-g game_field] [-m map_field]\n\ 315Usage: %s <game> <ip_address> [-p port] [-gf game_field] [-mf map_field]\n\
332 [-p ping_field] [-G game-time] [-H hostname] <game> <ip_address>\n", progname); 316 [-pf ping_field]\n", progname);
333} 317}
334 318
335/****************************************************************************** 319/******************************************************************************