summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e03d87d)
raw | patch | inline | side by side (parent: e03d87d)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 15 Dec 2005 17:06:55 +0000 (17:06 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Thu, 15 Dec 2005 17:06:55 +0000 (17:06 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1299 f882894a-f735-0410-b71e-b25c423dba1c
NPTest.pm | patch | blob | history | |
plugins/check_mysql.c | patch | blob | history | |
plugins/t/check_mysql.t | patch | blob | history |
diff --git a/NPTest.pm b/NPTest.pm
index 4036a9d0e4a04520c8d42fe66c48849eae430632..7ecf74399779bf31aa16215bedb36517f638db21 100644 (file)
--- a/NPTest.pm
+++ b/NPTest.pm
=item getTestParameter( "ENV_VARIABLE", $brief_description, $default )
+$default is optional.
+
This function allows the test harness
developer to interactively request test parameter information from the
user. The user can accept the developer's default value or reply "none"
{
my( $param, $envvar, $default, $brief, $scoped );
my $new_style;
- if (scalar @_ == 3) {
+ if (scalar @_ <= 3) {
($param, $brief, $default) = @_;
$envvar = $param;
$new_style = 1;
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index 3194ecede85b73f7ef572d06467848d066772e16..45f86a9c6319e49e88f4f152f5824f73ea4d2f2e 100644 (file)
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
/* should be status */
char *result = NULL;
+ char *error = NULL;
char slaveresult[SLAVERESULTSIZE];
setlocale (LC_ALL, "");
if(check_slave) {
/* check the slave status */
if (mysql_query (&mysql, "show slave status") != 0) {
+ error = strdup(mysql_error(&mysql));
mysql_close (&mysql);
- die (STATE_CRITICAL, _("slave query error: %s\n"), mysql_error (&mysql));
+ die (STATE_CRITICAL, _("slave query error: %s\n"), error);
}
/* store the result */
if ( (res = mysql_store_result (&mysql)) == NULL) {
+ error = strdup(mysql_error(&mysql));
mysql_close (&mysql);
- die (STATE_CRITICAL, _("slave store_result error: %s\n"), mysql_error (&mysql));
+ die (STATE_CRITICAL, _("slave store_result error: %s\n"), error);
+ }
+
+ /* Check there is some data */
+ if (mysql_num_rows(res) == 0) {
+ mysql_close(&mysql);
+ die (STATE_WARNING, "%s\n", _("No slaves defined"));
}
/* fetch the first row */
if ( (row = mysql_fetch_row (res)) == NULL) {
+ error = strdup(mysql_error(&mysql));
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"), error);
}
if (mysql_field_count (&mysql) == 12) {
index b29c5c6adeb77b44b85cc1986f3a9a211c715b85..764db72c1ddda7dbaf414cd29b3944faa336e1f5 100644 (file)
--- a/plugins/t/check_mysql.t
+++ b/plugins/t/check_mysql.t
plan skip_all => "check_mysql not compiled" unless (-x "check_mysql");
-plan tests => 3;
-
-my $failureOutput = '/Access denied for user /';
-my $mysqlserver = getTestParameter( "mysql_server", "NP_MYSQL_SERVER", undef,
- "A MySQL Server");
-my $mysql_login_details = getTestParameter( "mysql_login_details", "MYSQL_LOGIN_DETAILS", undef,
- "Command line parameters to specify login access");
+plan tests => 7;
+
+my $bad_login_output = '/Access denied for user /';
+my $mysqlserver = getTestParameter(
+ "NP_MYSQL_SERVER",
+ "A MySQL Server with no slaves setup"
+ );
+my $mysql_login_details = getTestParameter(
+ "MYSQL_LOGIN_DETAILS",
+ "Command line parameters to specify login access",
+ "-u user -ppw",
+ );
+my $with_slave = getTestParameter(
+ "NP_MYSQL_WITH_SLAVE",
+ "MySQL server with slaves setup"
+ );
+my $with_slave_login = getTestParameter(
+ "NP_MYSQL_WITH_SLAVE_LOGIN",
+ "Login details for server with slave",
+ "-uroot -ppw"
+ );
my $result;
-$result = NPTest->testCmd("./check_mysql -H $mysqlserver $mysql_login_details");
-cmp_ok( $result->return_code, '==', 0, "Login okay");
+SKIP: {
+ skip "No mysql server defined", 5 unless $mysqlserver;
+ $result = NPTest->testCmd("./check_mysql -H $mysqlserver $mysql_login_details");
+ cmp_ok( $result->return_code, '==', 0, "Login okay");
+
+ $result = NPTest->testCmd("./check_mysql -H $mysqlserver -u dummy");
+ cmp_ok( $result->return_code, '==', 2, "Login failure");
+ like( $result->output, $bad_login_output, "Expected login failure message");
+
+ $result = NPTest->testCmd("./check_mysql -S -H $mysqlserver $mysql_login_details");
+ cmp_ok( $result->return_code, "==", 1, "No slaves defined" );
+ like( $result->output, "/No slaves defined/", "Correct error message");
+}
-$result = NPTest->testCmd("./check_mysql -H $mysqlserver -u dummy");
-cmp_ok( $result->return_code, '==', 2, "Login expected failure");
-like( $result->output, $failureOutput, "Error string as expected");
+SKIP: {
+ skip "No mysql server with slaves defined", 2 unless $with_slave;
+ $result = NPTest->testCmd("./check_mysql -H $with_slave $with_slave_login");
+ cmp_ok( $result->return_code, '==', 0, "Login okay");
+ $result = NPTest->testCmd("./check_mysql -S -H $with_slave $with_slave_login");
+ cmp_ok( $result->return_code, "==", 0, "Slaves okay" );
+}