Skip to content

Commit

Permalink
[grafana] Grab data from grafana snap
Browse files Browse the repository at this point in the history
Closes: #3278

Co-authored-by: Pravesh Gaire <[email protected]>
Signed-off-by: Pravesh Gaire <[email protected]>
Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
2 people authored and TurboTurtle committed Nov 26, 2023
1 parent de853ea commit 8779206
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions sos/report/plugins/grafana.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*********")

0 comments on commit 8779206

Please sign in to comment.