From: Benjeman Meekhof Date: Tue, 3 Oct 2017 20:30:43 +0000 (-0400) Subject: mgr/influx: modify module database check to not require admin privileges X-Git-Tag: v13.0.1~599^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=06d7d37c7b9a8c3f4435eff04b6f4934be5e676f;p=ceph.git mgr/influx: modify module database check to not require admin privileges - existing check tried to list all DB and fails even if DB exists if user is not admin level - still tries to create database if not found and user has privs Signed-off-by: Benjeman Meekhof --- diff --git a/doc/mgr/influx.rst b/doc/mgr/influx.rst index bdb579dd2b09..37aa5cd63434 100644 --- a/doc/mgr/influx.rst +++ b/doc/mgr/influx.rst @@ -51,7 +51,7 @@ For example, a typical configuration might look like this: Additional optional configuration settings are: :interval: Time between reports to InfluxDB. Default 5 seconds. -:database: InfluxDB database name. Default "ceph" +:database: InfluxDB database name. Default "ceph". You will need to create this database and grant write privileges to the configured username or the username must have admin privileges to create it. :port: InfluxDB server port. Default 8086 diff --git a/src/pybind/mgr/influx/module.py b/src/pybind/mgr/influx/module.py index ca18f6e2117e..5d524c4ed232 100644 --- a/src/pybind/mgr/influx/module.py +++ b/src/pybind/mgr/influx/module.py @@ -9,6 +9,7 @@ from mgr_module import PERFCOUNTER_HISTOGRAM try: from influxdb import InfluxDBClient + from influxdb.exceptions import InfluxDBClientError except ImportError: InfluxDBClient = None @@ -112,13 +113,17 @@ class Module(MgrModule): password = self.get_config("password", default="") client = InfluxDBClient(host, port, username, password, database) - databases_avail = client.get_list_database() - if database not in databases_avail: - self.log.info("Creating database '{0}'".format(database)) - client.create_database(database) - client.write_points(self.get_df_stats(), 'ms') - client.write_points(self.get_daemon_stats(), 'ms') + # using influx client get_list_database requires admin privs, instead we'll catch the not found exception and inform the user if db can't be created + try: + client.write_points(self.get_df_stats(), 'ms') + client.write_points(self.get_daemon_stats(), 'ms') + except InfluxDBClientError as e: + if e.code == 404: + self.log.info("Database '{0}' not found, trying to create (requires admin privs). You can also create manually and grant write privs to user '{1}'".format(database,username)) + client.create_database(database) + else: + raise def shutdown(self): self.log.info('Stopping influx module') @@ -155,4 +160,4 @@ class Module(MgrModule): interval = 5 self.log.debug("sleeping for %d seconds",interval) self.event.wait(interval) - \ No newline at end of file +