Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gsanchietti committed Feb 24, 2025
1 parent d66442c commit edfdee9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion imageroot/actions/configure-module/20configure
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
)

Expand Down
2 changes: 1 addition & 1 deletion imageroot/actions/configure-module/80services
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion imageroot/actions/configure-module/validate-input.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"grafana_path": "grafana",
"lets_encrypt": true,
"mail_to": [ "[email protected]" ],
"mail_from": "[email protected]"
"mail_from": "[email protected]",
"mail_template": "custom_mail"
}
],
"type": "object",
Expand Down Expand Up @@ -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"
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions imageroot/bin/reload_configuration
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ ALERT_MANAGER_DEFAULT_CONFIG = {
}
]
}
]
],
'templates': "templates.d/*.tmpl"
}

def generate_prometheus_config(redis_client):
Expand Down Expand Up @@ -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
})
Expand All @@ -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)

Expand Down

0 comments on commit edfdee9

Please sign in to comment.