bundlewrap/bundles/check-mail-received/metadata.py

43 lines
1.3 KiB
Python
Raw Permalink Normal View History

2021-07-10 12:22:19 +00:00
@metadata_reactor.provides(
'cron/jobs/check-mail-received',
2021-07-10 12:22:19 +00:00
'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}'] = {
'check_command': 'check_imap_for_mail_from',
2021-07-10 12:22:19 +00:00
'check_interval': '15m',
'retry_interval': '5m',
'vars.sshmon_timeout': 30,
'vars.imap_host': config['imap_host'],
'vars.imap_user': config.get('imap_user', config['email']),
'vars.imap_pass': config['imap_pass'],
'vars.imap_from': my_mail_address,
2021-07-10 12:22:19 +00:00
}
return {
'cron': {
'jobs': {
'check-mail-received': '\n'.join(sorted(cron)),
},
2021-07-10 12:22:19 +00:00
},
'icinga2_api': {
'check-mail-received': {
'services': services,
},
},
}