-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[grafana] conf and logs from snap added #3289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,29 +19,53 @@ 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" | ||
|
||
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", | ||
]) | ||
add_cmds = [ | ||
f'{grafana_cli} plugins ls', | ||
f'{grafana_cli} plugins list-remote', | ||
'snap info grafana' if self._is_snap else None, | ||
f'{grafana_cli} -v' if not self._is_snap else None, | ||
'grafana-server -v' if not self._is_snap else None | ||
] | ||
self.add_cmd_output(list(filter(None, add_cmds))) | ||
|
||
log_file_pattern = "*.log*" if self.get_option("all_logs") else "*.log" | ||
|
||
self.add_copy_spec([ | ||
"/etc/grafana/", | ||
"/etc/sysconfig/grafana-server", | ||
log_path + log_file_pattern, | ||
config_path, | ||
"/etc/sysconfig/grafana-server" if not self._is_snap else None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
]) | ||
|
||
def postproc(self): | ||
protect_keys = [ | ||
"admin_password", "secret_key" | ||
"admin_password", | ||
"secret_key", | ||
"password", | ||
"client_secret" | ||
Comment on lines
-42
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1, that helps also to non-snap instances. |
||
] | ||
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*********") | ||
regexp = r"((?m)^\s*(%s)\s*=\s*)(.*)" % "|".join(protect_keys) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you remove the |
||
self.do_path_regex_sub(inifile, regexp, r"\1*********") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these commands not work with a snap installation? Or are they not present. Non-present commands are handled gracefully by
Plugin
, so we don't need to set these toNone
and filter later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise we don't need to gate the
snap info
command, we can just tuck anadd_cmd_output()
under the conditional on line 30.