diff --git a/bundles/grafana/items.py b/bundles/grafana/items.py index 2c46210..44e8ccf 100644 --- a/bundles/grafana/items.py +++ b/bundles/grafana/items.py @@ -1,3 +1,25 @@ -files['/etc/grafana/test'] = { - 'content': repo.libs.ini.dumps(repo.libs.ini.parse(c)), +assert node.has_bundle('redis') +assert node.has_bundle('postgresql') + +from shlex import quote + + +files['/etc/grafana/grafana.ini'] = { + 'content': repo.libs.ini.dumps(node.metadata.get('grafana/config')), + 'triggers': [ + 'svc_systemd:grafana-server:restart', + ] +} + +svc_systemd['grafana-server'] = { + 'needs': [ + 'pkg_apt:grafana', + ], +} + +actions['reset_grafana_admin_password'] = { + 'command': f"grafana-cli admin reset-admin-password {quote(node.metadata.get('grafana/config/security/admin_password'))}", + 'needs': [ + 'svc_systemd:grafana-server', + ], } diff --git a/bundles/grafana/metadata.py b/bundles/grafana/metadata.py index 9f30724..f307904 100644 --- a/bundles/grafana/metadata.py +++ b/bundles/grafana/metadata.py @@ -1,3 +1,5 @@ +postgres_password = repo.vault.password_for(f'{node.name} postgres role grafana') + defaults = { 'apt': { 'packages': { @@ -7,6 +9,27 @@ defaults = { 'deb https://packages.grafana.com/oss/deb stable main', ], }, + 'grafana': { + 'config': { + 'server': { + 'http_port': 3370, + }, + 'database': { + 'url': f'postgres://grafana:{postgres_password}@localhost:5432/grafana', + }, + 'remote_cache': { + 'type': 'redis', + 'connstr': 'addr=127.0.0.1:6379', + }, + 'security': { + 'admin_user': 'admin', + 'admin_password': str(repo.vault.password_for(f'{node.name} grafana admin')), + }, + 'users': { + 'allow_signup': False, + }, + }, + }, 'postgresql': { 'databases': { 'grafana': { @@ -15,7 +38,7 @@ defaults = { }, 'roles': { 'grafana': { - 'password': repo.vault.password_for(f'{node.name} postgres role grafana'), + 'password': postgres_password, }, }, }, diff --git a/nodes/home.server.py b/nodes/home.server.py index 2b3d1a2..28dd95c 100644 --- a/nodes/home.server.py +++ b/nodes/home.server.py @@ -11,6 +11,7 @@ 'grafana', 'influxdb2', 'postgresql', + 'redis', 'wireguard', 'zfs', ],