From ed2bb66e3e645488577c752aaa343d45cc60d307 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Thu, 16 Sep 2021 19:30:36 +0200 Subject: [PATCH] bundles/basic: add links to icinga, grafana and nginx vhosts to login message --- bundles/basic/files/motd | 1 - bundles/basic/items.py | 56 +++++++++++++++++++++++++++++++++++++- bundles/users/files/bashrc | 7 +++++ 3 files changed, 62 insertions(+), 2 deletions(-) delete mode 100644 bundles/basic/files/motd diff --git a/bundles/basic/files/motd b/bundles/basic/files/motd deleted file mode 100644 index 77de5e9..0000000 --- a/bundles/basic/files/motd +++ /dev/null @@ -1 +0,0 @@ -This system is managed using bundlewrap. diff --git a/bundles/basic/items.py b/bundles/basic/items.py index c414fe5..b466263 100644 --- a/bundles/basic/items.py +++ b/bundles/basic/items.py @@ -1,3 +1,8 @@ +from inspect import cleandoc +from uuid import UUID + +from bundlewrap.utils.text import italic + # TODO support non-systemd systems files = { @@ -13,7 +18,9 @@ files = { '/etc/htoprc.global': { 'source': 'htoprc', }, - '/etc/motd': {}, + '/etc/motd': { + 'content': '', + }, } locale_needs = set() @@ -34,3 +41,50 @@ actions = { 'command': 'locale-gen', }, } + +description = [] + +if not node.metadata.get('icinga_options/exclude_from_monitoring', False): + description.append('icingaweb2: https://icinga.kunsmann.eu/monitoring/host/show?host={}'.format(node.name)) + +if node.has_bundle('telegraf'): + description.append('Grafana: https://grafana.kunsmann.eu/d/{}'.format(UUID(int=node.magic_number).hex[:10])) + +if ( + not node.metadata.get('icinga_options/exclude_from_monitoring', False) or + node.has_bundle('telegraf') +): + description.append('') # divider line + +if node.metadata.get('nginx/vhosts', {}): + description.append('nginx vhosts:') + + for vname, vconfig in sorted(node.metadata.get('nginx/vhosts', {}).items()): + if vconfig.get('ssl', 'letsencrypt') is not None: + proto = 'https' + else: + proto = 'http' + + domain = vconfig.get('domain', vname) + + description.append(' {}: {}://{}{}'.format( + vname, + proto, + domain, + vconfig.get('website_check_path', '/'), + )) + + if node.metadata.get('description', []): + description.append('') # divider line + +for line in node.metadata.get('description', []): + description.append('# {}'.format(italic(line))) + +if description: + files['/etc/node.description'] = { + 'content': '\n'.join(description) + '\n', + } +else: + files['/etc/node.description'] = { + 'delete': True, + } diff --git a/bundles/users/files/bashrc b/bundles/users/files/bashrc index 00e5ead..c04fed1 100644 --- a/bundles/users/files/bashrc +++ b/bundles/users/files/bashrc @@ -21,6 +21,13 @@ case $TERM in ;; esac +if [[ -f "/etc/node.description" ]] +then + echo + cat "/etc/node.description" + echo +fi + uptime last | grep 'still logged in'