2021-05-02 08:44:50 +00:00
|
|
|
from itertools import count
|
2021-05-02 15:49:40 +00:00
|
|
|
from os import listdir
|
|
|
|
from os.path import isdir, isfile, join
|
2021-05-02 08:44:50 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from uuid import UUID
|
|
|
|
|
|
|
|
from bundlewrap.metadata import metadata_to_json
|
|
|
|
|
|
|
|
for row in Path(join(repo.path, 'bundles', 'grafana', 'dashboard-rows')).rglob("*.py"):
|
|
|
|
with open(row, 'r') as f:
|
|
|
|
exec(f.read())
|
|
|
|
|
|
|
|
directories = {
|
2021-07-04 18:06:35 +00:00
|
|
|
# Don't ask me why these permissions are that weird. It's what the
|
|
|
|
# debian package sets them to after upgrades.
|
2021-05-02 08:44:50 +00:00
|
|
|
'/etc/grafana/provisioning/dashboards': {
|
2021-05-15 05:31:27 +00:00
|
|
|
'group': 'grafana',
|
2021-05-02 08:44:50 +00:00
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
'/etc/grafana/provisioning/datasources': {
|
2021-05-15 05:31:27 +00:00
|
|
|
'group': 'grafana',
|
2021-05-02 08:44:50 +00:00
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
'/etc/grafana/provisioning/notifiers': {
|
2021-05-15 05:31:27 +00:00
|
|
|
'group': 'grafana',
|
2021-05-02 08:44:50 +00:00
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
'/etc/grafana/provisioning/plugins': {
|
2021-05-15 05:31:27 +00:00
|
|
|
'group': 'grafana',
|
2021-05-02 08:44:50 +00:00
|
|
|
'purge': True,
|
|
|
|
},
|
|
|
|
'/var/lib/grafana/dashboards': {
|
2021-08-07 05:03:15 +00:00
|
|
|
'owner': 'grafana',
|
2021-05-15 05:31:27 +00:00
|
|
|
'group': 'grafana',
|
2021-05-02 08:44:50 +00:00
|
|
|
'purge': True,
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
files = {
|
|
|
|
'/etc/grafana/grafana.ini': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': node.metadata['grafana'],
|
2021-05-15 05:31:27 +00:00
|
|
|
'group': 'grafana',
|
2021-05-02 08:44:50 +00:00
|
|
|
'mode': '0640',
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'/etc/grafana/provisioning/dashboards/bundlewrap.yaml': {
|
|
|
|
'source': 'dashboards.yaml',
|
2021-05-15 05:31:27 +00:00
|
|
|
'group': 'grafana',
|
2021-05-02 08:44:50 +00:00
|
|
|
'mode': '0640',
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd = {
|
|
|
|
'grafana-server': {
|
|
|
|
'needs': {
|
|
|
|
'file:/etc/grafana/grafana.ini',
|
|
|
|
'pkg_apt:grafana',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
### dashboard management starts here
|
|
|
|
for rnode in repo.nodes:
|
|
|
|
if not rnode.has_bundle('telegraf'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
panel_id = count(start=1)
|
|
|
|
dashboard = {
|
|
|
|
'title': rnode.name,
|
|
|
|
'uid': UUID(int=rnode.magic_number).hex[:10],
|
|
|
|
|
|
|
|
'editable': False,
|
|
|
|
'graphTooltip': 1,
|
2021-05-02 17:57:32 +00:00
|
|
|
'refresh': '1m',
|
2021-05-02 08:44:50 +00:00
|
|
|
'schemaVersion': 12,
|
|
|
|
'style': 'dark',
|
|
|
|
'tags': {'bw'},
|
|
|
|
'time': {
|
|
|
|
'from': 'now-1d',
|
|
|
|
'to': 'now'
|
|
|
|
},
|
|
|
|
'version': 1,
|
|
|
|
|
|
|
|
'rows': [
|
|
|
|
dashboard_row_cpu(panel_id, rnode),
|
|
|
|
dashboard_row_ip_traffic(panel_id, rnode),
|
|
|
|
dashboard_row_memory(panel_id, rnode),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2021-10-18 17:42:27 +00:00
|
|
|
if rnode.has_bundle('ipmitool'):
|
|
|
|
dashboard['rows'].append(dashboard_row_ipmitool(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('ipmitool')
|
|
|
|
elif rnode.has_bundle('lm-sensors'):
|
2021-05-19 16:46:22 +00:00
|
|
|
dashboard['rows'].append(dashboard_row_sensors(panel_id, rnode))
|
2021-06-05 10:23:09 +00:00
|
|
|
dashboard['tags'].add('lm-sensors')
|
2021-05-19 16:46:22 +00:00
|
|
|
|
|
|
|
dashboard['rows'].append(dashboard_row_disk_space(panel_id, rnode))
|
|
|
|
dashboard['rows'].append(dashboard_row_disk_iops(panel_id, rnode))
|
|
|
|
|
2021-05-02 09:34:55 +00:00
|
|
|
if rnode.has_bundle('nginx'):
|
|
|
|
dashboard['rows'].append(dashboard_row_nginx(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('nginx')
|
|
|
|
|
2021-05-02 09:55:34 +00:00
|
|
|
if rnode.has_bundle('postfix'):
|
|
|
|
dashboard['rows'].append(dashboard_row_postfix(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('postfix')
|
|
|
|
|
2021-08-21 05:47:24 +00:00
|
|
|
if rnode.has_bundle('dovecot'):
|
|
|
|
dashboard['rows'].append(dashboard_row_dovecot(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('dovecot')
|
|
|
|
|
2021-08-23 20:19:31 +00:00
|
|
|
if rnode.has_bundle('rspamd'):
|
|
|
|
dashboard['rows'].append(dashboard_row_rspamd(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('rspamd')
|
|
|
|
|
2021-05-02 11:09:01 +00:00
|
|
|
if rnode.has_bundle('postgresql'):
|
|
|
|
dashboard['rows'].append(dashboard_row_postgresql(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('postgresql')
|
|
|
|
|
2021-05-02 11:55:41 +00:00
|
|
|
if rnode.has_bundle('wireguard'):
|
|
|
|
dashboard['rows'].append(dashboard_row_wireguard(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('wireguard')
|
|
|
|
|
2021-06-25 18:04:30 +00:00
|
|
|
if rnode.has_bundle('zfs'):
|
|
|
|
dashboard['rows'].append(dashboard_row_zfs(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('zfs')
|
|
|
|
|
2021-07-23 17:34:55 +00:00
|
|
|
if rnode.has_bundle('unbound'):
|
|
|
|
dashboard['rows'].append(dashboard_row_unbound(panel_id, rnode))
|
|
|
|
dashboard['tags'].add('unbound')
|
|
|
|
|
2021-05-02 08:44:50 +00:00
|
|
|
files[f'/var/lib/grafana/dashboards/{rnode.name}.json'] = {
|
2021-07-04 18:06:35 +00:00
|
|
|
'owner': 'grafana',
|
|
|
|
'group': 'grafana',
|
2021-05-02 08:44:50 +00:00
|
|
|
# use metadata_to_json, because this supports sets
|
|
|
|
'content': metadata_to_json(dashboard),
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
}
|
2021-05-02 15:49:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
additional_path = join(repo.path, 'data', 'grafana', 'files', node.name, 'dashboards')
|
|
|
|
if isdir(additional_path):
|
|
|
|
for file in listdir(additional_path):
|
|
|
|
if not isfile(join(additional_path, file)) or file.startswith('.') or file.startswith('_'):
|
|
|
|
continue
|
|
|
|
|
|
|
|
files[f'/var/lib/grafana/dashboards/{file}'] = {
|
2021-05-15 05:31:27 +00:00
|
|
|
'owner': 'grafana',
|
|
|
|
'group': 'grafana',
|
2021-05-02 15:49:40 +00:00
|
|
|
'source': join(node.name, 'dashboards', file),
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:grafana-server:restart',
|
|
|
|
},
|
|
|
|
}
|