Bug#278864: check_mysql and slave status

2005-02-18 Thread Guido Trotter

Hi!

As you may know the new version of nagios-plugins has been released and uploaded
in debian. In the new release it seems there is some support for checking slave
status, but probably not your full patch...

Can you please check it and see if you think it's sufficient. If it's not I am
willing to integrate the rest of your patch, but I'd like to have assurance from
upstream before that they are going to integrate it too, in the next release...

Thanks,

--
Guido Trotter
nagios-plugins maintainer


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Bug#278864: check_mysql and slave status

2005-02-22 Thread Ian Gulliver
> Can you please check it and see if you think it's sufficient. If it's not I am
> willing to integrate the rest of your patch, but I'd like to have assurance 
> from
> upstream before that they are going to integrate it too, in the next 
> release...

The patch contained checking from the slave point of view, but not from
the master.  Attached is a new patch against the current version that
provides the latter as well.

-- 
Ian Gulliver
Penguin Hosting
"Failure is not an option; it comes bundled with your Microsoft products."
diff -udr nagios-plugins-1.4/plugins/check_mysql.c 
nagios-plugins-1.4-slave/plugins/check_mysql.c
--- nagios-plugins-1.4/plugins/check_mysql.c2005-02-22 11:35:35.0 
-0500
+++ nagios-plugins-1.4-slave/plugins/check_mysql.c  2005-02-22 
12:01:54.0 -0500
@@ -34,6 +34,7 @@
 char *db = NULL;
 unsigned int db_port = MYSQL_PORT;
 int check_slave = 0;
+char *slave_host = NULL;
 
 int process_arguments (int, char **);
 int validate_arguments (void);
@@ -137,6 +138,34 @@
mysql_free_result (res);
}
 
+   if(slave_host != NULL) {
+   int found = 0;
+   /* check for connected slave host */
+   if (mysql_query (&mysql, "show slave hosts") != 0) {
+   mysql_close (&mysql);
+   die (STATE_CRITICAL, _("slave hosts query error: 
%s\n"), mysql_error (&mysql));
+   }
+
+   /* store the result */
+   if ( (res = mysql_store_result (&mysql)) == NULL) {
+   mysql_close (&mysql);
+   die (STATE_CRITICAL, _("slave hosts store_result error: 
%s\n"), mysql_error (&mysql));
+   }
+
+   /* fetch the first row */
+   while ( (row = mysql_fetch_row (res)) != NULL) {
+   if (slave_host[0] != '\0' && strcmp(row[1],slave_host) 
!= 0)
+   continue;
+   found = 1;
+   }
+
+   if (found == 0)
+   die (STATE_CRITICAL, "Slave host %s%snot connected\n", 
slave_host, slave_host[0] == '\0' ? "" : " ");
+
+   /* free the result */
+   mysql_free_result (res);
+   }
+
/* close the connection */
mysql_close (&mysql);
 
@@ -165,6 +194,7 @@
{"password", required_argument, 0, 'p'},
{"port", required_argument, 0, 'P'},
{"check-slave", no_argument, 0, 'S'},
+   {"slave-host", optional_argument, 0, 's'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
@@ -175,7 +205,7 @@
return ERROR;
 
while (1) {
-   c = getopt_long (argc, argv, "hVSP:p:u:d:H:", longopts, 
&option);
+   c = getopt_long (argc, argv, "hVSP:p:u:d:H:s::", longopts, 
&option);
 
if (c == -1 || c == EOF)
break;
@@ -204,6 +234,12 @@
case 'S':
check_slave = 1;
/* check-slave */
break;
+   case 's':
+   if (optarg == NULL)
+   slave_host = "";
+   else
+   slave_host = optarg;
+   break;
case 'V':   
/* version */
print_revision (progname, revision);
exit (STATE_OK);
@@ -289,7 +325,9 @@
==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==\n\
Your clear-text password will be visible as a process table entry\n\
  -S, --check-slave\n\
-   Check if the slave thread is running properly.\n"));
+   Check if the slave thread is running properly.\n\
+ -s, --slave-host[=STRING]\n\
+   Check if a slave host (named STRING) is connected.\n"));
 
printf (_("\n\
 There are no required arguments. By default, the local database with\n\


signature.asc
Description: Digital signature