bundlewrap/bundles/smartd/metadata.py

108 lines
2.5 KiB
Python
Raw Normal View History

from re import search
defaults = {
'apt': {
'packages': {
'smartmontools': {
'needed_by': {
'svc_systemd:smartmontools',
},
},
'nvme-cli': {
'needed_by': {
'svc_systemd:smartmontools',
},
},
},
},
'icinga2_api': {
'smartd': {
'services': {
'SMARTD PROCESS': {
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_systemd_unit smartmontools',
},
},
},
},
}
if node.has_bundle('telegraf'):
defaults['telegraf'] = {
'input_plugins': {
'exec': {
'smartd': {
'commands': ['sudo /usr/local/sbin/telegraf-smartd'],
'data_format': 'influx',
'timeout': '5s',
},
},
},
'sudo_commands': {
'/usr/local/sbin/telegraf-smartd',
},
}
@metadata_reactor.provides(
'smartd/disks',
)
def zfs_disks_to_metadata(metadata):
disks = set()
for config in metadata.get('zfs/pools', {}).values():
2021-08-17 16:09:51 +00:00
for option in config['when_creating']['config']:
if option.get('type', '') in {'log', 'cache'}:
continue
for disk in option['devices']:
if search(r'p([0-9]+)$', disk):
continue
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,
},
},
}
2021-04-23 17:31:28 +00:00
@metadata_reactor.provides(
2023-07-13 19:31:11 +00:00
'systemd-timers/timers',
)
def monthly_long_test(metadata):
2023-07-13 19:31:11 +00:00
timers = {}
2023-07-13 19:31:11 +00:00
for day, disk in enumerate(sorted(metadata.get('smartd/disks', set())), start=1):
timers[f'smartd{disk.replace("/", "-")}'] = {
'command': f'/usr/sbin/smartctl --test=long {disk}',
'when': f'*-*-{day} 03:00:00 UTC',
}
return {
2023-07-13 19:31:11 +00:00
'systemd-timers': {
'timers': timers,
},
}