2023-07-13 19:30:49 +00:00
|
|
|
from re import search
|
|
|
|
|
2020-11-29 11:07:27 +00:00
|
|
|
defaults = {
|
|
|
|
'apt': {
|
|
|
|
'packages': {
|
2022-02-18 21:37:07 +00:00
|
|
|
'smartmontools': {
|
|
|
|
'needed_by': {
|
2023-07-13 19:30:29 +00:00
|
|
|
'svc_systemd:smartmontools',
|
2022-02-18 21:37:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'nvme-cli': {
|
|
|
|
'needed_by': {
|
2023-07-13 19:30:29 +00:00
|
|
|
'svc_systemd:smartmontools',
|
2022-02-18 21:37:07 +00:00
|
|
|
},
|
|
|
|
},
|
2020-11-29 11:07:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'icinga2_api': {
|
|
|
|
'smartd': {
|
|
|
|
'services': {
|
|
|
|
'SMARTD PROCESS': {
|
2023-07-13 19:30:29 +00:00
|
|
|
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_systemd_unit smartmontools',
|
2020-11-29 11:07:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-08-07 08:16:07 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-11-29 11:07:27 +00:00
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'smartd/disks',
|
|
|
|
)
|
2020-11-29 11:07:27 +00:00
|
|
|
def zfs_disks_to_metadata(metadata):
|
|
|
|
disks = set()
|
|
|
|
|
2021-07-17 16:09:35 +00:00
|
|
|
for config in metadata.get('zfs/pools', {}).values():
|
2021-08-17 16:09:51 +00:00
|
|
|
for option in config['when_creating']['config']:
|
2021-07-17 16:09:35 +00:00
|
|
|
if option.get('type', '') in {'log', 'cache'}:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for disk in option['devices']:
|
2024-02-25 13:45:47 +00:00
|
|
|
if search(r'p([0-9]+)$', disk) or disk.startswith('/dev/mapper/'):
|
2023-07-13 19:30:49 +00:00
|
|
|
continue
|
|
|
|
|
2021-07-17 16:09:35 +00:00
|
|
|
disks.add(disk)
|
2020-11-29 11:07:27 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'smartd': {
|
|
|
|
'disks': disks,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'icinga2_api/smartd/services',
|
|
|
|
)
|
2020-11-29 11:07:27 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
2021-08-15 14:22:34 +00:00
|
|
|
@metadata_reactor.provides(
|
2023-07-13 19:31:11 +00:00
|
|
|
'systemd-timers/timers',
|
2021-08-15 14:22:34 +00:00
|
|
|
)
|
|
|
|
def monthly_long_test(metadata):
|
2023-07-13 19:31:11 +00:00
|
|
|
timers = {}
|
2021-08-15 14:22:34 +00:00
|
|
|
|
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',
|
|
|
|
}
|
2021-08-15 14:22:34 +00:00
|
|
|
|
|
|
|
return {
|
2023-07-13 19:31:11 +00:00
|
|
|
'systemd-timers': {
|
|
|
|
'timers': timers,
|
2021-08-15 14:22:34 +00:00
|
|
|
},
|
|
|
|
}
|