我在这里查看了这个问题/答案:Prometheus AlertManager - Send Alerts to different clients based on routes
对我来说,这是一个不错的开始,我希望我可以向那里的Answerer评论一个简短的问题,但是我没有代表。
无论如何,我有一个带有两个组的 alert.rules.yml 文件,如下所示:
groups:
- name: DevOpsAlerts
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.instance }} down"
description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes. ({{ $value }} minutes)"
- alert: InstanceHighCpu
expr: 100 - (avg by (host) (irate(node_cpu{mode="idle"}[5m])) * 100) > 5
for: 10m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.host }}: CPU High"
description: "{{ $labels.host }} has high CPU activity"
- name: TestTeam2
rules:
- alert: - alert: InstanceLowMemory
expr: node_memory_MemAvailable < 268435456
for: 10m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.host }}: memory low"
description: "{{ $labels.host }} has less than 256M memory available"
- alert: InstanceLowDisk
expr: node_filesystem_avail{mountpoint="/"} < 1073741824
for: 10m
labels:
severity: critical
annotations:
summary: "Instance {{ $labels.host }}: low disk space"
description: "{{ $labels.host }} has less than 1G FS space"
此外,我还有一个 alertmanager.yml 文件,看起来像
global:
smtp_smarthost: 'smtpserver'
smtp_from: 'alertsender@email.com'
smtp_auth_username: 'alertsender@email.com'
smtp_auth_password: 'verystrongpassword'
smtp_require_tls: maybe
route:
group_by: ['alertname', 'cluster', 'service']
#default receiver
receiver: DevOps
routes:
- match:
alertname: InstanceDown
receiver: DevOps
- match:
group: InstanceHighCpu
receiver: test-team-1
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'cluster', 'service']
receivers:
- name: DevOps
email_configs:
# - to: devops_dude@email.com
- name: test-team-1
email_configs:
- to: test-dude1@email.com #This can be any email specified from the team
- name: team-name-2
email_configs:
- to: test_email@test.com #This can be any email specified from the team
因此,从我收集的信息中,我可以通过从警报规则文件中指定警报名称并将其路由到特定的接收者,将警报路由到特定的接收者组。
我真正遇到的一个大问题是:是否有一种方法可以根据警报规则文件中的组名称(而不是警报名称)将警报路由到特定的接收者。
所以不是
routes:
- match:
alertname: InstanceDown
receiver: DevOps
是否有某种实现方式:
routes:
- match:
group: DevOpsAlerts
receiver: DevOps
我一直在寻找这样的例子,但我找不到任何东西。谢谢。
答案 0 :(得分:2)
规则组名称不向Alertmanager公开,它们主要是在Prometheus端进行调试的。
您可以做的是在每个警报中添加一个<script type="text/javascript">
function selectImage(imgName){
opener.document.parentform.logo_url.value=imgName;
window.close();
}
</script>
标签。