diff options
Diffstat (limited to 'plugins/check_mysql_query.c')
| -rw-r--r-- | plugins/check_mysql_query.c | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index 5e04a94b..c7e84deb 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c | |||
| @@ -47,7 +47,8 @@ typedef struct { | |||
| 47 | check_mysql_query_config config; | 47 | check_mysql_query_config config; |
| 48 | } check_mysql_query_config_wrapper; | 48 | } check_mysql_query_config_wrapper; |
| 49 | static check_mysql_query_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); | 49 | static check_mysql_query_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/); |
| 50 | static check_mysql_query_config_wrapper validate_arguments(check_mysql_query_config_wrapper /*config_wrapper*/); | 50 | static check_mysql_query_config_wrapper |
| 51 | validate_arguments(check_mysql_query_config_wrapper /*config_wrapper*/); | ||
| 51 | static void print_help(void); | 52 | static void print_help(void); |
| 52 | void print_usage(void); | 53 | void print_usage(void); |
| 53 | 54 | ||
| @@ -83,7 +84,8 @@ int main(int argc, char **argv) { | |||
| 83 | } | 84 | } |
| 84 | 85 | ||
| 85 | /* establish a connection to the server and error checking */ | 86 | /* establish a connection to the server and error checking */ |
| 86 | if (!mysql_real_connect(&mysql, config.db_host, config.db_user, config.db_pass, config.db, config.db_port, config.db_socket, 0)) { | 87 | if (!mysql_real_connect(&mysql, config.db_host, config.db_user, config.db_pass, config.db, |
| 88 | config.db_port, config.db_socket, 0)) { | ||
| 87 | if (mysql_errno(&mysql) == CR_UNKNOWN_HOST) { | 89 | if (mysql_errno(&mysql) == CR_UNKNOWN_HOST) { |
| 88 | die(STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error(&mysql)); | 90 | die(STATE_WARNING, "QUERY %s: %s\n", _("WARNING"), mysql_error(&mysql)); |
| 89 | } else if (mysql_errno(&mysql) == CR_VERSION_ERROR) { | 91 | } else if (mysql_errno(&mysql) == CR_VERSION_ERROR) { |
| @@ -155,8 +157,11 @@ int main(int argc, char **argv) { | |||
| 155 | printf("QUERY %s: ", _("CRITICAL")); | 157 | printf("QUERY %s: ", _("CRITICAL")); |
| 156 | } | 158 | } |
| 157 | printf(_("'%s' returned %f | %s"), config.sql_query, value, | 159 | printf(_("'%s' returned %f | %s"), config.sql_query, value, |
| 158 | fperfdata("result", value, "", config.my_thresholds->warning, config.my_thresholds->warning ? config.my_thresholds->warning->end : 0, | 160 | fperfdata("result", value, "", config.my_thresholds->warning, |
| 159 | config.my_thresholds->critical, config.my_thresholds->critical ? config.my_thresholds->critical->end : 0, false, 0, false, 0)); | 161 | config.my_thresholds->warning ? config.my_thresholds->warning->end : 0, |
| 162 | config.my_thresholds->critical, | ||
| 163 | config.my_thresholds->critical ? config.my_thresholds->critical->end : 0, | ||
| 164 | false, 0, false, 0)); | ||
| 160 | printf("\n"); | 165 | printf("\n"); |
| 161 | 166 | ||
| 162 | return status; | 167 | return status; |
| @@ -164,12 +169,21 @@ int main(int argc, char **argv) { | |||
| 164 | 169 | ||
| 165 | /* process command-line arguments */ | 170 | /* process command-line arguments */ |
| 166 | check_mysql_query_config_wrapper process_arguments(int argc, char **argv) { | 171 | check_mysql_query_config_wrapper process_arguments(int argc, char **argv) { |
| 167 | static struct option longopts[] = { | 172 | static struct option longopts[] = {{"hostname", required_argument, 0, 'H'}, |
| 168 | {"hostname", required_argument, 0, 'H'}, {"socket", required_argument, 0, 's'}, {"database", required_argument, 0, 'd'}, | 173 | {"socket", required_argument, 0, 's'}, |
| 169 | {"username", required_argument, 0, 'u'}, {"password", required_argument, 0, 'p'}, {"file", required_argument, 0, 'f'}, | 174 | {"database", required_argument, 0, 'd'}, |
| 170 | {"group", required_argument, 0, 'g'}, {"port", required_argument, 0, 'P'}, {"verbose", no_argument, 0, 'v'}, | 175 | {"username", required_argument, 0, 'u'}, |
| 171 | {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, 'h'}, {"query", required_argument, 0, 'q'}, | 176 | {"password", required_argument, 0, 'p'}, |
| 172 | {"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'}, {0, 0, 0, 0}}; | 177 | {"file", required_argument, 0, 'f'}, |
| 178 | {"group", required_argument, 0, 'g'}, | ||
| 179 | {"port", required_argument, 0, 'P'}, | ||
| 180 | {"verbose", no_argument, 0, 'v'}, | ||
| 181 | {"version", no_argument, 0, 'V'}, | ||
| 182 | {"help", no_argument, 0, 'h'}, | ||
| 183 | {"query", required_argument, 0, 'q'}, | ||
| 184 | {"warning", required_argument, 0, 'w'}, | ||
| 185 | {"critical", required_argument, 0, 'c'}, | ||
| 186 | {0, 0, 0, 0}}; | ||
| 173 | 187 | ||
| 174 | check_mysql_query_config_wrapper result = { | 188 | check_mysql_query_config_wrapper result = { |
| 175 | .errorcode = OK, | 189 | .errorcode = OK, |
| @@ -255,7 +269,8 @@ check_mysql_query_config_wrapper process_arguments(int argc, char **argv) { | |||
| 255 | return validate_arguments(result); | 269 | return validate_arguments(result); |
| 256 | } | 270 | } |
| 257 | 271 | ||
| 258 | check_mysql_query_config_wrapper validate_arguments(check_mysql_query_config_wrapper config_wrapper) { | 272 | check_mysql_query_config_wrapper |
| 273 | validate_arguments(check_mysql_query_config_wrapper config_wrapper) { | ||
| 259 | if (config_wrapper.config.sql_query == NULL) { | 274 | if (config_wrapper.config.sql_query == NULL) { |
| 260 | usage("Must specify a SQL query to run"); | 275 | usage("Must specify a SQL query to run"); |
| 261 | } | 276 | } |
