From 43ff2e8607c0b7095c2a4dcab6e466bc67e2e2ff Mon Sep 17 00:00:00 2001 From: Michael Orlitzky <michael@orlitzky.com> Date: Thu, 26 Oct 2017 15:01:17 -0400 Subject: [PATCH 1/3] plugins/check_mysql*.c: define our own default MySQL port. The MYSQL_PORT constant used to be defined in mysql.h, and was used as the default port in the two plugins check_mysql and check_mysql_query. Now that mysql.h no longer defines that constant, our plugins fail to build against newer versions of MySQL and MariaDB. Since MYSQL_PORT used the "default port" on the local system, it actually was not the best choice as the default for the check plugins: when monitoring remote MySQL servers, the usual default of 3306 is more likely to be correct than whatever the local server happens to be listening on. As a result, we fix the issue by defining our own constant, called CHECK_PORT_DEFAULT, as "3306" at the top of both check_mysql.c and check_mysql_query.c. The existing uses of MYSQL_PORT have been changed to use the new CHECK_PORT_DEFAULT. This change is backwards-incompatible: any users who compiled in a MYSQL_PORT other than 3306 and who were running their checks on the same server as the database will now need to specify that port explicitly. Closes: https://github.com/nagios-plugins/nagios-plugins/issues/288 --- plugins/check_mysql.c | 7 +++++-- plugins/check_mysql_query.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index 83f89c85..c0b61292 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -36,6 +36,9 @@ const char *email = "devel@nagios-plugins.org"; #define SLAVERESULTSIZE 70 +/* The default port that MySQL servers listen on. */ +#define CHECK_PORT_DEFAULT 3306 + #include "common.h" #include "utils.h" #include "utils_base.h" @@ -58,7 +61,7 @@ char *ciphers = NULL; bool ssl = false; char *opt_file = NULL; char *opt_group = NULL; -unsigned int db_port = MYSQL_PORT; +unsigned int db_port = CHECK_PORT_DEFAULT; int check_slave = 0, warn_sec = 0, crit_sec = 0; int ignore_auth = 0; int verbose = 0; @@ -505,7 +508,7 @@ void print_help (void) { char *myport; - xasprintf (&myport, "%d", MYSQL_PORT); + xasprintf (&myport, "%d", CHECK_PORT_DEFAULT); print_revision (progname, NP_VERSION); diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index 436e0685..e9c3acfb 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c @@ -33,6 +33,9 @@ const char *progname = "check_mysql_query"; const char *copyright = "1999-2014"; const char *email = "devel@nagios-plugins.org"; +/* The default port that MySQL servers listen on. */ +#define CHECK_PORT_DEFAULT 3306 + #include "common.h" #include "utils.h" #include "utils_base.h" @@ -48,7 +51,7 @@ char *db_pass = NULL; char *db = NULL; char *opt_file = NULL; char *opt_group = NULL; -unsigned int db_port = MYSQL_PORT; +unsigned int db_port = CHECK_PORT_DEFAULT; int process_arguments (int, char **); int validate_arguments (void); @@ -300,7 +303,7 @@ void print_help (void) { char *myport; - xasprintf (&myport, "%d", MYSQL_PORT); + xasprintf (&myport, "%d", CHECK_PORT_DEFAULT); print_revision (progname, NP_VERSION); From 21ad98d17ab523f39bdc5248d89af35d1f0d4347 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky <michael@orlitzky.com> Date: Thu, 26 Oct 2017 15:10:46 -0400 Subject: [PATCH 2/3] plugins/check_mysql*.c: update the latest copyright year to 2017. --- plugins/check_mysql.c | 4 ++-- plugins/check_mysql_query.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index c0b61292..c346f5e0 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -5,7 +5,7 @@ * License: GPL * Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at) * Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) -* Copyright (c) 1999-2014 Nagios Plugins Development Team +* Copyright (c) 1999-2017 Nagios Plugins Development Team * * Description: * @@ -31,7 +31,7 @@ *****************************************************************************/ const char *progname = "check_mysql"; -const char *copyright = "1999-2014"; +const char *copyright = "1999-2017"; const char *email = "devel@nagios-plugins.org"; #define SLAVERESULTSIZE 70 diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index e9c3acfb..bc6bbbe5 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c @@ -3,7 +3,7 @@ * Nagios check_mysql_query plugin * * License: GPL -* Copyright (c) 2006-2014 Nagios Plugins Development Team +* Copyright (c) 2006-2017 Nagios Plugins Development Team * Original code from check_mysql, copyright 1999 Didi Rieder * * Description: @@ -30,7 +30,7 @@ *****************************************************************************/ const char *progname = "check_mysql_query"; -const char *copyright = "1999-2014"; +const char *copyright = "1999-2017"; const char *email = "devel@nagios-plugins.org"; /* The default port that MySQL servers listen on. */ From 85ee5c22196a8fe82945b2d0434644fec4ecaf71 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky <michael@orlitzky.com> Date: Fri, 27 Oct 2017 07:38:31 -0400 Subject: [PATCH 3/3] plugins/check_mysql*.c: remove trailing whitespace. --- plugins/check_mysql.c | 24 ++++++++++++------------ plugins/check_mysql_query.c | 24 ++++++++++++------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index c346f5e0..928d17df 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -1,33 +1,33 @@ /***************************************************************************** -* +* * Nagios check_mysql plugin -* +* * License: GPL * Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at) * Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net) * Copyright (c) 1999-2017 Nagios Plugins Development Team -* +* * Description: -* +* * This file contains the check_mysql plugin -* +* * This program tests connections to a mysql server -* -* +* +* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* +* +* *****************************************************************************/ const char *progname = "check_mysql"; @@ -128,7 +128,7 @@ main (int argc, char **argv) /* initialize mysql */ mysql_init (&mysql); - + if (opt_file != NULL) mysql_options(&mysql,MYSQL_READ_DEFAULT_FILE,opt_file); diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index bc6bbbe5..ba7de818 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c @@ -1,32 +1,32 @@ /***************************************************************************** -* +* * Nagios check_mysql_query plugin -* +* * License: GPL * Copyright (c) 2006-2017 Nagios Plugins Development Team * Original code from check_mysql, copyright 1999 Didi Rieder -* +* * Description: -* +* * This file contains the check_mysql_query plugin -* +* * This plugin is for running arbitrary SQL and checking the results -* -* +* +* * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. -* -* +* +* *****************************************************************************/ const char *progname = "check_mysql_query"; @@ -70,7 +70,7 @@ main (int argc, char **argv) MYSQL mysql; MYSQL_RES *res; MYSQL_ROW row; - + double value; char *error = NULL; int status;