# falcon-mailprovider **Repository Path**: flyingcar/falcon-mailprovider ## Basic Information - **Project Name**: falcon-mailprovider - **Description**: 使用Python实现的适配openfalcon(v1/v2)的邮件和企业微信发送接口,顺带支持Prometheus的webhook。 - **Primary Language**: Python - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-12-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # falcon-mailprovider 使用Python实现的适配openfalcon(v1/v2)的邮件和企业微信发送接口,顺带支持Prometheus的webhook。 邮件发送仅支持SSL协议465端口发送邮件,不支持25、587端口。 企业微信支持组和指定用户发送。 # 安装启动 ``` git clone https://gitee.com/tseyuzen/falcon-mailprovider.git virtualenv ./env source ./env/bin/activate pip install -r pip_requirements.txt ``` # 配置 1. gunicorn.conf ``` bind = ':4000' #自定义端口 ``` 2. sendmail.py ``` mail_settings = { "from": "alert@xxx.xxx", "hostname": "smtp.xxx.xxx", "username": "alert@xxx.xxx", "password": "yyyyyyyyyyyyy", "mail_encoding": "utf-8" } ``` 3. sendwechat.py ``` wechat_settings = { "corpid": "ww996b940f84ba358e", "corpsecret": "OTdycWLC_JXK_9Tkq6ok9DQ834NBRxWcgO2J0zryLNY", "agentid": "1000002" } ``` # 启动 ``` bash control start ``` # 日志 var/ 目录下 # 测试 ``` curl http://127.0.0.1:4000/mail -d "tos=abc@163.com,efd@qq.com&subject=xx&content=y" curl http://127.0.0.1:4000/wechat -d "tos=XiangShaoLong,WuTingFang&subject=xx&type=user" curl http://127.0.0.1:4000/wechat -d "tos=2,11,9&subject=xx&type=party" ``` Prometheus Alertmanager 关键配置 ``` global: templates: - './*.tmpl' route: group_by: ['project','item'] group_wait: 0s group_interval: 1m repeat_interval: 4h receiver: 2 routes: - receiver: 2 match_re: project: ^.* continue: true receivers: - name: '2' webhook_configs: - url: "http://127.0.0.1:4000/prometheus" ``` ``` -bash-4.2$ cat /app/prometheus/prometheus/rules.yml groups: - name: DEMO rules: - alert: "阿普测试" expr: up{instance="127.0.0.1:9100",job="node"}==1 for: 1m labels: serverity: P2 annotations: summary: "当前值:{{ $value }}" ```