diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index ffd96ed4743dc509745bdf83dbdf6f6821efd005..20901e639d908afd7f211469d8e50fe69f95a56b 100644 (file)
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
const char *progname = "check_mysql";
const char *revision = "$Revision$";
const char *progname = "check_mysql";
const char *revision = "$Revision$";
-const char *copyright = "1999-2002";
+const char *copyright = "1999-2004";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#define SLAVERESULTSIZE 40
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#define SLAVERESULTSIZE 40
#include "common.h"
#include "utils.h"
#include "netutils.h"
#include "common.h"
#include "utils.h"
#include "netutils.h"
+
#include <mysql/mysql.h>
#include <mysql/errmsg.h>
#include <mysql/mysql.h>
#include <mysql/errmsg.h>
void print_help (void);
void print_usage (void);
void print_help (void);
void print_usage (void);
+
+
int
main (int argc, char **argv)
{
int
main (int argc, char **argv)
{
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
MYSQL mysql;
MYSQL_RES *res;
MYSQL_ROW row;
+
+ /* should be status */
+
char *result = NULL;
char slaveresult[SLAVERESULTSIZE];
char *result = NULL;
char slaveresult[SLAVERESULTSIZE];
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
- if (process_arguments (argc, argv) != OK)
- usage (_("check_mysql: could not parse arguments\n"));
+ if (process_arguments (argc, argv) == ERROR)
+ usage4 (_("Could not parse arguments"));
/* initialize mysql */
mysql_init (&mysql);
/* initialize mysql */
mysql_init (&mysql);
/* check the slave status */
if (mysql_query (&mysql, "show slave status") != 0) {
mysql_close (&mysql);
/* check the slave status */
if (mysql_query (&mysql, "show slave status") != 0) {
mysql_close (&mysql);
- die (STATE_CRITICAL, "slave query error: %s\n", mysql_error (&mysql));
+ die (STATE_CRITICAL, _("slave query error: %s\n"), mysql_error (&mysql));
}
/* store the result */
if ( (res = mysql_store_result (&mysql)) == NULL) {
mysql_close (&mysql);
}
/* store the result */
if ( (res = mysql_store_result (&mysql)) == NULL) {
mysql_close (&mysql);
- die (STATE_CRITICAL, "slave store_result error: %s\n", mysql_error (&mysql));
+ die (STATE_CRITICAL, _("slave store_result error: %s\n"), mysql_error (&mysql));
}
/* fetch the first row */
if ( (row = mysql_fetch_row (res)) == NULL) {
mysql_free_result (res);
mysql_close (&mysql);
}
/* fetch the first row */
if ( (row = mysql_fetch_row (res)) == NULL) {
mysql_free_result (res);
mysql_close (&mysql);
- die (STATE_CRITICAL, "slave fetch row error: %s\n", mysql_error (&mysql));
+ die (STATE_CRITICAL, _("slave fetch row error: %s\n"), mysql_error (&mysql));
}
if (mysql_field_count (&mysql) == 12) {
/* mysql 3.23.x */
}
if (mysql_field_count (&mysql) == 12) {
/* mysql 3.23.x */
- snprintf (slaveresult, SLAVERESULTSIZE, "Slave running: %s", row[6]);
+ snprintf (slaveresult, SLAVERESULTSIZE, _("Slave running: %s"), row[6]);
if (strcmp (row[6], "Yes") != 0) {
mysql_free_result (res);
mysql_close (&mysql);
if (strcmp (row[6], "Yes") != 0) {
mysql_free_result (res);
mysql_close (&mysql);
} else {
/* mysql 4.x.x */
} else {
/* mysql 4.x.x */
- snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s", row[9], row[10]);
- if (strcmp (row[9], "Yes") != 0 || strcmp (row[10], "Yes") != 0) {
+ int slave_io_field = -1 , slave_sql_field = -1, i, num_fields;
+ MYSQL_FIELD* fields;
+
+ num_fields = mysql_num_fields(res);
+ fields = mysql_fetch_fields(res);
+ for(i = 0; i < num_fields; i++)
+ {
+ if (0 == strcmp(fields[i].name, "Slave_IO_Running"))
+ {
+ slave_io_field = i;
+ continue;
+ }
+ if (0 == strcmp(fields[i].name, "Slave_SQL_Running"))
+ {
+ slave_sql_field = i;
+ continue;
+ }
+ }
+ if ((slave_io_field < 0) || (slave_sql_field < 0) || (num_fields == 0))
+ {
+ mysql_free_result (res);
+ mysql_close (&mysql);
+ die (STATE_CRITICAL, "Slave status unavailable\n");
+ }
+
+ snprintf (slaveresult, SLAVERESULTSIZE, "Slave IO: %s Slave SQL: %s", row[slave_io_field], row[slave_sql_field]);
+ if (strcmp (row[slave_io_field], "Yes") != 0 || strcmp (row[slave_sql_field], "Yes") != 0) {
mysql_free_result (res);
mysql_close (&mysql);
die (STATE_CRITICAL, "%s\n", slaveresult);
mysql_free_result (res);
mysql_close (&mysql);
die (STATE_CRITICAL, "%s\n", slaveresult);
}
}
-
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
print_help ();
exit (STATE_OK);
case '?': /* help */
print_help ();
exit (STATE_OK);
case '?': /* help */
- printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
- print_usage ();
- exit (STATE_UNKNOWN);
+ usage2 (_("Unknown argument"), optarg);
}
}
}
}
}
}
-
int
validate_arguments (void)
{
int
validate_arguments (void)
{
}
}
-
void
print_help (void)
{
void
print_help (void)
{
@@ -298,12 +324,10 @@ a server listening on MySQL standard port %d will be checked\n"), MYSQL_PORT);
}
}
-
void
print_usage (void)
{
void
print_usage (void)
{
- printf (_("\
-Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password] [-S]\n"),
+ printf ("\
+Usage: %s [-d database] [-H host] [-P port] [-u user] [-p password] [-S]\n",
progname);
progname);
- printf (_(UT_HLP_VRS), progname, progname);
}
}