]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/influx: modify module database check to not require admin privileges
authorBenjeman Meekhof <bmeekhof@users.noreply.github.com>
Tue, 3 Oct 2017 20:30:43 +0000 (16:30 -0400)
committerBenjeman Meekhof <bmeekhof@users.noreply.github.com>
Wed, 4 Oct 2017 14:03:56 +0000 (10:03 -0400)
- 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 <bmeekhof@umich.edu>
doc/mgr/influx.rst
src/pybind/mgr/influx/module.py

index bdb579dd2b09a36cdce0707cdfd46baf510f27ce..37aa5cd63434d9c0ac73ee4625ed089c31685f1e 100644 (file)
@@ -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
     
 
index ca18f6e2117efce0070e02bea0099522f4cc1b2f..5d524c4ed232ab81aeca6e91ef73b8295f87cff0 100644 (file)
@@ -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
+