summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql_query.c
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-04-30 12:50:52 +0000
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2008-04-30 12:50:52 +0000
commitaca1e6a6cec40754c67d3cf229db2660c4685202 (patch)
treef9093f5eefea0dcf6745a6a92e17b74950a1efa3 /plugins/check_mysql_query.c
parent6f2ee45c932dfec9d9a1e651b39d18f98b2ef009 (diff)
downloadmonitoring-plugins-aca1e6a6cec40754c67d3cf229db2660c4685202.tar.gz
Add socket support to check_mysql*
Also clears the password from check_mysql command-line options git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1988 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_mysql_query.c')
-rw-r--r--plugins/check_mysql_query.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index 8c6a96c6..171fc69f 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
48char *db_user = NULL; 48char *db_user = NULL;
49char *db_host = NULL; 49char *db_host = NULL;
50char *db_socket = NULL;
50char *db_pass = NULL; 51char *db_pass = NULL;
51char *db = NULL; 52char *db = NULL;
52unsigned int db_port = MYSQL_PORT; 53unsigned 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
313print_usage (void) 321print_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}