2020-11-29 11:07:27 +00:00
|
|
|
defaults = {
|
|
|
|
'apt': {
|
|
|
|
'packages': {
|
|
|
|
'smartmontools': {},
|
2021-04-24 09:45:58 +00:00
|
|
|
'nvme-cli': {},
|
2020-11-29 11:07:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
'icinga2_api': {
|
|
|
|
'smartd': {
|
|
|
|
'services': {
|
|
|
|
'SMARTD PROCESS': {
|
|
|
|
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_systemd_unit smartd',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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']:
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
|
|
'telegraf/input_plugins/builtin/smart',
|
|
|
|
)
|
|
|
|
def telegraf(metadata):
|
|
|
|
if not node.has_bundle('telegraf'):
|
|
|
|
raise DoNotRunAgain
|
|
|
|
|
2021-08-15 14:22:34 +00:00
|
|
|
if metadata.get('smartd/disks', set()):
|
2021-04-23 17:31:28 +00:00
|
|
|
return {
|
|
|
|
'telegraf': {
|
|
|
|
'input_plugins': {
|
|
|
|
'builtin': {
|
|
|
|
'smart': [{
|
|
|
|
'devices': list(sorted(metadata.get('smartd/disks'))),
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return {}
|
2021-08-15 14:22:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
|
|
'cron/smartd',
|
|
|
|
)
|
|
|
|
def monthly_long_test(metadata):
|
|
|
|
lines = set()
|
|
|
|
|
|
|
|
for number, disk in enumerate(sorted(metadata.get('smartd/disks', set()))):
|
|
|
|
lines.add('0 3 {} * * root /usr/sbin/smartctl --test=long {} >/dev/null'.format(
|
|
|
|
number+1, # enumerate() starts at 0
|
|
|
|
disk,
|
|
|
|
))
|
|
|
|
|
|
|
|
return {
|
|
|
|
'cron': {
|
|
|
|
'smartd': '\n'.join(sorted(lines)),
|
|
|
|
},
|
|
|
|
}
|