defaults = {
    'apt': {
        'packages': {
            'build-essential': {},
            'graphviz': {},
            'libffi-dev': {},
            'libldap2-dev': {},
            'libpq-dev': {},
            'libsasl2-dev': {},
            'libssl-dev': {},
            'libxml2-dev': {},
            'libxslt1-dev': {},
            'python3-dev': {},
            'zlib1g-dev': {},
        },
    },
    'backups': {
        'paths': {
            '/opt/netbox/media',
            '/opt/netbox/scripts',
            # and database
        },
    },
    'postgresql': {
        'databases': {
            'netbox': {
                'owner': 'netbox',
            },
        },
        'roles': {
            'netbox': {
                'password': repo.vault.password_for('netbox postgresql ' + node.name),
            },
        },
    },
    'systemd-timers': {
        'timers': {
            'netbox_housekeeping': {
                'command': '/opt/netbox/venv/bin/python /opt/netbox/src/netbox/manage.py housekeeping',
                'pwd': '/opt/netbox',
                'user': 'netbox',
                'when': 'daily',
            }
        },
    },
    'zfs': {
        'datasets': {
            'tank/netbox': {},
            'tank/netbox/install': {
                'mountpoint': '/opt/netbox/src',
                'needed_by': {
                    'directory:/opt/netbox/src',
                },
            },
            'tank/netbox/media': {
                'mountpoint': '/opt/netbox/media',
                'needed_by': {
                    'directory:/opt/netbox/media',
                },
            },
            'tank/netbox/scripts': {
                'mountpoint': '/opt/netbox/scripts',
                'needed_by': {
                    'directory:/opt/netbox/scripts',
                },
            },
        },
    },
}


@metadata_reactor.provides(
    'icinga2_api/netbox/services/NETBOX UPDATE',
)
def icinga_check_for_new_release(metadata):
    return {
        'icinga2_api': {
            'netbox': {
                'services': {
                    'NETBOX UPDATE': {
                        'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_github_for_new_release netbox-community/netbox {}'.format(metadata.get('netbox/version')),
                        'vars.notification.mail': True,
                        'check_interval': '60m',
                    },
                },
            },
        },
    }


@metadata_reactor.provides(
    'nginx/vhosts/netbox',
)
def nginx(metadata):
    if not node.has_bundle('nginx'):
        raise DoNotRunAgain

    return {
        'nginx': {
            'vhosts': {
                'netbox': {
                    'domain': metadata.get('netbox/domain'),
                    'website_check_path': '/',
                    'website_check_string': 'NetBox',
                    'locations': {
                        '/': {
                            'target': 'http://127.0.0.1:22080',
                        },
                        '/static/': {
                            'alias': '/opt/netbox/src/netbox/static/',
                        },
                    },
                },
            },
        },
    }

