bundlewrap/bundles/check-mail-received/metadata.py
Franziska Kunsmann 3351767d56
All checks were successful
bundlewrap/pipeline/head This commit looks good
add bundle:check-mail-received
2021-07-10 14:22:19 +02:00

41 lines
1.3 KiB
Python

@metadata_reactor.provides(
'cron/check-mail-received',
'icinga2_api/check-mail-received/services',
)
def process_metadata(metadata):
cron = set()
services = {}
my_mail_address = 'root@{}'.format(metadata.get('hostname'))
for name, config in metadata.get('check-mail-received', {}).items():
cron.add('{minute} {hour} * * * root date | mail -s "daily test mail from {node}" -r {source} {target}'.format(
minute=node.magic_number%60,
hour=node.magic_number%24,
node=node.name,
source=my_mail_address,
target=config['email'],
))
services[f'MAIL RECEIVED ON {name}'] = {
'command_on_monitored_host': repo.libs.faults.join_faults([
'/usr/local/share/icinga/plugins/check_imap_for_mail_from',
config['imap_host'],
config.get('imap_user', config['email']),
config['imap_pass'],
my_mail_address,
]),
'check_interval': '15m',
'retry_interval': '5m',
}
return {
'cron': {
'check-mail-received': '\n'.join(sorted(cron)),
},
'icinga2_api': {
'check-mail-received': {
'services': services,
},
},
}