|
|
e75bc7 |
From 7c12e6c994b3320ef57a13e06f5c445b6bca7935 Mon Sep 17 00:00:00 2001
|
|
|
e75bc7 |
From: "Bryn M. Reeves" <bmr@redhat.com>
|
|
|
e75bc7 |
Date: Thu, 22 Jan 2015 15:37:15 +0000
|
|
|
e75bc7 |
Subject: [PATCH] [mysql] improve handling of dbuser, dbpass and MYSQL_PWD
|
|
|
e75bc7 |
|
|
|
e75bc7 |
Make sure that the mysql plugin behaves correctly when given
|
|
|
e75bc7 |
different combinations of values for dbuser, dbpass and MYSQL_PWD.
|
|
|
e75bc7 |
|
|
|
e75bc7 |
* If dbdump is set then either dbpass or MYSQL_PWD must be set
|
|
|
e75bc7 |
* Warn if dbdump is set and dbuser or dbpass is True/False/null
|
|
|
e75bc7 |
(indicates either 'sosreport -a' or '-k mysql.dbpass')
|
|
|
e75bc7 |
|
|
|
e75bc7 |
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
|
|
|
e75bc7 |
---
|
|
|
e75bc7 |
sos/plugins/mysql.py | 24 ++++++++++++++++++++----
|
|
|
e75bc7 |
1 file changed, 20 insertions(+), 4 deletions(-)
|
|
|
e75bc7 |
|
|
|
e75bc7 |
diff --git a/sos/plugins/mysql.py b/sos/plugins/mysql.py
|
|
|
e75bc7 |
index dd899a3..8dba204 100644
|
|
|
e75bc7 |
--- a/sos/plugins/mysql.py
|
|
|
e75bc7 |
+++ b/sos/plugins/mysql.py
|
|
|
e75bc7 |
@@ -24,35 +24,51 @@ class Mysql(Plugin):
|
|
|
e75bc7 |
profiles = ('services',)
|
|
|
fc05a2 |
mysql_cnf = "/etc/my.cnf"
|
|
|
fc05a2 |
|
|
|
fc05a2 |
+ pw_warn_text = " (password visible in process listings)"
|
|
|
fc05a2 |
+
|
|
|
fc05a2 |
option_list = [
|
|
|
fc05a2 |
("dbuser", "username for database dumps", "", "mysql"),
|
|
|
fc05a2 |
- ("dbpass", "password for database dumps", "", False),
|
|
|
fc05a2 |
+ ("dbpass", "password for database dumps" + pw_warn_text, "", False),
|
|
|
e75bc7 |
("dbdump", "collect a database dump", "", False)
|
|
|
fc05a2 |
]
|
|
|
fc05a2 |
|
|
|
fc05a2 |
def setup(self):
|
|
|
fc05a2 |
super(Mysql, self).setup()
|
|
|
fc05a2 |
+
|
|
|
e75bc7 |
self.add_copy_spec([
|
|
|
fc05a2 |
self.mysql_cnf,
|
|
|
fc05a2 |
"/var/log/mysql/mysqld.log",
|
|
|
fc05a2 |
"/var/log/mariadb/mariadb.log",
|
|
|
fc05a2 |
])
|
|
|
fc05a2 |
+
|
|
|
fc05a2 |
if self.get_option("all_logs"):
|
|
|
e75bc7 |
self.add_copy_spec([
|
|
|
fc05a2 |
"/var/log/mysql*",
|
|
|
fc05a2 |
"/var/log/mariadb*"
|
|
|
fc05a2 |
])
|
|
|
fc05a2 |
+
|
|
|
fc05a2 |
if self.get_option("dbdump"):
|
|
|
fc05a2 |
+ msg = "database user name and password must be supplied"
|
|
|
fc05a2 |
+ dbdump_err = "mysql.dbdump: %s" % msg
|
|
|
fc05a2 |
+
|
|
|
fc05a2 |
dbuser = self.get_option("dbuser")
|
|
|
fc05a2 |
dbpass = self.get_option("dbpass")
|
|
|
fc05a2 |
- if isinstance(dbuser, bool) or isinstance(dbpass, bool):
|
|
|
fc05a2 |
- # sosreport -a
|
|
|
fc05a2 |
- return
|
|
|
fc05a2 |
+
|
|
|
fc05a2 |
if 'MYSQL_PWD' in os.environ:
|
|
|
fc05a2 |
dbpass = os.environ['MYSQL_PWD']
|
|
|
fc05a2 |
+
|
|
|
fc05a2 |
+ if dbuser is True or dbpass is True:
|
|
|
fc05a2 |
+ # sosreport -a or -k mysql.{dbuser,dbpass}
|
|
|
fc05a2 |
+ self.soslog.warning(dbdump_err)
|
|
|
fc05a2 |
+ return
|
|
|
fc05a2 |
+
|
|
|
fc05a2 |
if not dbpass or dbpass is False:
|
|
|
fc05a2 |
# no MySQL password
|
|
|
fc05a2 |
+ self.soslog.warning(dbdump_err)
|
|
|
fc05a2 |
return
|
|
|
fc05a2 |
+
|
|
|
fc05a2 |
+ # no need to save/restore as this variable is private to
|
|
|
fc05a2 |
+ # the mysql plugin.
|
|
|
fc05a2 |
os.environ['MYSQL_PWD'] = dbpass
|
|
|
fc05a2 |
|
|
|
fc05a2 |
opts = "--user=%s --all-databases" % dbuser
|
|
|
e75bc7 |
--
|
|
|
e75bc7 |
1.9.3
|
|
|
e75bc7 |
|