diff options
-rw-r--r-- | sos/report/plugins/grafana.py | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/sos/report/plugins/grafana.py b/sos/report/plugins/grafana.py index 4aa5668c..0bc51fd4 100644 --- a/sos/report/plugins/grafana.py +++ b/sos/report/plugins/grafana.py @@ -19,29 +19,52 @@ class Grafana(Plugin, IndependentPlugin): packages = ('grafana',) + def _is_snap_installed(self): + grafana_pkg = self.policy.package_manager.pkg_by_name('grafana') + if grafana_pkg: + return grafana_pkg['pkg_manager'] == 'snap' + return False + def setup(self): - if self.get_option("all_logs"): - self.add_copy_spec("/var/log/grafana/*.log*") + self._is_snap = self._is_snap_installed() + if self._is_snap: + grafana_cli = "grafana.grafana-cli" + log_path = "/var/snap/grafana/common/data/log/" + config_path = "/var/snap/grafana/current/conf/grafana.ini" + + self.add_cmd_output("snap info grafana") else: - self.add_copy_spec("/var/log/grafana/*.log") + grafana_cli = "grafana-cli" + log_path = "/var/log/grafana/" + config_path = "/etc/grafana/" self.add_cmd_output([ - "grafana-cli plugins ls", - "grafana-cli plugins list-remote", - "grafana-cli -v", - "grafana-server -v", + f'{grafana_cli} plugins ls', + f'{grafana_cli} plugins list-remote', + f'{grafana_cli} -v', + 'grafana-server -v', ]) + log_file_pattern = "*.log*" if self.get_option("all_logs") else "*.log" + self.add_copy_spec([ - "/etc/grafana/", + log_path + log_file_pattern, + config_path, "/etc/sysconfig/grafana-server", ]) def postproc(self): protect_keys = [ - "admin_password", "secret_key" + "admin_password", + "secret_key", + "password", + "client_secret", ] + inifile = ( + "/var/snap/grafana/current/conf/grafana.ini" + if self._is_snap + else "/etc/grafana/grafana.ini" + ) regexp = r"(^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys) - self.do_path_regex_sub("/etc/grafana/grafana.ini", - regexp, r"\1*********") + self.do_path_regex_sub(inifile, regexp, r"\1*********") |