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.c1002
1 files changed, 564 insertions, 438 deletions
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 6a7daf11..26730d4c 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -1,444 +1,552 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_mysql plugin 3 * Monitoring check_mysql plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at) 6 * Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)
7* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) 7 * Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net)
8* Copyright (c) 1999-2011 Monitoring Plugins Development Team 8 * Copyright (c) 1999-2024 Monitoring Plugins Development Team
9* 9 *
10* Description: 10 * Description:
11* 11 *
12* This file contains the check_mysql plugin 12 * This file contains the check_mysql plugin
13* 13 *
14* This program tests connections to a mysql server 14 * This program tests connections to a mysql server
15* 15 *
16* 16 *
17* This program is free software: you can redistribute it and/or modify 17 * This program is free software: you can redistribute it and/or modify
18* it under the terms of the GNU General Public License as published by 18 * it under the terms of the GNU General Public License as published by
19* the Free Software Foundation, either version 3 of the License, or 19 * the Free Software Foundation, either version 3 of the License, or
20* (at your option) any later version. 20 * (at your option) any later version.
21* 21 *
22* This program is distributed in the hope that it will be useful, 22 * This program is distributed in the hope that it will be useful,
23* but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25* GNU General Public License for more details. 25 * GNU General Public License for more details.
26* 26 *
27* You should have received a copy of the GNU General Public License 27 * You should have received a copy of the GNU General Public License
28* along with this program. If not, see <http://www.gnu.org/licenses/>. 28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29* 29 *
30* 30 *
31*****************************************************************************/ 31 *****************************************************************************/
32
33const char *progname = "check_mysql";
34const char *copyright = "1999-2011";
35const char *email = "devel@monitoring-plugins.org";
36
37#define SLAVERESULTSIZE 96
38 32
39#include "common.h" 33#include "common.h"
34#include "output.h"
35#include "perfdata.h"
36#include "states.h"
37#include "thresholds.h"
40#include "utils.h" 38#include "utils.h"
41#include "utils_base.h" 39#include "utils_base.h"
42#include "netutils.h" 40#include "netutils.h"
41#include "check_mysql.d/config.h"
43 42
44#include <mysql.h> 43#include <mysql.h>
45#include <mysqld_error.h> 44#include <mysqld_error.h>
46#include <errmsg.h> 45#include <errmsg.h>
47 46
48char *db_user = NULL; 47const char *progname = "check_mysql";
49char *db_host = NULL; 48const char *copyright = "1999-2024";
50char *db_socket = NULL; 49const char *email = "devel@monitoring-plugins.org";
51char *db_pass = NULL; 50
52char *db = NULL; 51static int verbose = 0;
53char *ca_cert = NULL; 52
54char *ca_dir = NULL; 53#define REPLICA_RESULTSIZE 96
55char *cert = NULL;
56char *key = NULL;
57char *ciphers = NULL;
58bool ssl = false;
59char *opt_file = NULL;
60char *opt_group = NULL;
61unsigned int db_port = MYSQL_PORT;
62int check_slave = 0, warn_sec = 0, crit_sec = 0;
63int ignore_auth = 0;
64int verbose = 0;
65
66static double warning_time = 0;
67static double critical_time = 0;
68 54
69#define LENGTH_METRIC_UNIT 6 55#define LENGTH_METRIC_UNIT 6
70static const char *metric_unit[LENGTH_METRIC_UNIT] = { 56static const char *metric_unit[LENGTH_METRIC_UNIT] = {
71 "Open_files", 57 "Open_files", "Open_tables", "Qcache_free_memory", "Qcache_queries_in_cache",
72 "Open_tables", 58 "Threads_connected", "Threads_running"};
73 "Qcache_free_memory",
74 "Qcache_queries_in_cache",
75 "Threads_connected",
76 "Threads_running"
77};
78 59
79#define LENGTH_METRIC_COUNTER 9 60#define LENGTH_METRIC_COUNTER 9
80static const char *metric_counter[LENGTH_METRIC_COUNTER] = { 61static const char *metric_counter[LENGTH_METRIC_COUNTER] = {"Connections",
81 "Connections", 62 "Qcache_hits",
82 "Qcache_hits", 63 "Qcache_inserts",
83 "Qcache_inserts", 64 "Qcache_lowmem_prunes",
84 "Qcache_lowmem_prunes", 65 "Qcache_not_cached",
85 "Qcache_not_cached", 66 "Queries",
86 "Queries", 67 "Questions",
87 "Questions", 68 "Table_locks_waited",
88 "Table_locks_waited", 69 "Uptime"};
89 "Uptime" 70
90}; 71#define MYSQLDUMP_THREADS_QUERY \
91 72 "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE " \
92#define MYSQLDUMP_THREADS_QUERY "SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'" 73 "'SELECT /*!40001 SQL_NO_CACHE */%'"
93 74
94thresholds *my_threshold = NULL; 75typedef struct {
95 76 int errorcode;
96int process_arguments (int, char **); 77 check_mysql_config config;
97int validate_arguments (void); 78} check_mysql_config_wrapper;
98void print_help (void); 79static check_mysql_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
99void print_usage (void); 80static check_mysql_config_wrapper validate_arguments(check_mysql_config_wrapper /*config_wrapper*/);
100 81static void print_help(void);
101int 82void print_usage(void);
102main (int argc, char **argv) 83
103{ 84int main(int argc, char **argv) {
85 setlocale(LC_ALL, "");
86 bindtextdomain(PACKAGE, LOCALEDIR);
87 textdomain(PACKAGE);
104 88
105 MYSQL mysql; 89 /* Parse extra opts if any */
106 MYSQL_RES *res; 90 argv = np_extra_opts(&argc, argv, progname);
107 MYSQL_ROW row;
108 91
109 /* should be status */ 92 check_mysql_config_wrapper tmp_config = process_arguments(argc, argv);
93 if (tmp_config.errorcode == ERROR) {
94 usage4(_("Could not parse arguments"));
95 }
110 96
111 char *result = NULL; 97 const check_mysql_config config = tmp_config.config;
112 char *error = NULL;
113 char slaveresult[SLAVERESULTSIZE] = { 0 };
114 char* perf;
115 98
116 perf = strdup (""); 99 if (config.output_format_is_set) {
100 mp_set_format(config.output_format);
101 }
117 102
118 setlocale (LC_ALL, ""); 103 MYSQL mysql;
119 bindtextdomain (PACKAGE, LOCALEDIR); 104 /* initialize mysql */
120 textdomain (PACKAGE); 105 mysql_init(&mysql);
121 106
122 /* Parse extra opts if any */ 107 if (config.opt_file != NULL) {
123 argv=np_extra_opts (&argc, argv, progname); 108 mysql_options(&mysql, MYSQL_READ_DEFAULT_FILE, config.opt_file);
109 }
124 110
125 if (process_arguments (argc, argv) == ERROR) 111 if (config.opt_group != NULL) {
126 usage4 (_("Could not parse arguments")); 112 mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, config.opt_group);
113 } else {
114 mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "client");
115 }
127 116
128 /* initialize mysql */ 117 if (config.ssl) {
129 mysql_init (&mysql); 118 mysql_ssl_set(&mysql, config.key, config.cert, config.ca_cert, config.ca_dir,
130 119 config.ciphers);
131 if (opt_file != NULL) 120 }
132 mysql_options(&mysql,MYSQL_READ_DEFAULT_FILE,opt_file); 121
133 122 mp_check overall = mp_check_init();
134 if (opt_group != NULL) 123
135 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,opt_group); 124 mp_subcheck sc_connection = mp_subcheck_init();
136 else 125 /* establish a connection to the server and check for errors */
137 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); 126 if (!mysql_real_connect(&mysql, config.db_host, config.db_user, config.db_pass, config.db,
138 127 config.db_port, config.db_socket, 0)) {
139 if (ssl)
140 mysql_ssl_set(&mysql,key,cert,ca_cert,ca_dir,ciphers);
141 /* establish a connection to the server and error checking */
142 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
143 /* Depending on internally-selected auth plugin MySQL might return */ 128 /* Depending on internally-selected auth plugin MySQL might return */
144 /* ER_ACCESS_DENIED_NO_PASSWORD_ERROR or ER_ACCESS_DENIED_ERROR. */ 129 /* ER_ACCESS_DENIED_NO_PASSWORD_ERROR or ER_ACCESS_DENIED_ERROR. */
145 /* Semantically these errors are the same. */ 130 /* Semantically these errors are the same. */
146 if (ignore_auth && (mysql_errno (&mysql) == ER_ACCESS_DENIED_ERROR || mysql_errno (&mysql) == ER_ACCESS_DENIED_NO_PASSWORD_ERROR)) 131 if (config.ignore_auth && (mysql_errno(&mysql) == ER_ACCESS_DENIED_ERROR ||
147 { 132 mysql_errno(&mysql) == ER_ACCESS_DENIED_NO_PASSWORD_ERROR)) {
148 printf("MySQL OK - Version: %s (protocol %d)\n", 133 xasprintf(&sc_connection.output, "Version: %s (protocol %d)",
149 mysql_get_server_info(&mysql), 134 mysql_get_server_info(&mysql), mysql_get_proto_info(&mysql));
150 mysql_get_proto_info(&mysql) 135 sc_connection = mp_set_subcheck_state(sc_connection, STATE_OK);
151 ); 136
152 mysql_close (&mysql); 137 mysql_close(&mysql);
153 return STATE_OK; 138 } else {
139 if (mysql_errno(&mysql) == CR_UNKNOWN_HOST) {
140 sc_connection = mp_set_subcheck_state(sc_connection, STATE_WARNING);
141 xasprintf(&sc_connection.output, "%s", mysql_error(&mysql));
142 } else if (mysql_errno(&mysql) == CR_VERSION_ERROR) {
143 sc_connection = mp_set_subcheck_state(sc_connection, STATE_WARNING);
144 xasprintf(&sc_connection.output, "%s", mysql_error(&mysql));
145 } else if (mysql_errno(&mysql) == CR_OUT_OF_MEMORY) {
146 sc_connection = mp_set_subcheck_state(sc_connection, STATE_WARNING);
147 xasprintf(&sc_connection.output, "%s", mysql_error(&mysql));
148 } else if (mysql_errno(&mysql) == CR_IPSOCK_ERROR) {
149 sc_connection = mp_set_subcheck_state(sc_connection, STATE_WARNING);
150 xasprintf(&sc_connection.output, "%s", mysql_error(&mysql));
151 } else if (mysql_errno(&mysql) == CR_SOCKET_CREATE_ERROR) {
152 sc_connection = mp_set_subcheck_state(sc_connection, STATE_WARNING);
153 xasprintf(&sc_connection.output, "%s", mysql_error(&mysql));
154 } else {
155 sc_connection = mp_set_subcheck_state(sc_connection, STATE_CRITICAL);
156 xasprintf(&sc_connection.output, "%s", mysql_error(&mysql));
157 }
154 } 158 }
155 else if (mysql_errno (&mysql) == CR_UNKNOWN_HOST) 159
156 die (STATE_WARNING, "%s\n", mysql_error (&mysql)); 160 mp_add_subcheck_to_check(&overall, sc_connection);
157 else if (mysql_errno (&mysql) == CR_VERSION_ERROR) 161 mp_exit(overall);
158 die (STATE_WARNING, "%s\n", mysql_error (&mysql)); 162 } else {
159 else if (mysql_errno (&mysql) == CR_OUT_OF_MEMORY) 163 // successful connection
160 die (STATE_WARNING, "%s\n", mysql_error (&mysql)); 164 sc_connection = mp_set_subcheck_state(sc_connection, STATE_OK);
161 else if (mysql_errno (&mysql) == CR_IPSOCK_ERROR) 165 xasprintf(&sc_connection.output, "Version: %s (protocol %d)", mysql_get_server_info(&mysql),
162 die (STATE_WARNING, "%s\n", mysql_error (&mysql)); 166 mysql_get_proto_info(&mysql));
163 else if (mysql_errno (&mysql) == CR_SOCKET_CREATE_ERROR) 167 mp_add_subcheck_to_check(&overall, sc_connection);
164 die (STATE_WARNING, "%s\n", mysql_error (&mysql));
165 else
166 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql));
167 } 168 }
168 169
169 /* get the server stats */ 170 /* get the server stats */
170 result = strdup (mysql_stat (&mysql)); 171 char *mysql_stats = strdup(mysql_stat(&mysql));
172
173 mp_subcheck sc_stats = mp_subcheck_init();
174 sc_stats = mp_set_subcheck_default_state(sc_stats, STATE_OK);
171 175
172 /* error checking once more */ 176 /* error checking once more */
173 if (mysql_error (&mysql)) { 177 if (mysql_errno(&mysql) != 0) {
174 if (mysql_errno (&mysql) == CR_SERVER_GONE_ERROR) 178 if ((mysql_errno(&mysql) == CR_SERVER_GONE_ERROR) ||
175 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); 179 (mysql_errno(&mysql) == CR_SERVER_LOST) || (mysql_errno(&mysql) == CR_UNKNOWN_ERROR)) {
176 else if (mysql_errno (&mysql) == CR_SERVER_LOST) 180 sc_stats = mp_set_subcheck_state(sc_stats, STATE_CRITICAL);
177 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); 181 xasprintf(&sc_stats.output, "Retrieving stats failed: %s", mysql_error(&mysql));
178 else if (mysql_errno (&mysql) == CR_UNKNOWN_ERROR) 182 } else {
179 die (STATE_CRITICAL, "%s\n", mysql_error (&mysql)); 183 // not sure which error modes occur here, but mysql_error indicates an error
184 sc_stats = mp_set_subcheck_state(sc_stats, STATE_WARNING);
185 xasprintf(&sc_stats.output, "retrieving stats caused an error: %s",
186 mysql_error(&mysql));
187 }
188
189 mp_add_subcheck_to_check(&overall, sc_stats);
190 mp_exit(overall);
191 } else {
192 xasprintf(&sc_stats.output, "retrieved stats: %s", mysql_stats);
193 sc_stats = mp_set_subcheck_state(sc_stats, STATE_OK);
194 mp_add_subcheck_to_check(&overall, sc_stats);
180 } 195 }
181 196
197 MYSQL_RES *res;
198 MYSQL_ROW row;
199 mp_subcheck sc_query = mp_subcheck_init();
182 /* try to fetch some perf data */ 200 /* try to fetch some perf data */
183 if (mysql_query (&mysql, "show global status") == 0) { 201 if (mysql_query(&mysql, "show global status") == 0) {
184 if ( (res = mysql_store_result (&mysql)) == NULL) { 202 if ((res = mysql_store_result(&mysql)) == NULL) {
185 error = strdup(mysql_error(&mysql)); 203 xasprintf(&sc_connection.output, "query failed - status store_result error: %s",
186 mysql_close (&mysql); 204 mysql_error(&mysql));
187 die (STATE_CRITICAL, _("status store_result error: %s\n"), error); 205 mysql_close(&mysql);
188 }
189 206
190 while ( (row = mysql_fetch_row (res)) != NULL) { 207 sc_query = mp_set_subcheck_state(sc_query, STATE_CRITICAL);
191 int i; 208 mp_add_subcheck_to_check(&overall, sc_query);
209 mp_exit(overall);
210 }
192 211
193 for(i = 0; i < LENGTH_METRIC_UNIT; i++) { 212 while ((row = mysql_fetch_row(res)) != NULL) {
213 for (int i = 0; i < LENGTH_METRIC_UNIT; i++) {
194 if (strcmp(row[0], metric_unit[i]) == 0) { 214 if (strcmp(row[0], metric_unit[i]) == 0) {
195 xasprintf(&perf, "%s%s ", perf, perfdata(metric_unit[i], 215 mp_perfdata pd_mysql_stat = perfdata_init();
196 atol(row[1]), "", false, 0, false, 0, false, 0, false, 0)); 216 pd_mysql_stat.label = (char *)metric_unit[i];
217 pd_mysql_stat.value = mp_create_pd_value(atol(row[1]));
218 mp_add_perfdata_to_subcheck(&sc_stats, pd_mysql_stat);
197 continue; 219 continue;
198 } 220 }
199 } 221 }
200 for(i = 0; i < LENGTH_METRIC_COUNTER; i++) { 222
223 for (int i = 0; i < LENGTH_METRIC_COUNTER; i++) {
201 if (strcmp(row[0], metric_counter[i]) == 0) { 224 if (strcmp(row[0], metric_counter[i]) == 0) {
202 xasprintf(&perf, "%s%s ", perf, perfdata(metric_counter[i], 225 mp_perfdata pd_mysql_stat = perfdata_init();
203 atol(row[1]), "c", false, 0, false, 0, false, 0, false, 0)); 226 pd_mysql_stat.label = (char *)metric_counter[i];
227 pd_mysql_stat.value = mp_create_pd_value(atol(row[1]));
228 pd_mysql_stat.uom = "c";
229 mp_add_perfdata_to_subcheck(&sc_stats, pd_mysql_stat);
204 continue; 230 continue;
205 } 231 }
206 } 232 }
207 } 233 }
208 /* remove trailing space */ 234 } else {
209 if (strlen(perf) > 0) 235 // Query failed!
210 perf[strlen(perf) - 1] = '\0'; 236 xasprintf(&sc_connection.output, "query failed");
237 sc_query = mp_set_subcheck_state(sc_query, STATE_CRITICAL);
238 mp_add_subcheck_to_check(&overall, sc_query);
239 mp_exit(overall);
211 } 240 }
212 241
213 if(check_slave) { 242 if (config.check_replica) {
214 /* check the slave status */ 243 // Detect which version we are, on older version
215 if (mysql_query (&mysql, "show slave status") != 0) { 244 // "show slave status" should work, on newer ones
216 error = strdup(mysql_error(&mysql)); 245 // "show replica status"
217 mysql_close (&mysql); 246 // But first we have to find out whether this is
218 die (STATE_CRITICAL, _("slave query error: %s\n"), error); 247 // MySQL or MariaDB since the version numbering scheme
248 // is different
249 bool use_deprecated_slave_status = false;
250 const char *server_version = mysql_get_server_info(&mysql);
251 unsigned long server_verion_int = mysql_get_server_version(&mysql);
252 unsigned long major_version = server_verion_int / 10000;
253 unsigned long minor_version = (server_verion_int % 10000) / 100;
254 unsigned long patch_version = (server_verion_int % 100);
255
256 if (verbose) {
257 printf("Found MariaDB/MySQL: %s, main version: %lu, minor version: %lu, patch version: "
258 "%lu\n",
259 server_version, major_version, minor_version, patch_version);
260 }
261
262 if (strstr(server_version, "MariaDB") != NULL) {
263 // Looks like MariaDB, new commands should be available after 10.5.1
264 if (major_version < 10) {
265 use_deprecated_slave_status = true;
266 } else if (major_version == 10) {
267 if (minor_version < 5) {
268 use_deprecated_slave_status = true;
269 } else if (minor_version == 5 && patch_version < 1) {
270 use_deprecated_slave_status = true;
271 }
272 }
273 } else {
274 // Looks like MySQL or at least not like MariaDB
275 if (major_version < 8) {
276 use_deprecated_slave_status = true;
277 } else if (major_version == 10 && minor_version < 4) {
278 use_deprecated_slave_status = true;
279 }
280 }
281
282 char *replica_query = NULL;
283 if (use_deprecated_slave_status) {
284 replica_query = "show slave status";
285 } else {
286 replica_query = "show replica status";
287 }
288
289 mp_subcheck sc_replica = mp_subcheck_init();
290
291 /* check the replica status */
292 if (mysql_query(&mysql, replica_query) != 0) {
293 xasprintf(&sc_replica.output, "replica query error: %s", mysql_error(&mysql));
294 mysql_close(&mysql);
295
296 sc_replica = mp_set_subcheck_state(sc_replica, STATE_CRITICAL);
297 mp_add_subcheck_to_check(&overall, sc_replica);
298 mp_exit(overall);
219 } 299 }
220 300
221 /* store the result */ 301 /* store the result */
222 if ( (res = mysql_store_result (&mysql)) == NULL) { 302 if ((res = mysql_store_result(&mysql)) == NULL) {
223 error = strdup(mysql_error(&mysql)); 303 xasprintf(&sc_replica.output, "replica store_result error: %s", mysql_error(&mysql));
224 mysql_close (&mysql); 304 mysql_close(&mysql);
225 die (STATE_CRITICAL, _("slave store_result error: %s\n"), error); 305
306 sc_replica = mp_set_subcheck_state(sc_replica, STATE_CRITICAL);
307 mp_add_subcheck_to_check(&overall, sc_replica);
308 mp_exit(overall);
226 } 309 }
227 310
228 /* Check there is some data */ 311 /* Check there is some data */
229 if (mysql_num_rows(res) == 0) { 312 if (mysql_num_rows(res) == 0) {
230 mysql_close(&mysql); 313 mysql_close(&mysql);
231 die (STATE_WARNING, "%s\n", _("No slaves defined")); 314
315 xasprintf(&sc_replica.output, "no replicas defined");
316 sc_replica = mp_set_subcheck_state(sc_replica, STATE_WARNING);
317 mp_add_subcheck_to_check(&overall, sc_replica);
318 mp_exit(overall);
232 } 319 }
233 320
234 /* fetch the first row */ 321 /* fetch the first row */
235 if ( (row = mysql_fetch_row (res)) == NULL) { 322 if ((row = mysql_fetch_row(res)) == NULL) {
236 error = strdup(mysql_error(&mysql)); 323 xasprintf(&sc_replica.output, "replica fetch row error: %s", mysql_error(&mysql));
237 mysql_free_result (res); 324 mysql_free_result(res);
238 mysql_close (&mysql); 325 mysql_close(&mysql);
239 die (STATE_CRITICAL, _("slave fetch row error: %s\n"), error); 326
327 sc_replica = mp_set_subcheck_state(sc_replica, STATE_CRITICAL);
328 mp_add_subcheck_to_check(&overall, sc_replica);
329 mp_exit(overall);
240 } 330 }
241 331
242 if (mysql_field_count (&mysql) == 12) { 332 if (mysql_field_count(&mysql) == 12) {
243 /* mysql 3.23.x */ 333 /* mysql 3.23.x */
244 snprintf (slaveresult, SLAVERESULTSIZE, _("Slave running: %s"), row[6]); 334 xasprintf(&sc_replica.output, "Replica running: %s", row[6]);
245 if (strcmp (row[6], "Yes") != 0) { 335 if (strcmp(row[6], "Yes") != 0) {
246 mysql_free_result (res); 336 mysql_free_result(res);
247 mysql_close (&mysql); 337 mysql_close(&mysql);
248 die (STATE_CRITICAL, "%s\n", slaveresult); 338
339 sc_replica = mp_set_subcheck_state(sc_replica, STATE_CRITICAL);
340 mp_add_subcheck_to_check(&overall, sc_replica);
341 mp_exit(overall);
249 } 342 }
250
251 } else { 343 } else {
252 /* mysql 4.x.x and mysql 5.x.x */ 344 /* mysql 4.x.x and mysql 5.x.x */
253 int slave_io_field = -1 , slave_sql_field = -1, seconds_behind_field = -1, i, num_fields; 345 int replica_io_field = -1;
254 MYSQL_FIELD* fields; 346 int replica_sql_field = -1;
255 347 int seconds_behind_field = -1;
256 num_fields = mysql_num_fields(res); 348 unsigned int num_fields = mysql_num_fields(res);
257 fields = mysql_fetch_fields(res); 349 MYSQL_FIELD *fields = mysql_fetch_fields(res);
258 for(i = 0; i < num_fields; i++) { 350 for (int i = 0; i < (int)num_fields; i++) {
259 if (strcmp(fields[i].name, "Slave_IO_Running") == 0) { 351 if ((strcasecmp(fields[i].name, "Slave_IO_Running") == 0) ||
260 slave_io_field = i; 352 (strcasecmp(fields[i].name, "Replica_IO_Running") == 0)) {
353 replica_io_field = i;
261 continue; 354 continue;
262 } 355 }
263 if (strcmp(fields[i].name, "Slave_SQL_Running") == 0) { 356 if ((strcasecmp(fields[i].name, "Slave_SQL_Running") == 0) ||
264 slave_sql_field = i; 357 (strcasecmp(fields[i].name, "Replica_SQL_Running") == 0)) {
358 replica_sql_field = i;
265 continue; 359 continue;
266 } 360 }
267 if (strcmp(fields[i].name, "Seconds_Behind_Master") == 0) { 361 if ((strcasecmp(fields[i].name, "Seconds_Behind_Master") == 0) ||
362 (strcasecmp(fields[i].name, "Seconds_Behind_Source") == 0)) {
268 seconds_behind_field = i; 363 seconds_behind_field = i;
269 continue; 364 continue;
270 } 365 }
271 } 366 }
272 367
273 /* Check if slave status is available */ 368 /* Check if replica status is available */
274 if ((slave_io_field < 0) || (slave_sql_field < 0) || (num_fields == 0)) { 369 if ((replica_io_field < 0) || (replica_sql_field < 0) || (num_fields == 0)) {
275 mysql_free_result (res); 370 mysql_free_result(res);
276 mysql_close (&mysql); 371 mysql_close(&mysql);
277 die (STATE_CRITICAL, "Slave status unavailable\n"); 372
373 xasprintf(&sc_replica.output, "Replica status unavailable");
374 sc_replica = mp_set_subcheck_state(sc_replica, STATE_CRITICAL);
375 mp_add_subcheck_to_check(&overall, sc_replica);
376 mp_exit(overall);
278 } 377 }
279 378
280 /* Save slave status in slaveresult */ 379 /* Save replica status in replica_result */
281 snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s Seconds Behind Master: %s", row[slave_io_field], row[slave_sql_field], seconds_behind_field!=-1?row[seconds_behind_field]:"Unknown"); 380 xasprintf(&sc_replica.output,
381 "Replica IO: %s Replica SQL: %s Seconds Behind Master: %s",
382 row[replica_io_field], row[replica_sql_field],
383 seconds_behind_field != -1 ? row[seconds_behind_field] : "Unknown");
282 384
283 /* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no mysqldump threads running */ 385 /* Raise critical error if SQL THREAD or IO THREAD are stopped, but only if there are no
284 if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) { 386 * mysqldump threads running */
387 if (strcmp(row[replica_io_field], "Yes") != 0 ||
388 strcmp(row[replica_sql_field], "Yes") != 0) {
285 MYSQL_RES *res_mysqldump; 389 MYSQL_RES *res_mysqldump;
286 MYSQL_ROW row_mysqldump; 390 MYSQL_ROW row_mysqldump;
287 unsigned int mysqldump_threads = 0; 391 unsigned int mysqldump_threads = 0;
288 392
289 if (mysql_query (&mysql, MYSQLDUMP_THREADS_QUERY) == 0) { 393 if (mysql_query(&mysql, MYSQLDUMP_THREADS_QUERY) == 0) {
290 /* store the result */ 394 /* store the result */
291 if ( (res_mysqldump = mysql_store_result (&mysql)) != NULL) { 395 if ((res_mysqldump = mysql_store_result(&mysql)) != NULL) {
292 if (mysql_num_rows(res_mysqldump) == 1) { 396 if (mysql_num_rows(res_mysqldump) == 1) {
293 if ( (row_mysqldump = mysql_fetch_row (res_mysqldump)) != NULL) { 397 if ((row_mysqldump = mysql_fetch_row(res_mysqldump)) != NULL) {
294 mysqldump_threads = atoi(row_mysqldump[0]); 398 mysqldump_threads = atoi(row_mysqldump[0]);
295 } 399 }
296 } 400 }
297 /* free the result */ 401 /* free the result */
298 mysql_free_result (res_mysqldump); 402 mysql_free_result(res_mysqldump);
299 } 403 }
300 mysql_close (&mysql); 404 mysql_close(&mysql);
301 } 405 }
406
302 if (mysqldump_threads == 0) { 407 if (mysqldump_threads == 0) {
303 die (STATE_CRITICAL, "%s\n", slaveresult); 408 sc_replica = mp_set_subcheck_state(sc_replica, STATE_CRITICAL);
409 mp_add_subcheck_to_check(&overall, sc_replica);
410 mp_exit(overall);
304 } else { 411 } else {
305 strncat(slaveresult, " Mysqldump: in progress", SLAVERESULTSIZE-1); 412 xasprintf(&sc_replica.output, "%s %s", sc_replica.output,
413 " Mysqldump: in progress");
306 } 414 }
307 } 415 }
308 416
309 if (verbose >=3) { 417 if (verbose >= 3) {
310 if (seconds_behind_field == -1) { 418 if (seconds_behind_field == -1) {
311 printf("seconds_behind_field not found\n"); 419 printf("seconds_behind_field not found\n");
312 } else { 420 } else {
313 printf ("seconds_behind_field(index %d)=%s\n", seconds_behind_field, row[seconds_behind_field]); 421 printf("seconds_behind_field(index %d)=%s\n", seconds_behind_field,
422 row[seconds_behind_field]);
314 } 423 }
315 } 424 }
316 425
317 /* Check Seconds Behind against threshold */ 426 /* Check Seconds Behind against threshold */
318 if ((seconds_behind_field != -1) && (row[seconds_behind_field] != NULL && strcmp (row[seconds_behind_field], "NULL") != 0)) { 427 if ((seconds_behind_field != -1) && (row[seconds_behind_field] != NULL &&
319 double value = atof(row[seconds_behind_field]); 428 strcmp(row[seconds_behind_field], "NULL") != 0)) {
320 int status; 429 mp_perfdata pd_seconds_behind = perfdata_init();
321 430 pd_seconds_behind.label = "seconds behind master";
322 status = get_status(value, my_threshold); 431 pd_seconds_behind.value = mp_create_pd_value(atof(row[seconds_behind_field]));
323 432 pd_seconds_behind =
324 xasprintf (&perf, "%s %s", perf, fperfdata ("seconds behind master", value, "s", 433 mp_pd_set_thresholds(pd_seconds_behind, config.replica_thresholds);
325 true, (double) warning_time, 434 pd_seconds_behind.uom = "s";
326 true, (double) critical_time, 435 mp_add_perfdata_to_subcheck(&sc_replica, pd_seconds_behind);
327 false, 0, 436
328 false, 0)); 437 mp_state_enum status = mp_get_pd_status(pd_seconds_behind);
329 438
330 if (status == STATE_WARNING) { 439 sc_replica = mp_set_subcheck_state(sc_replica, status);
331 printf("SLOW_SLAVE %s: %s|%s\n", _("WARNING"), slaveresult, perf); 440
332 exit(STATE_WARNING); 441 if (status != STATE_OK) {
333 } else if (status == STATE_CRITICAL) { 442 xasprintf(&sc_replica.output, "slow replica - %s", sc_replica.output);
334 printf("SLOW_SLAVE %s: %s|%s\n", _("CRITICAL"), slaveresult, perf); 443 mp_add_subcheck_to_check(&overall, sc_replica);
335 exit(STATE_CRITICAL); 444 mp_exit(overall);
336 } 445 }
337 } 446 }
338 } 447 }
339 448
340 /* free the result */ 449 /* free the result */
341 mysql_free_result (res); 450 mysql_free_result(res);
342 } 451 }
343 452
344 /* close the connection */ 453 /* close the connection */
345 mysql_close (&mysql); 454 mysql_close(&mysql);
346
347 /* print out the result of stats */
348 if (check_slave) {
349 printf ("%s %s|%s\n", result, slaveresult, perf);
350 } else {
351 printf ("%s|%s\n", result, perf);
352 }
353 455
354 return STATE_OK; 456 mp_exit(overall);
355} 457}
356 458
357
358/* process command-line arguments */ 459/* process command-line arguments */
359int 460check_mysql_config_wrapper process_arguments(int argc, char **argv) {
360process_arguments (int argc, char **argv)
361{
362 int c;
363 char *warning = NULL;
364 char *critical = NULL;
365 461
366 int option = 0; 462 enum {
367 static struct option longopts[] = { 463 CHECK_REPLICA_OPT = CHAR_MAX + 1,
368 {"hostname", required_argument, 0, 'H'}, 464 output_format_index,
369 {"socket", required_argument, 0, 's'},
370 {"database", required_argument, 0, 'd'},
371 {"username", required_argument, 0, 'u'},
372 {"password", required_argument, 0, 'p'},
373 {"file", required_argument, 0, 'f'},
374 {"group", required_argument, 0, 'g'},
375 {"port", required_argument, 0, 'P'},
376 {"critical", required_argument, 0, 'c'},
377 {"warning", required_argument, 0, 'w'},
378 {"check-slave", no_argument, 0, 'S'},
379 {"ignore-auth", no_argument, 0, 'n'},
380 {"verbose", no_argument, 0, 'v'},
381 {"version", no_argument, 0, 'V'},
382 {"help", no_argument, 0, 'h'},
383 {"ssl", no_argument, 0, 'l'},
384 {"ca-cert", optional_argument, 0, 'C'},
385 {"key", required_argument,0,'k'},
386 {"cert", required_argument,0,'a'},
387 {"ca-dir", required_argument, 0, 'D'},
388 {"ciphers", required_argument, 0, 'L'},
389 {0, 0, 0, 0}
390 }; 465 };
391 466
392 if (argc < 1) 467 static struct option longopts[] = {{"hostname", required_argument, 0, 'H'},
393 return ERROR; 468 {"socket", required_argument, 0, 's'},
469 {"database", required_argument, 0, 'd'},
470 {"username", required_argument, 0, 'u'},
471 {"password", required_argument, 0, 'p'},
472 {"file", required_argument, 0, 'f'},
473 {"group", required_argument, 0, 'g'},
474 {"port", required_argument, 0, 'P'},
475 {"critical", required_argument, 0, 'c'},
476 {"warning", required_argument, 0, 'w'},
477 {"check-slave", no_argument, 0, 'S'},
478 {"check-replica", no_argument, 0, CHECK_REPLICA_OPT},
479 {"ignore-auth", no_argument, 0, 'n'},
480 {"verbose", no_argument, 0, 'v'},
481 {"version", no_argument, 0, 'V'},
482 {"help", no_argument, 0, 'h'},
483 {"ssl", no_argument, 0, 'l'},
484 {"ca-cert", optional_argument, 0, 'C'},
485 {"key", required_argument, 0, 'k'},
486 {"cert", required_argument, 0, 'a'},
487 {"ca-dir", required_argument, 0, 'D'},
488 {"ciphers", required_argument, 0, 'L'},
489 {"output-format", required_argument, 0, output_format_index},
490 {0, 0, 0, 0}};
491
492 check_mysql_config_wrapper result = {
493 .errorcode = OK,
494 .config = check_mysql_config_init(),
495 };
394 496
395 while (1) { 497 if (argc < 1) {
396 c = getopt_long (argc, argv, "hlvVnSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option); 498 result.errorcode = ERROR;
499 return result;
500 }
397 501
398 if (c == -1 || c == EOF) 502 int option = 0;
503 while (true) {
504 int option_index =
505 getopt_long(argc, argv, "hlvVnSP:p:u:d:H:s:c:w:a:k:C:D:L:f:g:", longopts, &option);
506
507 if (option_index == -1 || option_index == EOF) {
399 break; 508 break;
509 }
400 510
401 switch (c) { 511 switch (option_index) {
402 case 'H': /* hostname */ 512 case 'H': /* hostname */
403 if (is_host (optarg)) { 513 if (is_host(optarg)) {
404 db_host = optarg; 514 result.config.db_host = optarg;
405 } 515 } else if (*optarg == '/') {
406 else if (*optarg == '/') { 516 result.config.db_socket = optarg;
407 db_socket = optarg; 517 } else {
408 } 518 usage2(_("Invalid hostname/address"), optarg);
409 else {
410 usage2 (_("Invalid hostname/address"), optarg);
411 } 519 }
412 break; 520 break;
413 case 's': /* socket */ 521 case 's': /* socket */
414 db_socket = optarg; 522 result.config.db_socket = optarg;
415 break; 523 break;
416 case 'd': /* database */ 524 case 'd': /* database */
417 db = optarg; 525 result.config.db = optarg;
418 break; 526 break;
419 case 'l': 527 case 'l':
420 ssl = true; 528 result.config.ssl = true;
421 break; 529 break;
422 case 'C': 530 case 'C':
423 ca_cert = optarg; 531 result.config.ca_cert = optarg;
424 break; 532 break;
425 case 'a': 533 case 'a':
426 cert = optarg; 534 result.config.cert = optarg;
427 break; 535 break;
428 case 'k': 536 case 'k':
429 key = optarg; 537 result.config.key = optarg;
430 break; 538 break;
431 case 'D': 539 case 'D':
432 ca_dir = optarg; 540 result.config.ca_dir = optarg;
433 break; 541 break;
434 case 'L': 542 case 'L':
435 ciphers = optarg; 543 result.config.ciphers = optarg;
436 break; 544 break;
437 case 'u': /* username */ 545 case 'u': /* username */
438 db_user = optarg; 546 result.config.db_user = optarg;
439 break; 547 break;
440 case 'p': /* authentication information: password */ 548 case 'p': /* authentication information: password */
441 db_pass = strdup(optarg); 549 result.config.db_pass = strdup(optarg);
442 550
443 /* Delete the password from process list */ 551 /* Delete the password from process list */
444 while (*optarg != '\0') { 552 while (*optarg != '\0') {
@@ -446,167 +554,185 @@ process_arguments (int argc, char **argv)
446 optarg++; 554 optarg++;
447 } 555 }
448 break; 556 break;
449 case 'f': /* client options file */ 557 case 'f': /* client options file */
450 opt_file = optarg; 558 result.config.opt_file = optarg;
451 break; 559 break;
452 case 'g': /* client options group */ 560 case 'g': /* client options group */
453 opt_group = optarg; 561 result.config.opt_group = optarg;
454 break; 562 break;
455 case 'P': /* critical time threshold */ 563 case 'P': /* critical time threshold */
456 db_port = atoi (optarg); 564 result.config.db_port = atoi(optarg);
457 break; 565 break;
458 case 'S': 566 case 'S':
459 check_slave = 1; /* check-slave */ 567 case CHECK_REPLICA_OPT:
568 result.config.check_replica = true; /* check-slave */
460 break; 569 break;
461 case 'n': 570 case 'n':
462 ignore_auth = 1; /* ignore-auth */ 571 result.config.ignore_auth = true; /* ignore-auth */
463 break;
464 case 'w':
465 warning = optarg;
466 warning_time = strtod (warning, NULL);
467 break;
468 case 'c':
469 critical = optarg;
470 critical_time = strtod (critical, NULL);
471 break; 572 break;
472 case 'V': /* version */ 573 case 'w': {
473 print_revision (progname, NP_VERSION); 574 mp_range_parsed tmp = mp_parse_range_string(optarg);
474 exit (STATE_UNKNOWN); 575 if (tmp.error != MP_PARSING_SUCCES) {
475 case 'h': /* help */ 576 die(STATE_UNKNOWN, "failed to parse warning time threshold");
476 print_help (); 577 }
477 exit (STATE_UNKNOWN); 578 result.config.replica_thresholds =
579 mp_thresholds_set_warn(result.config.replica_thresholds, tmp.range);
580 } break;
581 case 'c': {
582 mp_range_parsed tmp = mp_parse_range_string(optarg);
583 if (tmp.error != MP_PARSING_SUCCES) {
584 die(STATE_UNKNOWN, "failed to parse critical time threshold");
585 }
586 result.config.replica_thresholds =
587 mp_thresholds_set_crit(result.config.replica_thresholds, tmp.range);
588 } break;
589 case 'V': /* version */
590 print_revision(progname, NP_VERSION);
591 exit(STATE_UNKNOWN);
592 case 'h': /* help */
593 print_help();
594 exit(STATE_UNKNOWN);
478 case 'v': 595 case 'v':
479 verbose++; 596 verbose++;
480 break; 597 break;
481 case '?': /* help */ 598 case '?': /* help */
482 usage5 (); 599 usage5();
600 case output_format_index: {
601 parsed_output_format parser = mp_parse_output_format(optarg);
602 if (!parser.parsing_success) {
603 printf("Invalid output format: %s\n", optarg);
604 exit(STATE_UNKNOWN);
605 }
606
607 result.config.output_format_is_set = true;
608 result.config.output_format = parser.output_format;
609 break;
610 }
483 } 611 }
484 } 612 }
485 613
486 c = optind; 614 int index = optind;
487 615
488 set_thresholds(&my_threshold, warning, critical); 616 while (argc > index) {
489 617 if (result.config.db_host == NULL) {
490 while ( argc > c ) { 618 if (is_host(argv[index])) {
491 619 result.config.db_host = argv[index++];
492 if (db_host == NULL) 620 } else {
493 if (is_host (argv[c])) { 621 usage2(_("Invalid hostname/address"), argv[index]);
494 db_host = argv[c++];
495 }
496 else {
497 usage2 (_("Invalid hostname/address"), argv[c]);
498 } 622 }
499 else if (db_user == NULL) 623 } else if (result.config.db_user == NULL) {
500 db_user = argv[c++]; 624 result.config.db_user = argv[index++];
501 else if (db_pass == NULL) 625 } else if (result.config.db_pass == NULL) {
502 db_pass = argv[c++]; 626 result.config.db_pass = argv[index++];
503 else if (db == NULL) 627 } else if (result.config.db == NULL) {
504 db = argv[c++]; 628 result.config.db = argv[index++];
505 else if (is_intnonneg (argv[c])) 629 } else if (is_intnonneg(argv[index])) {
506 db_port = atoi (argv[c++]); 630 result.config.db_port = atoi(argv[index++]);
507 else 631 } else {
508 break; 632 break;
633 }
509 } 634 }
510 635
511 return validate_arguments (); 636 return validate_arguments(result);
512} 637}
513 638
639check_mysql_config_wrapper validate_arguments(check_mysql_config_wrapper config_wrapper) {
640 if (config_wrapper.config.db_user == NULL) {
641 config_wrapper.config.db_user = strdup("");
642 }
514 643
515int 644 if (config_wrapper.config.db_host == NULL) {
516validate_arguments (void) 645 config_wrapper.config.db_host = strdup("");
517{ 646 }
518 if (db_user == NULL)
519 db_user = strdup("");
520
521 if (db_host == NULL)
522 db_host = strdup("");
523 647
524 if (db == NULL) 648 if (config_wrapper.config.db == NULL) {
525 db = strdup(""); 649 config_wrapper.config.db = strdup("");
650 }
526 651
527 return OK; 652 return config_wrapper;
528} 653}
529 654
530 655void print_help(void) {
531void
532print_help (void)
533{
534 char *myport; 656 char *myport;
535 xasprintf (&myport, "%d", MYSQL_PORT); 657 xasprintf(&myport, "%d", MYSQL_PORT);
536 658
537 print_revision (progname, NP_VERSION); 659 print_revision(progname, NP_VERSION);
538 660
539 printf (_(COPYRIGHT), copyright, email); 661 printf(_(COPYRIGHT), copyright, email);
540 662
541 printf ("%s\n", _("This program tests connections to a MySQL server")); 663 printf("%s\n", _("This program tests connections to a MySQL server"));
542 664
543 printf ("\n\n"); 665 printf("\n\n");
544 666
545 print_usage (); 667 print_usage();
546 668
547 printf (UT_HELP_VRSN); 669 printf(UT_HELP_VRSN);
548 printf (UT_EXTRA_OPTS); 670 printf(UT_EXTRA_OPTS);
549 671
550 printf (UT_HOST_PORT, 'P', myport); 672 printf(UT_HOST_PORT, 'P', myport);
551 printf (" %s\n", "-n, --ignore-auth"); 673 printf(" %s\n", "-n, --ignore-auth");
552 printf (" %s\n", _("Ignore authentication failure and check for mysql connectivity only")); 674 printf(" %s\n", _("Ignore authentication failure and check for mysql connectivity only"));
553 675
554 printf (" %s\n", "-s, --socket=STRING"); 676 printf(" %s\n", "-s, --socket=STRING");
555 printf (" %s\n", _("Use the specified socket (has no effect if -H is used)")); 677 printf(" %s\n", _("Use the specified socket (has no effect if -H is used)"));
556 678
557 printf (" %s\n", "-d, --database=STRING"); 679 printf(" %s\n", "-d, --database=STRING");
558 printf (" %s\n", _("Check database with indicated name")); 680 printf(" %s\n", _("Check database with indicated name"));
559 printf (" %s\n", "-f, --file=STRING"); 681 printf(" %s\n", "-f, --file=STRING");
560 printf (" %s\n", _("Read from the specified client options file")); 682 printf(" %s\n", _("Read from the specified client options file"));
561 printf (" %s\n", "-g, --group=STRING"); 683 printf(" %s\n", "-g, --group=STRING");
562 printf (" %s\n", _("Use a client options group")); 684 printf(" %s\n", _("Use a client options group"));
563 printf (" %s\n", "-u, --username=STRING"); 685 printf(" %s\n", "-u, --username=STRING");
564 printf (" %s\n", _("Connect using the indicated username")); 686 printf(" %s\n", _("Connect using the indicated username"));
565 printf (" %s\n", "-p, --password=STRING"); 687 printf(" %s\n", "-p, --password=STRING");
566 printf (" %s\n", _("Use the indicated password to authenticate the connection")); 688 printf(" %s\n", _("Use the indicated password to authenticate the connection"));
567 printf (" ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!")); 689 printf(" ==> %s <==\n", _("IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!!"));
568 printf (" %s\n", _("Your clear-text password could be visible as a process table entry")); 690 printf(" %s\n", _("Your clear-text password could be visible as a process table entry"));
569 printf (" %s\n", "-S, --check-slave"); 691 printf(" %s\n", "-S, --check-slave");
570 printf (" %s\n", _("Check if the slave thread is running properly.")); 692 printf(" %s\n", _("Check if the slave thread is running properly. This option is deprecated "
571 printf (" %s\n", "-w, --warning"); 693 "in favour of check-replica, which does the same"));
572 printf (" %s\n", _("Exit with WARNING status if slave server is more than INTEGER seconds")); 694 printf(" %s\n", "--check-replica");
573 printf (" %s\n", _("behind master")); 695 printf(" %s\n", _("Check if the replica thread is running properly."));
574 printf (" %s\n", "-c, --critical"); 696 printf(" %s\n", "-w, --warning");
575 printf (" %s\n", _("Exit with CRITICAL status if slave server is more then INTEGER seconds")); 697 printf(" %s\n",
576 printf (" %s\n", _("behind master")); 698 _("Exit with WARNING status if replica server is more than INTEGER seconds"));
577 printf (" %s\n", "-l, --ssl"); 699 printf(" %s\n", _("behind master"));
578 printf (" %s\n", _("Use ssl encryption")); 700 printf(" %s\n", "-c, --critical");
579 printf (" %s\n", "-C, --ca-cert=STRING"); 701 printf(" %s\n",
580 printf (" %s\n", _("Path to CA signing the cert")); 702 _("Exit with CRITICAL status if replica server is more then INTEGER seconds"));
581 printf (" %s\n", "-a, --cert=STRING"); 703 printf(" %s\n", _("behind master"));
582 printf (" %s\n", _("Path to SSL certificate")); 704 printf(" %s\n", "-l, --ssl");
583 printf (" %s\n", "-k, --key=STRING"); 705 printf(" %s\n", _("Use ssl encryption"));
584 printf (" %s\n", _("Path to private SSL key")); 706 printf(" %s\n", "-C, --ca-cert=STRING");
585 printf (" %s\n", "-D, --ca-dir=STRING"); 707 printf(" %s\n", _("Path to CA signing the cert"));
586 printf (" %s\n", _("Path to CA directory")); 708 printf(" %s\n", "-a, --cert=STRING");
587 printf (" %s\n", "-L, --ciphers=STRING"); 709 printf(" %s\n", _("Path to SSL certificate"));
588 printf (" %s\n", _("List of valid SSL ciphers")); 710 printf(" %s\n", "-k, --key=STRING");
589 711 printf(" %s\n", _("Path to private SSL key"));
590 712 printf(" %s\n", "-D, --ca-dir=STRING");
591 printf ("\n"); 713 printf(" %s\n", _("Path to CA directory"));
592 printf (" %s\n", _("There are no required arguments. By default, the local database is checked")); 714 printf(" %s\n", "-L, --ciphers=STRING");
593 printf (" %s\n", _("using the default unix socket. You can force TCP on localhost by using an")); 715 printf(" %s\n", _("List of valid SSL ciphers"));
594 printf (" %s\n", _("IP address or FQDN ('localhost' will use the socket as well).")); 716
595 717 printf(UT_OUTPUT_FORMAT);
596 printf ("\n"); 718
597 printf ("%s\n", _("Notes:")); 719 printf("\n");
598 printf (" %s\n", _("You must specify -p with an empty string to force an empty password,")); 720 printf(" %s\n",
599 printf (" %s\n", _("overriding any my.cnf settings.")); 721 _("There are no required arguments. By default, the local database is checked"));
600 722 printf(" %s\n", _("using the default unix socket. You can force TCP on localhost by using an"));
601 printf (UT_SUPPORT); 723 printf(" %s\n", _("IP address or FQDN ('localhost' will use the socket as well)."));
724
725 printf("\n");
726 printf("%s\n", _("Notes:"));
727 printf(" %s\n", _("You must specify -p with an empty string to force an empty password,"));
728 printf(" %s\n", _("overriding any my.cnf settings."));
729
730 printf(UT_SUPPORT);
602} 731}
603 732
604 733void print_usage(void) {
605void 734 printf("%s\n", _("Usage:"));
606print_usage (void) 735 printf(" %s [-d database] [-H host] [-P port] [-s socket]\n", progname);
607{ 736 printf(" [-u user] [-p password] [-S] [-l] [-a cert] [-k key]\n");
608 printf ("%s\n", _("Usage:")); 737 printf(" [-C ca-cert] [-D ca-dir] [-L ciphers] [-f optfile] [-g group]\n");
609 printf (" %s [-d database] [-H host] [-P port] [-s socket]\n",progname);
610 printf (" [-u user] [-p password] [-S] [-l] [-a cert] [-k key]\n");
611 printf (" [-C ca-cert] [-D ca-dir] [-L ciphers] [-f optfile] [-g group]\n");
612} 738}