From: Simon J Mudd Date: Mon, 1 Dec 2014 23:26:20 +0000 (+0100) Subject: Add checks for access to tables which may not be selectable X-Git-Url: http://git.iain.cx/?p=pstop.git;a=commitdiff_plain;h=c427814304da3af8e1ef51199aaca5c44304ed83;hp=fee828471a2ac86d4cc8f4982d444a9d4a9a0344 Add checks for access to tables which may not be selectable --- diff --git a/main.go b/main.go index 4825729..662743e 100644 --- a/main.go +++ b/main.go @@ -83,16 +83,36 @@ func usage() { // rather than giving an error message if the requires P_S tables can't // be found. func validate_mysql_version(dbh *sql.DB) error { - lib.Logger.Println("validate_mysql_version()") + var tables = [...]string{ + "performance_schema.file_summary_by_instance", + "performance_Schema.table_io_waits_summary_by_table", + "performance_schema.table_lock_waits_summary_by_table", + } - _, mysql_version := lib.SelectGlobalVariableByVariableName(dbh, "VERSION") + lib.Logger.Println("validate_mysql_version()") + lib.Logger.Println("- Getting MySQL version") + err, mysql_version := lib.SelectGlobalVariableByVariableName(dbh, "VERSION") + if err != nil { + return err + } lib.Logger.Println("- mysql_version: '" + mysql_version + "'") + if !re_valid_version.MatchString(mysql_version) { err := errors.New(lib.MyName() + " does not work with MySQL version " + mysql_version) return err } - lib.Logger.Println("- MySQL version is valid, continuing") + lib.Logger.Println("OK: MySQL version is valid, continuing") + + lib.Logger.Println("Checking access to required tables:") + for i := range tables { + if err := lib.CheckTableAccess(dbh, tables[i]); err == nil { + lib.Logger.Println("OK: " + tables[i] + " found") + } else { + return err + } + } + lib.Logger.Println("OK: all table checks passed") return nil }