]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/plugins/debug.py
import 15.2.9
[ceph.git] / ceph / src / pybind / mgr / dashboard / plugins / debug.py
index d5719157bc44f7e58f2aafd87a51066b7d34a950..e4efa9c747e3b3e3c177bd57ea4b13f4776b017c 100644 (file)
@@ -21,7 +21,8 @@ class Actions(Enum):
 
 
 @PM.add_plugin  # pylint: disable=too-many-ancestors
-class Debug(SP, I.CanCherrypy, I.ConfiguresCherryPy):  # pylint: disable=too-many-ancestors
+class Debug(SP, I.CanCherrypy, I.ConfiguresCherryPy,  # pylint: disable=too-many-ancestors
+            I.Setupable, I.ConfigNotify):
     NAME = 'debug'
 
     OPTIONS = [
@@ -33,6 +34,26 @@ class Debug(SP, I.CanCherrypy, I.ConfiguresCherryPy):  # pylint: disable=too-man
         )
     ]
 
+    @no_type_check  # https://github.com/python/mypy/issues/7806
+    def _refresh_health_checks(self):
+        debug = self.get_option(self.NAME)
+        if debug:
+            self.mgr.health_checks.update({'DASHBOARD_DEBUG': {
+                'severity': 'warning',
+                'summary': 'Dashboard debug mode is enabled',
+                'detail': [
+                    'Please disable debug mode in production environments using '
+                    '"ceph dashboard {} {}"'.format(self.NAME, Actions.DISABLE.value)
+                ]
+            }})
+        else:
+            self.mgr.health_checks.pop('DASHBOARD_DEBUG', None)
+        self.mgr.refresh_health_checks()
+
+    @PM.add_hook
+    def setup(self):
+        self._refresh_health_checks()
+
     @no_type_check
     def handler(self, action):
         ret = 0
@@ -40,10 +61,11 @@ class Debug(SP, I.CanCherrypy, I.ConfiguresCherryPy):  # pylint: disable=too-man
         if action in [Actions.ENABLE.value, Actions.DISABLE.value]:
             self.set_option(self.NAME, action == Actions.ENABLE.value)
             self.mgr.update_cherrypy_config({})
+            self._refresh_health_checks()
         else:
             debug = self.get_option(self.NAME)
             msg = "Debug: '{}'".format('enabled' if debug else 'disabled')
-        return (ret, msg, None)
+        return ret, msg, None
 
     COMMANDS = [
         SP.Command(
@@ -70,3 +92,7 @@ class Debug(SP, I.CanCherrypy, I.ConfiguresCherryPy):  # pylint: disable=too-man
             'environment': 'test_suite' if self.get_option(self.NAME) else 'production',
             'error_page.default': self.custom_error_response,
         })
+
+    @PM.add_hook
+    def config_notify(self):
+        self._refresh_health_checks()