2021-02-12 19:37:36 +00:00
|
|
|
#import re
|
2020-08-29 19:10:59 +00:00
|
|
|
|
|
|
|
defaults = {
|
2020-10-25 15:39:35 +00:00
|
|
|
'apt': {
|
|
|
|
'packages': {
|
2020-10-31 09:11:15 +00:00
|
|
|
'zfs-dkms': {
|
2020-10-25 15:39:35 +00:00
|
|
|
'needed_by': {
|
|
|
|
'pkg_apt:zfs-zed',
|
|
|
|
'pkg_apt:zfsutils-linux',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'zfs-zed': {
|
|
|
|
'needed_by': {
|
2022-02-12 10:24:50 +00:00
|
|
|
'svc_systemd:zfs-zed',
|
2020-10-25 15:39:35 +00:00
|
|
|
'zfs_dataset:',
|
|
|
|
'zfs_pool:',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'zfsutils-linux': {
|
|
|
|
'needed_by': {
|
|
|
|
'pkg_apt:zfs-zed',
|
|
|
|
'zfs_dataset:',
|
|
|
|
'zfs_pool:',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'parted': {
|
|
|
|
'needed_by': {
|
|
|
|
'zfs_pool:',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-13 07:37:00 +00:00
|
|
|
'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,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-12 10:24:50 +00:00
|
|
|
'pacman': {
|
2022-05-16 08:52:14 +00:00
|
|
|
'no_extract': {
|
|
|
|
'etc/sudoers.d/zfs',
|
|
|
|
},
|
2022-02-12 10:24:50 +00:00
|
|
|
'packages': {
|
|
|
|
'zfs-utils': {
|
|
|
|
'needed_by': {
|
|
|
|
'svc_systemd:zfs-zed',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-02-12 10:29:26 +00:00
|
|
|
'systemd-timers': {
|
|
|
|
'timers': {
|
|
|
|
'zfs-auto-snapshot-daily': {
|
|
|
|
'when': 'daily',
|
|
|
|
'command': '/usr/local/sbin/zfs-auto-snapshot daily',
|
|
|
|
},
|
|
|
|
'zfs-auto-snapshot-hourly': {
|
|
|
|
'when': 'hourly',
|
|
|
|
'command': '/usr/local/sbin/zfs-auto-snapshot hourly',
|
|
|
|
},
|
|
|
|
'zfs-auto-snapshot-monthly': {
|
|
|
|
'when': 'monthly',
|
|
|
|
'command': '/usr/local/sbin/zfs-auto-snapshot monthly',
|
|
|
|
},
|
|
|
|
'zfs-auto-snapshot-weekly': {
|
|
|
|
'when': 'weekly',
|
|
|
|
'command': '/usr/local/sbin/zfs-auto-snapshot weekly',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-08-29 19:10:59 +00:00
|
|
|
'zfs': {
|
|
|
|
'datasets': {},
|
|
|
|
'pools': {},
|
|
|
|
'snapshots': {
|
|
|
|
'retain_defaults': {
|
|
|
|
'hourly': 24,
|
|
|
|
'daily': 7,
|
|
|
|
'weekly': 2,
|
|
|
|
'monthly': 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-07-01 16:19:24 +00:00
|
|
|
if node.os == 'debian' and node.os_version[0] <= 10:
|
|
|
|
defaults['apt']['repos'] = {
|
|
|
|
'backports': {
|
|
|
|
'install_gpg_key': False, # default debian signing key
|
|
|
|
'items': {
|
|
|
|
'deb http://deb.debian.org/debian {os_release}-backports main',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-04-23 17:31:28 +00:00
|
|
|
if node.has_bundle('telegraf'):
|
|
|
|
defaults['telegraf'] = {
|
|
|
|
'input_plugins': {
|
|
|
|
'builtin': {
|
|
|
|
'zfs': [{
|
|
|
|
'poolMetrics': True,
|
|
|
|
}],
|
|
|
|
},
|
2021-06-25 18:04:30 +00:00
|
|
|
'exec': {
|
|
|
|
'zfs-dataset': {
|
|
|
|
'commands': ['sudo /usr/local/sbin/telegraf-per-dataset'],
|
|
|
|
'data_format': 'influx',
|
|
|
|
'timeout': '5s',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'sudo_commands': {
|
|
|
|
'/usr/local/sbin/telegraf-per-dataset',
|
2021-04-23 17:31:28 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-30 10:30:32 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'pacman/packages',
|
|
|
|
)
|
|
|
|
def packages(metadata):
|
|
|
|
if node.metadata.get('pacman/linux-lts', False):
|
|
|
|
pkgname = 'zfs-linux-lts'
|
|
|
|
else:
|
|
|
|
pkgname = 'zfs-linux'
|
|
|
|
return {
|
|
|
|
'pacman': {
|
|
|
|
'packages': {
|
|
|
|
pkgname: {
|
|
|
|
'needed_by': {
|
|
|
|
'zfs_dataset:',
|
|
|
|
'zfs_pool:',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-05-20 10:38:27 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'apt/packages',
|
|
|
|
)
|
|
|
|
def linux_headers(metadata):
|
|
|
|
cpu_arch = metadata.get('cpu_arch', 'amd64')
|
|
|
|
|
|
|
|
return {
|
|
|
|
'apt': {
|
|
|
|
'packages': {
|
|
|
|
f'linux-headers-{cpu_arch}': {
|
|
|
|
'needed_by': {
|
|
|
|
'pkg_apt:zfs-dkms',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-04-30 10:30:32 +00:00
|
|
|
|
2022-04-03 07:48:28 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'systemd-timers/timers/zfs-scrub',
|
|
|
|
)
|
|
|
|
def scrub_timer(metadata):
|
|
|
|
scrubs = [f'zpool scrub {pool}' for pool in sorted(metadata.get('zfs/pools', {}))]
|
|
|
|
return {
|
|
|
|
'systemd-timers': {
|
|
|
|
'timers': {
|
|
|
|
'zfs-scrub': {
|
|
|
|
'when': 'Sun 02:00:00 UTC',
|
|
|
|
'command': scrubs,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-15 18:32:23 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'icinga2_api/zfs/services',
|
|
|
|
)
|
2020-08-29 19:10:59 +00:00
|
|
|
def monitoring(metadata):
|
|
|
|
if not node.has_bundle('sshmon'):
|
|
|
|
raise DoNotRunAgain
|
|
|
|
|
|
|
|
services = {}
|
|
|
|
|
2022-04-06 16:13:01 +00:00
|
|
|
if metadata.get('zfs/enable_old_snapshots_check', True):
|
|
|
|
services['ZFS OLD SNAPSHOTS'] = {
|
|
|
|
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zfs_old_snapshots',
|
2022-06-05 07:30:44 +00:00
|
|
|
'vars.sshmon_timeout': 30,
|
2022-04-06 16:13:01 +00:00
|
|
|
}
|
|
|
|
|
2021-02-12 19:37:36 +00:00
|
|
|
for poolname, _ in metadata.get('zfs/pools').items():
|
2020-08-29 19:10:59 +00:00
|
|
|
services['ZFS ZPOOL ONLINE {}'.format(poolname)] = {
|
2020-11-10 09:35:01 +00:00
|
|
|
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zpool_online {}'.format(poolname),
|
2020-11-22 07:24:44 +00:00
|
|
|
'vars.notification.mail': True,
|
2020-08-29 19:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
services['ZFS ZPOOL SPACE ' + poolname] = {
|
2020-11-22 07:24:44 +00:00
|
|
|
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_zpool_space {} 90'.format(poolname),
|
|
|
|
'vars.notification.mail': True,
|
2020-08-29 19:10:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
'icinga2_api': {
|
|
|
|
'zfs': {
|
|
|
|
'services': services,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-05-15 18:32:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
|
|
'zfs/filesystems_with_backup_snapshots',
|
|
|
|
)
|
|
|
|
def backups_with_snapshot(metadata):
|
|
|
|
backups = metadata.get('backups/paths', set())
|
|
|
|
datasets = metadata.get('zfs/datasets', {})
|
|
|
|
|
|
|
|
backups_in_zfs_datasets = {}
|
|
|
|
|
|
|
|
for path in backups:
|
|
|
|
for dname, dconfig in datasets.items():
|
|
|
|
if 'mountpoint' in dconfig:
|
|
|
|
if path[:len(dconfig['mountpoint'])] == dconfig['mountpoint']:
|
|
|
|
backups_in_zfs_datasets.setdefault(dname, set()).add(path)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'zfs': {
|
|
|
|
'filesystems_with_backup_snapshots': backups_in_zfs_datasets,
|
|
|
|
},
|
|
|
|
}
|