bundlewrap/bundles/smartd/metadata.py
Franziska Kunsmann cee2a41771
All checks were successful
kunsi/bundlewrap/pipeline/head This commit looks good
items/zfs_pool: rewrite item to support all kinds of zfs pools
2021-07-17 18:12:57 +02:00

82 lines
1.8 KiB
Python

defaults = {
'apt': {
'packages': {
'smartmontools': {},
'nvme-cli': {},
},
},
'icinga2_api': {
'smartd': {
'services': {
'SMARTD PROCESS': {
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_systemd_unit smartd',
},
},
},
},
}
@metadata_reactor.provides(
'smartd/disks',
)
def zfs_disks_to_metadata(metadata):
disks = set()
for config in metadata.get('zfs/pools', {}).values():
for option in config:
if option.get('type', '') in {'log', 'cache'}:
continue
for disk in option['devices']:
disks.add(disk)
return {
'smartd': {
'disks': disks,
},
}
@metadata_reactor.provides(
'icinga2_api/smartd/services',
)
def icinga(metadata):
services = {}
for disk in metadata.get('smartd/disks', set()):
services[f'SMART STATUS {disk}'] = {
'command_on_monitored_host': f'sudo /usr/local/share/icinga/plugins/check_smart -d {disk} -i auto',
'vars.notification.mail': True,
}
return {
'icinga2_api': {
'smartd': {
'services': services,
},
},
}
@metadata_reactor.provides(
'telegraf/input_plugins/builtin/smart',
)
def telegraf(metadata):
if not node.has_bundle('telegraf'):
raise DoNotRunAgain
if metadata.get('smartd/disks', {}):
return {
'telegraf': {
'input_plugins': {
'builtin': {
'smart': [{
'devices': list(sorted(metadata.get('smartd/disks'))),
}],
},
},
},
}
return {}