summaryrefslogtreecommitdiffstats
path: root/plugins/check_mysql_query.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_mysql_query.c')
-rw-r--r--plugins/check_mysql_query.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index edc2ec8..71ab776 100644
--- a/plugins/check_mysql_query.c
+++ b/plugins/check_mysql_query.c
@@ -1,9 +1,9 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Nagios check_mysql_query plugin 3* Monitoring check_mysql_query plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2006-2009 Nagios Plugins Development Team 6* Copyright (c) 2006-2009 Monitoring Plugins Development Team
7* Original code from check_mysql, copyright 1999 Didi Rieder 7* Original code from check_mysql, copyright 1999 Didi Rieder
8* 8*
9* Description: 9* Description:
@@ -31,7 +31,7 @@
31 31
32const char *progname = "check_mysql_query"; 32const char *progname = "check_mysql_query";
33const char *copyright = "1999-2007"; 33const char *copyright = "1999-2007";
34const char *email = "devel@nagios-plugins.org"; 34const char *email = "devel@monitoring-plugins.org";
35 35
36#include "common.h" 36#include "common.h"
37#include "utils.h" 37#include "utils.h"
@@ -46,6 +46,8 @@ char *db_host = NULL;
46char *db_socket = NULL; 46char *db_socket = NULL;
47char *db_pass = NULL; 47char *db_pass = NULL;
48char *db = NULL; 48char *db = NULL;
49char *opt_file = NULL;
50char *opt_group = NULL;
49unsigned int db_port = MYSQL_PORT; 51unsigned int db_port = MYSQL_PORT;
50 52
51int process_arguments (int, char **); 53int process_arguments (int, char **);
@@ -83,7 +85,13 @@ main (int argc, char **argv)
83 /* initialize mysql */ 85 /* initialize mysql */
84 mysql_init (&mysql); 86 mysql_init (&mysql);
85 87
86 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client"); 88 if (opt_file != NULL)
89 mysql_options(&mysql,MYSQL_READ_DEFAULT_FILE,opt_file);
90
91 if (opt_group != NULL)
92 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,opt_group);
93 else
94 mysql_options(&mysql,MYSQL_READ_DEFAULT_GROUP,"client");
87 95
88 /* establish a connection to the server and error checking */ 96 /* establish a connection to the server and error checking */
89 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) { 97 if (!mysql_real_connect(&mysql,db_host,db_user,db_pass,db,db_port,db_socket,0)) {
@@ -152,7 +160,13 @@ main (int argc, char **argv)
152 } else if (status == STATE_CRITICAL) { 160 } else if (status == STATE_CRITICAL) {
153 printf("QUERY %s: ", _("CRITICAL")); 161 printf("QUERY %s: ", _("CRITICAL"));
154 } 162 }
155 printf(_("'%s' returned %f"), sql_query, value); 163 printf(_("'%s' returned %f | %s"), sql_query, value,
164 fperfdata("result", value, "",
165 my_thresholds->warning?TRUE:FALSE, my_thresholds->warning?my_thresholds->warning->end:0,
166 my_thresholds->critical?TRUE:FALSE, my_thresholds->critical?my_thresholds->critical->end:0,
167 FALSE, 0,
168 FALSE, 0)
169 );
156 printf("\n"); 170 printf("\n");
157 171
158 return status; 172 return status;
@@ -174,6 +188,8 @@ process_arguments (int argc, char **argv)
174 {"database", required_argument, 0, 'd'}, 188 {"database", required_argument, 0, 'd'},
175 {"username", required_argument, 0, 'u'}, 189 {"username", required_argument, 0, 'u'},
176 {"password", required_argument, 0, 'p'}, 190 {"password", required_argument, 0, 'p'},
191 {"file", required_argument, 0, 'f'},
192 {"group", required_argument, 0, 'g'},
177 {"port", required_argument, 0, 'P'}, 193 {"port", required_argument, 0, 'P'},
178 {"verbose", no_argument, 0, 'v'}, 194 {"verbose", no_argument, 0, 'v'},
179 {"version", no_argument, 0, 'V'}, 195 {"version", no_argument, 0, 'V'},
@@ -188,7 +204,7 @@ process_arguments (int argc, char **argv)
188 return ERROR; 204 return ERROR;
189 205
190 while (1) { 206 while (1) {
191 c = getopt_long (argc, argv, "hvVP:p:u:d:H:s:q:w:c:", longopts, &option); 207 c = getopt_long (argc, argv, "hvVP:p:u:d:H:s:q:w:c:f:g:", longopts, &option);
192 208
193 if (c == -1 || c == EOF) 209 if (c == -1 || c == EOF)
194 break; 210 break;
@@ -220,6 +236,12 @@ process_arguments (int argc, char **argv)
220 optarg++; 236 optarg++;
221 } 237 }
222 break; 238 break;
239 case 'f': /* client options file */
240 opt_file = optarg;
241 break;
242 case 'g': /* client options group */
243 opt_group = optarg;
244 break;
223 case 'P': /* critical time threshold */ 245 case 'P': /* critical time threshold */
224 db_port = atoi (optarg); 246 db_port = atoi (optarg);
225 break; 247 break;
@@ -299,6 +321,10 @@ print_help (void)
299 printf (" %s\n", _("Use the specified socket (has no effect if -H is used)")); 321 printf (" %s\n", _("Use the specified socket (has no effect if -H is used)"));
300 printf (" -d, --database=STRING\n"); 322 printf (" -d, --database=STRING\n");
301 printf (" %s\n", _("Database to check")); 323 printf (" %s\n", _("Database to check"));
324 printf (" %s\n", "-f, --file=STRING");
325 printf (" %s\n", _("Read from the specified client options file"));
326 printf (" %s\n", "-g, --group=STRING");
327 printf (" %s\n", _("Use a client options group"));
302 printf (" -u, --username=STRING\n"); 328 printf (" -u, --username=STRING\n");
303 printf (" %s\n", _("Username to login with")); 329 printf (" %s\n", _("Username to login with"));
304 printf (" -p, --password=STRING\n"); 330 printf (" -p, --password=STRING\n");
@@ -324,5 +350,5 @@ print_usage (void)
324{ 350{
325 printf ("%s\n", _("Usage:")); 351 printf ("%s\n", _("Usage:"));
326 printf (" %s -q SQL_query [-w warn] [-c crit] [-H host] [-P port] [-s socket]\n",progname); 352 printf (" %s -q SQL_query [-w warn] [-c crit] [-H host] [-P port] [-s socket]\n",progname);
327 printf (" [-d database] [-u user] [-p password]\n"); 353 printf (" [-d database] [-u user] [-p password] [-f optfile] [-g group]\n");
328} 354}