2021-03-21 10:11:49 +00:00
|
|
|
from bundlewrap.metadata import atomic
|
|
|
|
|
2020-11-07 21:31:18 +00:00
|
|
|
defaults = {
|
|
|
|
'apt': {
|
|
|
|
'packages': {
|
|
|
|
'postfix': {},
|
2021-05-23 10:24:00 +00:00
|
|
|
'python3-dnsq': {
|
|
|
|
# handled by pkg_pip
|
|
|
|
'installed': False,
|
|
|
|
},
|
2020-11-07 21:31:18 +00:00
|
|
|
},
|
|
|
|
},
|
2020-11-10 09:21:37 +00:00
|
|
|
'icinga2_api': {
|
|
|
|
'postfix': {
|
|
|
|
'services': {
|
|
|
|
'POSTFIX PROCESS': {
|
2021-06-28 17:59:54 +00:00
|
|
|
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_systemd_unit postfix' + ('' if node.os == 'arch' else '@-'),
|
2020-11-10 09:21:37 +00:00
|
|
|
},
|
|
|
|
'POSTFIX QUEUE': {
|
|
|
|
'command_on_monitored_host': 'sudo /usr/local/share/icinga/plugins/check_postfix_queue -w 20 -c 40 -d 50',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-05-23 10:24:00 +00:00
|
|
|
'pacman': {
|
|
|
|
'packages': {
|
|
|
|
'postfix': {},
|
2021-07-10 13:59:03 +00:00
|
|
|
's-nail': {},
|
2021-05-23 10:24:00 +00:00
|
|
|
},
|
|
|
|
},
|
2020-11-07 21:31:18 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 09:21:37 +00:00
|
|
|
if node.has_bundle('postfixadmin'):
|
|
|
|
defaults['icinga2_api']['postfix']['services'].update({
|
|
|
|
'SMTP CONNECT': {
|
|
|
|
'check_command': 'check_smtp',
|
2021-04-10 14:50:16 +00:00
|
|
|
'max_check_attempts': '5',
|
|
|
|
'retry_interval': '3m',
|
2020-11-22 07:24:44 +00:00
|
|
|
'vars.notification.sms': True,
|
2020-11-10 09:21:37 +00:00
|
|
|
},
|
|
|
|
'SMTP SUBMISSION CONNECT': {
|
|
|
|
'check_command': 'check_smtp',
|
2021-04-10 14:50:16 +00:00
|
|
|
'max_check_attempts': '5',
|
|
|
|
'retry_interval': '3m',
|
2021-01-02 11:26:37 +00:00
|
|
|
'vars.notification.sms': True,
|
2021-04-10 14:50:16 +00:00
|
|
|
'vars.port': '587',
|
2020-11-10 09:21:37 +00:00
|
|
|
},
|
|
|
|
})
|
2021-07-17 08:17:39 +00:00
|
|
|
|
2020-11-10 09:21:37 +00:00
|
|
|
else:
|
|
|
|
defaults['icinga2_api']['postfix']['services'].update({
|
|
|
|
'SMTP CONNECT': {
|
|
|
|
'command_on_monitored_host': '/usr/lib/nagios/plugins/check_smtp -H localhost',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-04-23 17:31:28 +00:00
|
|
|
if node.has_bundle('telegraf'):
|
|
|
|
defaults['telegraf'] = {
|
|
|
|
'input_plugins': {
|
2021-04-24 08:17:05 +00:00
|
|
|
'exec': {
|
|
|
|
'postfix': {
|
|
|
|
'commands': ['postfix-telegraf-queue'],
|
2021-04-24 09:45:58 +00:00
|
|
|
'interval': '30s',
|
2021-04-24 08:17:05 +00:00
|
|
|
'data_format': 'influx',
|
|
|
|
'timeout': '5s',
|
|
|
|
},
|
2021-04-23 17:31:28 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-24 08:17:05 +00:00
|
|
|
'sudo_commands': {
|
|
|
|
'/usr/sbin/postqueue -j',
|
|
|
|
},
|
2021-04-23 17:31:28 +00:00
|
|
|
}
|
|
|
|
|
2020-11-10 09:21:37 +00:00
|
|
|
|
2021-01-07 17:44:38 +00:00
|
|
|
@metadata_reactor.provides(
|
|
|
|
'letsencrypt/domains',
|
|
|
|
'letsencrypt/reload_after',
|
|
|
|
)
|
2020-11-07 21:31:18 +00:00
|
|
|
def letsencrypt(metadata):
|
2021-02-20 16:30:38 +00:00
|
|
|
if not node.has_bundle('letsencrypt') or not node.has_bundle('postfixadmin'):
|
2020-11-07 21:31:18 +00:00
|
|
|
raise DoNotRunAgain
|
|
|
|
|
|
|
|
result = {
|
|
|
|
'reload_after': {
|
|
|
|
'postfix',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-02-20 16:30:38 +00:00
|
|
|
result['domains'] = {
|
|
|
|
metadata.get('postfix/myhostname', metadata.get('hostname')): set(),
|
|
|
|
}
|
2020-11-07 21:31:18 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
'letsencrypt': result,
|
|
|
|
}
|
2021-03-21 10:11:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
@metadata_reactor.provides(
|
2023-09-24 18:59:58 +00:00
|
|
|
'firewall/port_rules',
|
|
|
|
'firewall/port_rules',
|
|
|
|
'firewall/port_rules',
|
|
|
|
'firewall/port_rules',
|
2021-03-21 10:11:49 +00:00
|
|
|
)
|
2021-06-03 11:59:15 +00:00
|
|
|
def firewall(metadata):
|
2021-03-21 10:11:49 +00:00
|
|
|
if node.has_bundle('postfixadmin'):
|
2021-04-04 08:34:55 +00:00
|
|
|
default = {'*'}
|
2021-03-21 10:11:49 +00:00
|
|
|
else:
|
|
|
|
default = metadata.get('postfix/mynetworks', set())
|
|
|
|
|
|
|
|
rules = {
|
2023-09-24 18:59:58 +00:00
|
|
|
'25/tcp': atomic(metadata.get('postfix/restrict-to', default)),
|
|
|
|
'465/tcp': atomic(metadata.get('postfix/restrict-to', default)),
|
2021-03-21 10:11:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if node.has_bundle('postfixadmin'):
|
2023-09-24 18:59:58 +00:00
|
|
|
rules['587/tcp'] = atomic(metadata.get('postfix/restrict-to', default))
|
|
|
|
rules['2525/tcp'] = atomic(metadata.get('postfix/restrict-to', default))
|
2021-03-21 10:11:49 +00:00
|
|
|
|
|
|
|
return {
|
2021-06-03 11:59:15 +00:00
|
|
|
'firewall': {
|
2021-03-21 10:11:49 +00:00
|
|
|
'port_rules': rules,
|
|
|
|
},
|
|
|
|
}
|
2021-03-22 19:24:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
@metadata_reactor.provides(
|
|
|
|
'icinga2_api/postfix/services',
|
|
|
|
)
|
|
|
|
def icinga2(metadata):
|
2021-04-01 15:00:53 +00:00
|
|
|
if metadata.get('postfix/relayhost', ''):
|
|
|
|
# The system does not send mail on its own. There is no point in
|
|
|
|
# checking it for any listings.
|
|
|
|
return {}
|
2021-03-22 19:24:14 +00:00
|
|
|
|
2021-04-01 15:00:53 +00:00
|
|
|
services = {}
|
2021-03-22 19:24:14 +00:00
|
|
|
for ip_type in repo.libs.tools.resolve_identifier(repo, node.name).values():
|
|
|
|
for ip in ip_type:
|
|
|
|
if not ip.is_private:
|
|
|
|
services[f'SPAM BLOCKLIST {ip}'] = {
|
2021-11-28 06:26:41 +00:00
|
|
|
'check_command': 'spam_blocklist',
|
|
|
|
'vars.ip': str(ip),
|
2021-03-22 19:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
'icinga2_api': {
|
|
|
|
'postfix': {
|
|
|
|
'services': services,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|