global:
#定义一个基础的SMTP邮件配置
smtp_smarthost: 'smtp.gmail.com:587'
smtp_from: 'youremail@gmail.com'
smtp_auth_username: 'youremail@gmail.com'
smtp_auth_password: 'yourpassword'
smtp_require_tls: true
route:
group_wait: 10s
group_interval: 5m
repeat_interval: 12h
receiver: 'default-receiver'
receivers:
- name: 'default-receiver'
email_configs:
- to: 'your-email@example.com'
#定义警报邮件的主题
subject: '{{ .GroupLabels.job }}: {{ .CommonLabels.alertname }}'
#定义警报邮件的内容
body: |
Alert Name: {{ .CommonLabels.alertname }}
Namespace: {{ .CommonLabels.namespace }}
Severity: {{ .CommonLabels.severity }}
Job: {{ .GroupLabels.job }}
Instance: {{ .CommonLabels.instance }}
Summary: {{ .CommonAnnotations.summary }}
Description: {{ .CommonAnnotations.description }}
- targets: ['localhost:9090']
labels:
environment: 'staging'
job: 'prometheus'
./alertmanager --config.file=alertmanager.yaml
这样就完成了按目标组转发Prometheus警报的设置。一旦有警报触发,就会将其转发到在配置文件中定义的默认收件人邮箱中。