diff options
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | plugins/check_mysql.c | 47 | ||||
-rw-r--r-- | plugins/check_mysql_query.c | 20 | ||||
-rw-r--r-- | plugins/t/check_mysql.t | 22 |
4 files changed, 68 insertions, 23 deletions
@@ -18,6 +18,8 @@ This file documents the major additions and syntax changes between releases. | |||
18 | check_dig can now pass arguments dig by using -A/--dig-arguments (#1874041/#1889453) | 18 | check_dig can now pass arguments dig by using -A/--dig-arguments (#1874041/#1889453) |
19 | check_ntp and check_ntp_peer now show proper jitter/stratum thresholds longopts in --help | 19 | check_ntp and check_ntp_peer now show proper jitter/stratum thresholds longopts in --help |
20 | check_dns now allow to repeat -a to match multiple possibly returned address (common with load balancers) | 20 | check_dns now allow to repeat -a to match multiple possibly returned address (common with load balancers) |
21 | check_mysql now try clearing password in processlist just like check_mysql_query | ||
22 | check_mysql and check_mysql_query now support sockets explicitely (-s, --socket) | ||
21 | 23 | ||
22 | 1.4.11 13th December 2007 | 24 | 1.4.11 13th December 2007 |
23 | Fixed check_http regression in 1.4.10 where following redirects to | 25 | Fixed check_http regression in 1.4.10 where following redirects to |
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index ea2e30d..3d7426d 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c | |||
@@ -50,6 +50,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
50 | 50 | ||
51 | char *db_user = NULL; | 51 | char *db_user = NULL; |
52 | char *db_host = NULL; | 52 | char *db_host = NULL; |
53 | char *db_socket = NULL; | ||
53 | char *db_pass = NULL; | 54 | char *db_pass = NULL; |
54 | char *db = NULL; | 55 | char *db = NULL; |
55 | unsigned int db_port = MYSQL_PORT; | 56 | unsigned int db_port = MYSQL_PORT; |
@@ -90,7 +91,7 @@ main (int argc, char **argv) | |||
90 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); | 91 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); |
91 | 92 | ||
92 | /* establish a connection to the server and error checking */ | 93 | /* establish a connection to the server and error checking */ |
93 | if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,NULL,0)) { | 94 | if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { |
94 | if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) | 95 | if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) |
95 | die (STATE_WARNING, "%s\n", mysql_error (&mysql)); | 96 | die (STATE_WARNING, "%s\n", mysql_error (&mysql)); |
96 | else if (mysql_errno (&mysql) == CR_VERSION_ERROR) | 97 | else if (mysql_errno (&mysql) == CR_VERSION_ERROR) |
@@ -243,6 +244,7 @@ process_arguments (int argc, char **argv) | |||
243 | int option = 0; | 244 | int option = 0; |
244 | static struct option longopts[] = { | 245 | static struct option longopts[] = { |
245 | {"hostname", required_argument, 0, 'H'}, | 246 | {"hostname", required_argument, 0, 'H'}, |
247 | {"socket", required_argument, 0, 's'}, | ||
246 | {"database", required_argument, 0, 'd'}, | 248 | {"database", required_argument, 0, 'd'}, |
247 | {"username", required_argument, 0, 'u'}, | 249 | {"username", required_argument, 0, 'u'}, |
248 | {"password", required_argument, 0, 'p'}, | 250 | {"password", required_argument, 0, 'p'}, |
@@ -260,7 +262,7 @@ process_arguments (int argc, char **argv) | |||
260 | return ERROR; | 262 | return ERROR; |
261 | 263 | ||
262 | while (1) { | 264 | while (1) { |
263 | c = getopt_long (argc, argv, "hvVSP:p:u:d:H:c:w:", longopts, &option); | 265 | c = getopt_long (argc, argv, "hvVSP:p:u:d:H:s:c:w:", longopts, &option); |
264 | 266 | ||
265 | if (c == -1 || c == EOF) | 267 | if (c == -1 || c == EOF) |
266 | break; | 268 | break; |
@@ -274,14 +276,23 @@ process_arguments (int argc, char **argv) | |||
274 | usage2 (_("Invalid hostname/address"), optarg); | 276 | usage2 (_("Invalid hostname/address"), optarg); |
275 | } | 277 | } |
276 | break; | 278 | break; |
277 | case 'd': /* hostname */ | 279 | case 's': /* socket */ |
280 | db_socket = optarg; | ||
281 | break; | ||
282 | case 'd': /* database */ | ||
278 | db = optarg; | 283 | db = optarg; |
279 | break; | 284 | break; |
280 | case 'u': /* username */ | 285 | case 'u': /* username */ |
281 | db_user = optarg; | 286 | db_user = optarg; |
282 | break; | 287 | break; |
283 | case 'p': /* authentication information: password */ | 288 | case 'p': /* authentication information: password */ |
284 | db_pass = optarg; | 289 | db_pass = strdup(optarg); |
290 | |||
291 | /* Delete the password from process list */ | ||
292 | while (*optarg != '\0') { | ||
293 | *optarg = 'X'; | ||
294 | optarg++; | ||
295 | } | ||
285 | break; | 296 | break; |
286 | case 'P': /* critical time threshold */ | 297 | case 'P': /* critical time threshold */ |
287 | db_port = atoi (optarg); | 298 | db_port = atoi (optarg); |
@@ -373,28 +384,33 @@ print_help (void) | |||
373 | 384 | ||
374 | print_usage (); | 385 | print_usage (); |
375 | 386 | ||
376 | printf (_(UT_HELP_VRSN)); | 387 | printf (_(UT_HELP_VRSN)); |
377 | 388 | ||
378 | printf (_(UT_HOST_PORT), 'P', myport); | 389 | printf (_(UT_HOST_PORT), 'P', myport); |
390 | printf (" %s\n", "-s, --socket=STRING"); | ||
391 | printf (" %s\n", _("Use the specified socket (has no effect if -H is used)")); | ||
379 | 392 | ||
380 | printf (" %s\n", "-d, --database=STRING"); | 393 | printf (" %s\n", "-d, --database=STRING"); |
381 | printf (" %s\n", _("Check database with indicated name")); | 394 | printf (" %s\n", _("Check database with indicated name")); |
382 | printf (" %s\n", "-u, --username=STRING"); | 395 | printf (" %s\n", "-u, --username=STRING"); |
383 | printf (" %s\n", _("Connect using the indicated username")); | 396 | printf (" %s\n", _("Connect using the indicated username")); |
384 | printf (" %s\n", "-p, --password=STRING"); | 397 | printf (" %s\n", "-p, --password=STRING"); |
385 | printf (" %s\n", _("Use the indicated password to authenticate the connection")); | 398 | printf (" %s\n", _("Use the indicated password to authenticate the connection")); |
386 | printf (" %s\n", _("==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==")); | 399 | printf (" ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!")); |
387 | printf (" %s\n", _("Your clear-text password will be visible as a process table entry")); | 400 | printf (" %s\n", _("Your clear-text password could be visible as a process table entry")); |
388 | printf (" %s\n", "-S, --check-slave"); | 401 | printf (" %s\n", "-S, --check-slave"); |
389 | printf (" %s\n", _("Check if the slave thread is running properly.")); | 402 | printf (" %s\n", _("Check if the slave thread is running properly.")); |
390 | printf (" %s\n", "-w, --warning"); | 403 | printf (" %s\n", "-w, --warning"); |
391 | printf (" %s\n", _("Exit with WARNING status if slave server is more than INTEGER seconds behind master")); | 404 | printf (" %s\n", _("Exit with WARNING status if slave server is more than INTEGER seconds")); |
405 | printf (" %s\n", _("behind master")); | ||
392 | printf (" %s\n", "-c, --critical"); | 406 | printf (" %s\n", "-c, --critical"); |
393 | printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds behind master")); | 407 | printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); |
408 | printf (" %s\n", _("behind master")); | ||
394 | 409 | ||
395 | printf ("\n"); | 410 | printf ("\n"); |
396 | printf (" %s\n", _("There are no required arguments. By default, the local database with")); | 411 | printf (" %s\n", _("There are no required arguments. By default, the local database is checked")); |
397 | printf (_(" a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT); | 412 | printf (" %s\n", _("using the default unix socket. You can force TCP on localhost by using an")); |
413 | printf (" %s\n", _("IP address or FQDN ('localhost' will use the socket as well).")); | ||
398 | 414 | ||
399 | printf (_(UT_SUPPORT)); | 415 | printf (_(UT_SUPPORT)); |
400 | } | 416 | } |
@@ -404,5 +420,6 @@ void | |||
404 | print_usage (void) | 420 | print_usage (void) |
405 | { | 421 | { |
406 | printf (_("Usage:")); | 422 | printf (_("Usage:")); |
407 | printf ("%s [-d database] [-H host] [-P port] [-u user] [-p password] [-S]\n",progname); | 423 | printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname); |
424 | printf (" [-u user] [-p password] [-S]\n"); | ||
408 | } | 425 | } |
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index 8c6a96c..171fc69 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c | |||
@@ -47,6 +47,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
47 | 47 | ||
48 | char *db_user = NULL; | 48 | char *db_user = NULL; |
49 | char *db_host = NULL; | 49 | char *db_host = NULL; |
50 | char *db_socket = NULL; | ||
50 | char *db_pass = NULL; | 51 | char *db_pass = NULL; |
51 | char *db = NULL; | 52 | char *db = NULL; |
52 | unsigned int db_port = MYSQL_PORT; | 53 | unsigned int db_port = MYSQL_PORT; |
@@ -86,7 +87,7 @@ main (int argc, char **argv) | |||
86 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); | 87 | mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); |
87 | 88 | ||
88 | /* establish a connection to the server and error checking */ | 89 | /* establish a connection to the server and error checking */ |
89 | if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,NULL,0)) { | 90 | if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { |
90 | if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) | 91 | if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) |
91 | die (STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error (&mysql)); | 92 | die (STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error (&mysql)); |
92 | else if (mysql_errno (&mysql) == CR_VERSION_ERROR) | 93 | else if (mysql_errno (&mysql) == CR_VERSION_ERROR) |
@@ -170,6 +171,7 @@ process_arguments (int argc, char **argv) | |||
170 | int option = 0; | 171 | int option = 0; |
171 | static struct option longopts[] = { | 172 | static struct option longopts[] = { |
172 | {"hostname", required_argument, 0, 'H'}, | 173 | {"hostname", required_argument, 0, 'H'}, |
174 | {"socket", required_argument, 0, 's'}, | ||
173 | {"database", required_argument, 0, 'd'}, | 175 | {"database", required_argument, 0, 'd'}, |
174 | {"username", required_argument, 0, 'u'}, | 176 | {"username", required_argument, 0, 'u'}, |
175 | {"password", required_argument, 0, 'p'}, | 177 | {"password", required_argument, 0, 'p'}, |
@@ -187,7 +189,7 @@ process_arguments (int argc, char **argv) | |||
187 | return ERROR; | 189 | return ERROR; |
188 | 190 | ||
189 | while (1) { | 191 | while (1) { |
190 | c = getopt_long (argc, argv, "hvVSP:p:u:d:H:q:w:c:", longopts, &option); | 192 | c = getopt_long (argc, argv, "hvVSP:p:u:d:H:s:q:w:c:", longopts, &option); |
191 | 193 | ||
192 | if (c == -1 || c == EOF) | 194 | if (c == -1 || c == EOF) |
193 | break; | 195 | break; |
@@ -201,14 +203,17 @@ process_arguments (int argc, char **argv) | |||
201 | usage2 (_("Invalid hostname/address"), optarg); | 203 | usage2 (_("Invalid hostname/address"), optarg); |
202 | } | 204 | } |
203 | break; | 205 | break; |
204 | case 'd': /* hostname */ | 206 | case 's': /* socket */ |
207 | db_socket = optarg; | ||
208 | break; | ||
209 | case 'd': /* database */ | ||
205 | db = optarg; | 210 | db = optarg; |
206 | break; | 211 | break; |
207 | case 'u': /* username */ | 212 | case 'u': /* username */ |
208 | db_user = optarg; | 213 | db_user = optarg; |
209 | break; | 214 | break; |
210 | case 'p': /* authentication information: password */ | 215 | case 'p': /* authentication information: password */ |
211 | asprintf(&db_pass, "%s", optarg); | 216 | db_pass = strdup(optarg); |
212 | 217 | ||
213 | /* Delete the password from process list */ | 218 | /* Delete the password from process list */ |
214 | while (*optarg != '\0') { | 219 | while (*optarg != '\0') { |
@@ -293,6 +298,8 @@ print_help (void) | |||
293 | printf (" %s\n", _("SQL query to run. Only first column in first row will be read")); | 298 | printf (" %s\n", _("SQL query to run. Only first column in first row will be read")); |
294 | printf (_(UT_WARN_CRIT_RANGE)); | 299 | printf (_(UT_WARN_CRIT_RANGE)); |
295 | printf (_(UT_HOST_PORT), 'P', myport); | 300 | printf (_(UT_HOST_PORT), 'P', myport); |
301 | printf (" %s\n", "-s, --socket=STRING"); | ||
302 | printf (" %s\n", _("Use the specified socket (has no effect if -H is used)")); | ||
296 | printf (" -d, --database=STRING\n"); | 303 | printf (" -d, --database=STRING\n"); |
297 | printf (" %s\n", _("Database to check")); | 304 | printf (" %s\n", _("Database to check")); |
298 | printf (" -u, --username=STRING\n"); | 305 | printf (" -u, --username=STRING\n"); |
@@ -300,6 +307,7 @@ print_help (void) | |||
300 | printf (" -p, --password=STRING\n"); | 307 | printf (" -p, --password=STRING\n"); |
301 | printf (" %s\n", _("Password to login with")); | 308 | printf (" %s\n", _("Password to login with")); |
302 | printf (" ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!")); | 309 | printf (" ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!")); |
310 | printf (" %s\n", _("Your clear-text password could be visible as a process table entry")); | ||
303 | 311 | ||
304 | printf ("\n"); | 312 | printf ("\n"); |
305 | printf (" %s\n", _("A query is required. The result from the query should be numeric.")); | 313 | printf (" %s\n", _("A query is required. The result from the query should be numeric.")); |
@@ -313,6 +321,6 @@ void | |||
313 | print_usage (void) | 321 | print_usage (void) |
314 | { | 322 | { |
315 | printf (_("Usage:")); | 323 | printf (_("Usage:")); |
316 | printf ("%s -q SQL_query [-w warn] [-c crit]\n",progname); | 324 | printf (" %s -q SQL_query [-w warn] [-c crit] [-H host] [-P port] [-s socket]\n",progname); |
317 | printf ("[-d database] [-H host] [-P port] [-u user] [-p password]\n"); | 325 | printf (" [-d database] [-u user] [-p password]\n"); |
318 | } | 326 | } |
diff --git a/plugins/t/check_mysql.t b/plugins/t/check_mysql.t index 852926a..e8bccf1 100644 --- a/plugins/t/check_mysql.t +++ b/plugins/t/check_mysql.t | |||
@@ -19,12 +19,16 @@ use vars qw($tests); | |||
19 | 19 | ||
20 | plan skip_all => "check_mysql not compiled" unless (-x "check_mysql"); | 20 | plan skip_all => "check_mysql not compiled" unless (-x "check_mysql"); |
21 | 21 | ||
22 | plan tests => 10; | 22 | plan tests => 15; |
23 | 23 | ||
24 | my $bad_login_output = '/Access denied for user /'; | 24 | my $bad_login_output = '/Access denied for user /'; |
25 | my $mysqlserver = getTestParameter( | 25 | my $mysqlserver = getTestParameter( |
26 | "NP_MYSQL_SERVER", | 26 | "NP_MYSQL_SERVER", |
27 | "A MySQL Server with no slaves setup" | 27 | "A MySQL Server hostname or IP with no slaves setup" |
28 | ); | ||
29 | my $mysqlsocket = getTestParameter( | ||
30 | "NP_MYSQL_SOCKET", | ||
31 | "A MySQL Server socket with no slaves setup" | ||
28 | ); | 32 | ); |
29 | my $mysql_login_details = getTestParameter( | 33 | my $mysql_login_details = getTestParameter( |
30 | "MYSQL_LOGIN_DETAILS", | 34 | "MYSQL_LOGIN_DETAILS", |
@@ -58,6 +62,20 @@ SKIP: { | |||
58 | } | 62 | } |
59 | 63 | ||
60 | SKIP: { | 64 | SKIP: { |
65 | skip "No mysql socket defined", 5 unless $mysqlsocket; | ||
66 | $result = NPTest->testCmd("./check_mysql -s $mysqlsocket $mysql_login_details"); | ||
67 | cmp_ok( $result->return_code, '==', 0, "Login okay"); | ||
68 | |||
69 | $result = NPTest->testCmd("./check_mysql -s $mysqlsocket -u dummy -pdummy"); | ||
70 | cmp_ok( $result->return_code, '==', 2, "Login failure"); | ||
71 | like( $result->output, $bad_login_output, "Expected login failure message"); | ||
72 | |||
73 | $result = NPTest->testCmd("./check_mysql -S -s $mysqlsocket $mysql_login_details"); | ||
74 | cmp_ok( $result->return_code, "==", 1, "No slaves defined" ); | ||
75 | like( $result->output, "/No slaves defined/", "Correct error message"); | ||
76 | } | ||
77 | |||
78 | SKIP: { | ||
61 | skip "No mysql server with slaves defined", 5 unless $with_slave; | 79 | skip "No mysql server with slaves defined", 5 unless $with_slave; |
62 | $result = NPTest->testCmd("./check_mysql -H $with_slave $with_slave_login"); | 80 | $result = NPTest->testCmd("./check_mysql -H $with_slave $with_slave_login"); |
63 | cmp_ok( $result->return_code, '==', 0, "Login okay"); | 81 | cmp_ok( $result->return_code, '==', 0, "Login okay"); |