diff --git a/README.md b/README.md index d0d3ecb..16ad394 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ You can send a test alert to verify the mail configuration: runagent -m metrics1 test-alert +### Customimze alert rules + +### Customize alert mail template + + + ## Testing Test the module using the `test-module.sh` script: diff --git a/imageroot/actions/configure-module/20configure b/imageroot/actions/configure-module/20configure index 440644a..d08190a 100755 --- a/imageroot/actions/configure-module/20configure +++ b/imageroot/actions/configure-module/20configure @@ -48,7 +48,7 @@ else: agent_id=agent.resolve_agent_id('traefik@node'), action='delete-route', data={ - 'instance': os.environ['MODULE_ID'] + 'instance': os.environ['MODULE_ID'] + '_prometheus' }, ) diff --git a/imageroot/actions/configure-module/80services b/imageroot/actions/configure-module/80services index db44194..eca4d27 100755 --- a/imageroot/actions/configure-module/80services +++ b/imageroot/actions/configure-module/80services @@ -7,7 +7,7 @@ # reload the configuration to apply new configuration if systemctl --user -q is-active prometheus.service; then - systemctl --user restart prometheus.service + systemctl --user restart prometheus.service alertmanager.service fi if [ -n "$GRAFANA_PATH" ]; then diff --git a/imageroot/actions/configure-module/validate-input.json b/imageroot/actions/configure-module/validate-input.json index 78d6ebc..0b700ec 100644 --- a/imageroot/actions/configure-module/validate-input.json +++ b/imageroot/actions/configure-module/validate-input.json @@ -9,7 +9,8 @@ "grafana_path": "grafana", "lets_encrypt": true, "mail_to": [ "alert@nethserver.org" ], - "mail_from": "no-reply@nethserver.org" + "mail_from": "no-reply@nethserver.org", + "mail_template": "custom_mail" } ], "type": "object", @@ -47,6 +48,11 @@ "type": "string", "format": "email" } + }, + "mail_template": { + "type": "string", + "description": "Name of the custom mail template to use for alerts. The file with the template must already exists inside templates.d/ directory.", + "format": "string" } } } diff --git a/imageroot/bin/reload_configuration b/imageroot/bin/reload_configuration index 4d9156a..0280b7b 100755 --- a/imageroot/bin/reload_configuration +++ b/imageroot/bin/reload_configuration @@ -43,7 +43,8 @@ ALERT_MANAGER_DEFAULT_CONFIG = { } ] } - ] + ], + 'templates': "templates.d/*.tmpl" } def generate_prometheus_config(redis_client): @@ -121,12 +122,13 @@ def generate_alertmanagr_config(redis_client): alert_config['global'] = smtp_config if smtp_config != {} and 'mail_to' in config and config['mail_to']: + mail_config = { + 'to': ",".join(config['mail_to']) + } + if 'mail_template' in config and config['mail_template']: + mail_config['template'] = config['mail_template'] alert_config['receivers'].append({ - 'email_configs': [ - { - 'to': ",".join(config['mail_to']) - } - ], + 'email_configs': [ mail_config ], 'name': 'mail-alert', 'continue': True }) @@ -135,6 +137,8 @@ def generate_alertmanagr_config(redis_client): 'receiver': 'mail-alert' }) + os.makedirs('templates.d', exist_ok=True) + with open('alertmanager.yml', 'w') as f: yaml.dump(alert_config, f, default_flow_style=False)