bundlewrap/bundles/zfs/metadata.py

165 lines
5.3 KiB
Python

import re
defaults = {
'apt': {
'packages': {
'linux-headers-amd64': {
'needed_by': {
'pkg_apt:zfs-dkms',
},
},
'zfs-dkms': {
'needed_by': {
'pkg_apt:zfs-zed',
'pkg_apt:zfsutils-linux',
},
},
'zfs-zed': {
'needed_by': {
'zfs_dataset:',
'zfs_pool:',
},
},
'zfsutils-linux': {
'needed_by': {
'pkg_apt:zfs-zed',
'zfs_dataset:',
'zfs_pool:',
},
},
'parted': {
'needed_by': {
'zfs_pool:',
},
},
},
'repos': {
'backports': {
'install_gpg_key': False, # default debian signing key
'items': [
'deb http://deb.debian.org/debian {os_release}-backports main',
],
},
},
},
'cron': {
'zfs-auto-snapshot-daily': '0 0 * * * root /usr/local/sbin/zfs-auto-snapshot daily',
'zfs-auto-snapshot-hourly': '0 * * * * root /usr/local/sbin/zfs-auto-snapshot hourly',
'zfs-auto-snapshot-monthly': '0 0 1 * * root /usr/local/sbin/zfs-auto-snapshot monthly',
'zfs-auto-snapshot-weekly': '0 0 * * 7 root /usr/local/sbin/zfs-auto-snapshot weekly',
},
'zfs': {
'datasets': {},
'pools': {},
'snapshots': {
# 'backup': {
# 'enabled': True,
# 'filesystems_with_snapshot': {},
# },
'retain_defaults': {
'hourly': 24,
'daily': 7,
'weekly': 2,
'monthly': 1,
},
},
},
}
if node.has_bundle('sshmon'):
defaults.update({
'icinga2_api': {
'zfs': {
'services': {
'ZFS AUTO SNAPSHOT': {
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zfs_auto_snapshot',
},
'ZFS MOUNTED VOLUMES': {
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zfs_volumes',
'vars.notification.mail': True,
},
'ZFS OLD SNAPSHOTS': {
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zfs_old_snapshots',
}
},
},
},
})
@metadata_reactor
def zfs_scrub_cronjob(metadata):
when = metadata.get('zfs/scrub/cron', '{} 0 * * sun'.format((node.magic_number % 60)))
return {
'cron': {
'zfs-scrub': '{} root /usr/lib/zfs-linux/scrub'.format(when),
},
}
# TODO
#@metadata_reactor
#def zfs_snapshot_backup(metadata):
# if metadata.get('zfs/snapshots/backup/enabled'):
# # Collect all filesystems/datasets (e.g., "tank/mysql") which
# # are configured for (local) snapshots. For each of them, store
# # the mountpoint. This information will be used primarily by
# # "/usr/local/sbin/zfs-backup-snapshot", but may also be used by
# # other bundles (think backup tools).
# #
# # In other words, this API allows other bundles to check whether
# # a path belongs to a ZFS dataset with snapshots enabled.
#
# filesystems = {}
#
# if metadata.get('zfs/snapshots/snapshot_only', None) is not None:
# for name in metadata.get('zfs/snapshots/snapshot_only'):
# attrs = metadata.get('zfs/datasets')[name]
# if attrs.get('mountpoint') not in (None, "none"):
# filesystems[name] = attrs['mountpoint']
# else:
# for name, attrs in metadata.get('zfs/datasets').items():
# if attrs.get('mountpoint') not in (None, "none"):
# filesystems[name] = attrs['mountpoint']
#
# for pattern in metadata.get('zfs/snapshots/snapshot_never', set()):
# filesystems = {k: v for k, v in filesystems.items() if not re.search(pattern, k)}
#
# return {
# 'zfs': {
# 'snapshots': {
# 'backup': {
# 'filesystems_with_snapshot': filesystems,
# },
# },
# },
# }
# else:
# return {}
@metadata_reactor
def monitoring(metadata):
if not node.has_bundle('sshmon'):
raise DoNotRunAgain
services = {}
for poolname, pool_options in metadata.get('zfs/pools').items():
services['ZFS ZPOOL ONLINE {}'.format(poolname)] = {
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zpool_online {}'.format(poolname),
'vars.notification.mail': True,
}
services['ZFS ZPOOL SPACE ' + poolname] = {
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zpool_space {} 90'.format(poolname),
'vars.notification.mail': True,
}
return {
'icinga2_api': {
'zfs': {
'services': services,
},
},
}