{"id":1566,"date":"2023-03-25T17:40:53","date_gmt":"2023-03-25T09:40:53","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1566"},"modified":"2023-04-27T21:34:27","modified_gmt":"2023-04-27T13:34:27","slug":"prometheus-receive-alerts-through-enterprise-wechat","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/prometheus-receive-alerts-through-enterprise-wechat\/","title":{"rendered":"Prometheus\u901a\u8fc7\u4f01\u4e1a\u5fae\u4fe1\u63a5\u6536\u544a\u8b66"},"content":{"rendered":"<h2>\u51c6\u5907\u5de5\u4f5c<\/h2>\n<p>step 1: \u8bbf\u95ee<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/work.weixin.qq.com\/\" title=\"\u4f01\u4e1a\u5fae\u4fe1\">\u4f01\u4e1a\u5fae\u4fe1<\/a> \u6ce8\u518c\u4f01\u4e1a\u5fae\u4fe1\u8d26\u53f7\uff08\u4e0d\u9700\u8981\u4f01\u4e1a\u8ba4\u8bc1\uff09\u3002<\/p>\n<p>step 2: \u8bbf\u95ee<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/work.weixin.qq.com\/wework_admin\/frame#apps\" title=\"\u5e94\u7528\u7ba1\u7406\">\u5e94\u7528\u7ba1\u7406<\/a> \u521b\u5efa\u7b2c\u4e09\u65b9\u5e94\u7528\uff0c\u70b9\u51fb\u521b\u5efa\u5e94\u7528\u6309\u94ae -&gt; \u586b\u5199\u5e94\u7528\u4fe1\u606f\uff1a<\/p>\n<p><!-- more --><\/p>\n<h2>Prometheus\u914d\u7f6e<\/h2>\n<ul>\n<li>prometheus.yml \u914d\u7f6e<\/li>\n<\/ul>\n<pre><code class=\"language-yml\"># Alertmanager configuration\nalerting:\n  alertmanagers:\n  - static_configs:\n    - targets: [&#039;localhost:9093&#039;]\n\nrule_files:\n  - &quot;rules.yml&quot;\n\nscrape_configs:\n  - job_name: &#039;node&#039;\n    static_configs:\n      - targets: [&#039;localhost:9100&#039;]<\/code><\/pre>\n<ul>\n<li>rules.yml \u914d\u7f6e<\/li>\n<\/ul>\n<pre><code class=\"language-yml\">groups:\n- name: prometheus_go_goroutines\n  rules:\n  - alert: go_goroutines_numbers\n    expr: go_goroutines &gt; 100\n    for: 15s\n    annotations:\n      summary: &quot;prometheus\u7684gorotine\u6570\u636e\u8d85\u8fc7100!&quot;\n- name: node\n  rules:\n  - alert: server_status\n    expr: up{job=&quot;node&quot;} == 0\n    for: 15s\n    annotations:\n      summary: &quot;\u673a\u5668 {{ $labels.instance }} \u5b95\u673a&quot;\n      description: &quot;\u673a\u5668 {{ $labels.instance }} \u5b95\u673a&quot;<\/code><\/pre>\n<h2>Alertmanger\u914d\u7f6e<\/h2>\n<ul>\n<li><code>alertmanager.yml<\/code><\/li>\n<\/ul>\n<pre><code class=\"language-yml\">route:\n  group_by: [&#039;alertname&#039;]\n  receiver: &#039;wechat&#039;\n\nreceivers:\n  - name: &#039;wechat&#039;\n    wechat_configs:\n    - send_resolved: true\n      corp_id: &#039;xxx&#039;\n      to_party: &#039;1&#039;\n      agent_id: &#039;1000002&#039;\n      api_secret: &#039;xxxx&#039;<\/code><\/pre>\n<p>\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n<ul>\n<li><code>corp_id<\/code>: \u4f01\u4e1a\u5fae\u4fe1\u8d26\u53f7\u552f\u4e00ID\uff0c\u53ef\u4ee5\u5728\u6211\u7684\u4f01\u4e1a\u4e2d\u67e5\u770b<\/li>\n<li><code>to_party<\/code>: \u9700\u8981\u53d1\u9001\u7684\u7ec4<\/li>\n<li><code>agent_id<\/code>: \u7b2c\u4e09\u65b9\u4f01\u4e1a\u5e94\u7528\u7684ID\uff0c\u53ef\u4ee5\u5728\u81ea\u5df1\u521b\u5efa\u7684\u7b2c\u4e09\u65b9\u4f01\u4e1a\u5e94\u7528\u8be6\u60c5\u9875\u9762\u67e5\u770b<\/li>\n<li><code>api_secret<\/code>: \u7b2c\u4e09\u65b9\u4f01\u4e1a\u5e94\u7528\u7684\u5bc6\u94a5\uff0c\u53ef\u4ee5\u5728\u81ea\u5df1\u521b\u5efa\u7684\u7b2c\u4e09\u65b9\u4f01\u4e1a\u5e94\u7528\u8be6\u60c5\u9875\u9762\u67e5\u770b<\/li>\n<\/ul>\n<h2>\u914d\u7f6e\u6a21\u677f<\/h2>\n<ul>\n<li><code>alertmanager.yml<\/code><\/li>\n<\/ul>\n<pre><code class=\"language-yml\">templates:\n  - &#039;.\/template\/wechat.tmpl&#039;<\/code><\/pre>\n<ul>\n<li><code>wechat.tmpl<\/code><\/li>\n<\/ul>\n<pre><code>{{ define &quot;wechat.default.message&quot; }}\n{{ range .Alerts }}\n========start=========\n\u544a\u8b66\u7a0b\u5e8f: prometheus_alert\n\u544a\u8b66\u7ea7\u522b: {{ .Labels.serverity }}\n\u544a\u8b66\u7c7b\u578b: {{ .Labels.alertname }}\n\u6545\u969c\u4e3b\u673a: {{ .Labels.instance }}\n\u544a\u8b66\u4e3b\u9898: {{ .Annotations.summary }}\n\u544a\u8b66\u8be6\u60c5: {{ .Annotations.description }}\n\u89e6\u53d1\u65f6\u95f4: {{ .StartsAt.Format &quot;2019-11-02 15:08:05&quot; }}\n=========end===========\n{{ end }}\n{{ end }}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u51c6\u5907\u5de5\u4f5c step 1: \u8bbf\u95ee\u4f01\u4e1a\u5fae\u4fe1 \u6ce8\u518c\u4f01\u4e1a\u5fae\u4fe1\u8d26\u53f7\uff08\u4e0d\u9700\u8981\u4f01\u4e1a\u8ba4\u8bc1\uff09\u3002 step 2: \u8bbf\u95ee\u5e94\u7528\u7ba1\u7406 \u521b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[386],"tags":[391,387,392],"class_list":["post-1566","post","type-post","status-publish","format-standard","hentry","category-monitor","tag-alertmanger","tag-prometheus","tag-392"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1566"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1566\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}