summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_mysql.c')
-rw-r--r--plugins/check_mysql.c102
1 files changed, 38 insertions, 64 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 50836f91..a4a2ed1d 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -15,6 +15,8 @@
15******************************************************************************/ 15******************************************************************************/
16 16
17#define PROGNAME "check_mysql" 17#define PROGNAME "check_mysql"
18#define REVISION "$Revision$"
19#define COPYRIGHT "1999-2002"
18 20
19#include "common.h" 21#include "common.h"
20#include "utils.h" 22#include "utils.h"
@@ -22,14 +24,13 @@
22#include <mysql/mysql.h> 24#include <mysql/mysql.h>
23#include <mysql/errmsg.h> 25#include <mysql/errmsg.h>
24 26
25char *db_user = NULL; 27char *db_user = "";
26char *db_host = NULL; 28char *db_host = "";
27char *db_pass = NULL; 29char *db_pass = "";
28char *db = NULL; 30char *db = "";
29unsigned int db_port = MYSQL_PORT; 31unsigned int db_port = MYSQL_PORT;
30 32
31int process_arguments (int, char **); 33int process_arguments (int, char **);
32int call_getopt (int, char **);
33int validate_arguments (void); 34int validate_arguments (void);
34int check_disk (int usp, int free_disk); 35int check_disk (int usp, int free_disk);
35void print_help (void); 36void print_help (void);
@@ -126,48 +127,6 @@ process_arguments (int argc, char **argv)
126{ 127{
127 int c; 128 int c;
128 129
129 if (argc < 1)
130 return ERROR;
131
132 c = 0;
133 while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
134
135 if (is_option (argv[c]))
136 continue;
137
138 if (db_host == NULL)
139 if (is_host (argv[c])) {
140 db_host = argv[c];
141 }
142 else {
143 usage ("Invalid host name");
144 }
145 else if (db_user == NULL)
146 db_user = argv[c];
147 else if (db_pass == NULL)
148 db_pass = argv[c];
149 else if (db == NULL)
150 db = argv[c];
151 else if (is_intnonneg (argv[c]))
152 db_port = atoi (argv[c]);
153 }
154
155 if (db_host == NULL)
156 db_host = strscpy (db_host, "127.0.0.1");
157
158 return validate_arguments ();
159}
160
161
162
163
164
165
166int
167call_getopt (int argc, char **argv)
168{
169 int c, i = 0;
170
171#ifdef HAVE_GETOPT_H 130#ifdef HAVE_GETOPT_H
172 int option_index = 0; 131 int option_index = 0;
173 static struct option long_options[] = { 132 static struct option long_options[] = {
@@ -183,29 +142,21 @@ call_getopt (int argc, char **argv)
183 }; 142 };
184#endif 143#endif
185 144
145 if (argc < 1)
146 return ERROR;
147
186 while (1) { 148 while (1) {
187#ifdef HAVE_GETOPT_H 149#ifdef HAVE_GETOPT_H
188 c = 150 c =
189 getopt_long (argc, argv, "+hVP:p:u:d:H:", long_options, &option_index); 151 getopt_long (argc, argv, "hVP:p:u:d:H:", long_options, &option_index);
190#else 152#else
191 c = getopt (argc, argv, "+?hVP:p:u:d:H:"); 153 c = getopt (argc, argv, "hVP:p:u:d:H:");
192#endif 154#endif
193 155
194 i++; 156 if (c == -1 || c == EOF)
195
196 if (c == -1 || c == EOF || c == 1)
197 break; 157 break;
198 158
199 switch (c) { 159 switch (c) {
200 case 'P':
201 case 'p':
202 case 'u':
203 case 'd':
204 case 'H':
205 i++;
206 }
207
208 switch (c) {
209 case 'H': /* hostname */ 160 case 'H': /* hostname */
210 if (is_host (optarg)) { 161 if (is_host (optarg)) {
211 db_host = optarg; 162 db_host = optarg;
@@ -227,7 +178,7 @@ call_getopt (int argc, char **argv)
227 db_port = atoi (optarg); 178 db_port = atoi (optarg);
228 break; 179 break;
229 case 'V': /* version */ 180 case 'V': /* version */
230 print_revision (my_basename (argv[0]), "$Revision$"); 181 print_revision (PROGNAME, REVISION);
231 exit (STATE_OK); 182 exit (STATE_OK);
232 case 'h': /* help */ 183 case 'h': /* help */
233 print_help (); 184 print_help ();
@@ -236,7 +187,30 @@ call_getopt (int argc, char **argv)
236 usage ("Invalid argument\n"); 187 usage ("Invalid argument\n");
237 } 188 }
238 } 189 }
239 return i; 190
191 c = optind;
192
193 if (strlen(db_host) == 0 && argc > c)
194 if (is_host (argv[c])) {
195 db_host = argv[c++];
196 }
197 else {
198 usage ("Invalid host name");
199 }
200
201 if (strlen(db_user) == 0 && argc > c)
202 db_user = argv[c++];
203
204 if (strlen(db_pass) == 0 && argc > c)
205 db_pass = argv[c++];
206
207 if (strlen(db) == 0 && argc > c)
208 db = argv[c++];
209
210 if (is_intnonneg (argv[c]))
211 db_port = atoi (argv[c++]);
212
213 return validate_arguments ();
240} 214}
241 215
242 216
@@ -256,7 +230,7 @@ validate_arguments (void)
256void 230void
257print_help (void) 231print_help (void)
258{ 232{
259 print_revision (PROGNAME, "$Revision$"); 233 print_revision (PROGNAME, REVISION);
260 printf 234 printf
261 ("Copyright (c) 2000 Didi Rieder/Karl DeBisschop\n\n" 235 ("Copyright (c) 2000 Didi Rieder/Karl DeBisschop\n\n"
262 "This plugin is for testing a mysql server.\n"); 236 "This plugin is for testing a mysql server.\n");