Skip to content

Commit

Permalink
增加zabbix告警支持,接口更新,帮助文档更新zabbix
Browse files Browse the repository at this point in the history
  • Loading branch information
jikun.zhang committed Mar 28, 2020
1 parent d86ef6d commit 7d69c72
Show file tree
Hide file tree
Showing 21 changed files with 442 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ PrometheusAlert全家桶 简介

-----------------

PrometheusAlert是开源的运维告警中心消息转发系统,支持主流的监控系统Prometheus,日志系统Graylog2,Graylog3和数据可视化系统Grafana发出的预警消息,支持将收到的这些消息发送到钉钉,微信,腾讯短信,腾讯电话,阿里云短信,阿里云电话,华为短信等。
PrometheusAlert是开源的运维告警中心消息转发系统,支持主流的监控系统Prometheus、Zabbix,日志系统Graylog2,Graylog3和数据可视化系统Grafana发出的预警消息,支持将收到的这些消息发送到钉钉,微信,腾讯短信,腾讯电话,阿里云短信,阿里云电话,华为短信等。

![it](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/it.png)

--------------------------------------

PrometheusAlert具备如下特性
---------------------
- 支持多种消息来源,目前主要有Prometheus,Graylog2,Graylog3,Grafana。
- 支持多种消息来源,目前主要有Prometheus,Zabbix,Graylog2,Graylog3,Grafana。
- 支持多种类型的发送目标,支持钉钉,微信,腾讯短信,腾讯语音,阿里云短信,阿里云语音,华为短信。
- 针对Prometheus增加了告警级别,并且支持按照不同级别发送消息到不同目标对象。
- 简化Prometheus分组配置,支持按照具体消息发送到单个或多个接收方。
Expand All @@ -33,7 +33,7 @@ PrometheusAlert具备如下特性
* [Prometheus配置](doc/readme/prometheus.md)
* [graylog配置](doc/readme/graylog.md)
* [grafana配置](doc/readme/grafana.md)
* [zabbix配置(待更新)](...)
* [zabbix配置](doc/readme/zabbix.md)
* [告警接收目标配置]
* [钉钉告警配置](doc/readme/dingding.md)
* [企业微信告警配置](doc/readme/wechat.md)
Expand Down
46 changes: 46 additions & 0 deletions controllers/zabbix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package controllers

import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/astaxie/beego/logs"
)

type ZabbixController struct {
beego.Controller
}

type ZabbixMessage struct{
ZabbixTarget string `json:"zabbixtarget"`
ZabbixMessage string `json:"zabbixmessage"`
ZabbixType string `json:"zabbixtype"`
}

func (c *ZabbixController) ZabbixAlert() {
alert:=ZabbixMessage{}
logsign:="["+LogsSign()+"]"
logs.Info(logsign,string(c.Ctx.Input.RequestBody))
json.Unmarshal(c.Ctx.Input.RequestBody, &alert)
c.Data["json"]=SendMessageZabbix(alert,logsign)
logs.Info(logsign,c.Data["json"])
c.ServeJSON()
}
func SendMessageZabbix(message ZabbixMessage,logsign string) (string){
ret:=""
switch message.ZabbixType {
case "wx":
ret=PostToWeiXin(message.ZabbixMessage,message.ZabbixTarget,logsign)
case "dd":
ret=PostToDingDing("Zabbix告警消息",message.ZabbixMessage,message.ZabbixTarget,logsign)
case "dx":
ret=PostTXmessage(message.ZabbixMessage,message.ZabbixTarget,logsign)
ret=ret+PostHWmessage(message.ZabbixMessage,message.ZabbixTarget,logsign)
ret=ret+PostALYmessage(message.ZabbixMessage,message.ZabbixTarget,logsign)
case "dh":
ret=PostTXphonecall(message.ZabbixMessage,message.ZabbixTarget,logsign)
ret=ret+PostALYphonecall(message.ZabbixMessage,message.ZabbixTarget,logsign)
default:
ret="参数错误"
}
return ret
}
29 changes: 28 additions & 1 deletion doc/readme/aliyun.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,31 @@

语音(电话):https://help.aliyun.com/document_detail/55070.html?spm=a2c4g.11186623.6.547.77e271b9SAbG6p

阿里云模版配置可参考,code为变量名称:`prometheus告警:${code}`
阿里云模版配置可参考,code为变量名称:`prometheus告警:${code}`

配置阿里云短信和语音参数:

```
#---------------------↓阿里云接口-----------------------
#是否开启阿里云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-alydx=1
#阿里云短信主账号AccessKey的ID
ALY_DX_AccessKeyId=xxxxxxxxxxxxxxxxxxxxxx
#阿里云短信接口密钥
ALY_DX_AccessSecret=xxxxxxxxxxxxxxxxxxxxxx
#阿里云短信签名名称
ALY_DX_SignName=阿里云
#阿里云短信模板ID
ALY_DX_Template=xxxxxxxxxxxxxxxxxxxxxx
#是否开启阿里云电话告警通道,可同时开始多个通道0为关闭,1为开启
open-alydx=1
#阿里云电话主账号AccessKey的ID
ALY_DH_AccessKeyId=xxxxxxxxxxxxxxxxxxxxxx
#阿里云电话接口密钥
ALY_DH_AccessSecret=xxxxxxxxxxxxxxxxxxxxxx
#阿里云电话被叫显号,必须是已购买的号码
ALY_DX_CalledShowNumber=xxxxxxxxx
#阿里云电话文本转语音(TTS)模板ID
ALY_DH_TtsCode=xxxxxxxx
```
22 changes: 21 additions & 1 deletion doc/readme/dingding.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ PrometheusAlert全家桶钉钉配置说明
![ding2](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/dingding2.png)

新版本的钉钉加了安全设置,只需选择安全设置中的 自定义关键词 即可,并将关键词设置为 Prometheus或者app.conf中设置的title值均可,参考下图
![ding2](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/dingding3.png)
![ding2](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/dingding3.png)

钉钉相关配置:

```
#---------------------↓全局配置-----------------------
#告警消息标题
title=PrometheusAlert
#钉钉告警 告警logo图标地址
logourl=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png
#钉钉告警 恢复logo图标地址
rlogourl=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png
#---------------------↓webhook-----------------------
#是否开启钉钉告警通道,可同时开始多个通道0为关闭,1为开启
open-dingding=1
#默认钉钉机器人地址
ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxxx
#是否开启 @所有人(0为关闭,1为开启)
dd_isatall=1
```
22 changes: 21 additions & 1 deletion doc/readme/hw.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,24 @@

`模版类型:通知类`

`模版内容:运维告警:${TXT_66}`
`模版内容:运维告警:${TXT_66}`

华为云短信相关配置:

```
#---------------------↓华为云接口-----------------------
#是否开启华为云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-hwdx=1
#华为云短信接口key
HWY_DX_APP_Key=xxxxxxxxxxxxxxxxxxxxxx
#华为云短信接口Secret
HWY_DX_APP_Secret=xxxxxxxxxxxxxxxxxxxxxx
#华为云APP接入地址(端口接口地址)
HWY_DX_APP_Url=https://rtcsms.cn-north-1.myhuaweicloud.com:10743
#华为云短信模板ID
HWY_DX_Templateid=xxxxxxxxxxxxxxxxxxxxxx
#华为云签名名称,必须是已审核通过的,与模板类型一致的签名名称,按照自己的实际签名填写
HWY_DX_Signature=华为云
#华为云签名通道号
HWY_DX_Sender=xxxxxxxxxx
```
6 changes: 6 additions & 0 deletions doc/readme/restful.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ PrometheusAlert 暂提供以下几类接口,分别对应各自接入端
```
/prometheus/alert 默认接口
/prometheus/router AlertManager router指定接收端接口
```

- `zabbix接口`

```
/zabbix/alert 默认接口
```

- `grafana接口`
Expand Down
20 changes: 11 additions & 9 deletions doc/readme/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@ copyrequestbody = true
title=PrometheusAlert
#链接到告警平台地址
GraylogAlerturl=http://graylog.org
#logo图标地址
#钉钉告警 告警logo图标地址
logourl=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png
#钉钉告警 恢复logo图标地址
rlogourl=https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/alert-center.png
#短信告警级别(等于3就进行短信告警) 告警级别定义 0 信息,1 警告,2 一般严重,3 严重,4 灾难
messagelevel=3
#电话告警级别(等于4就进行语音告警) 告警级别定义 0 信息,1 警告,2 一般严重,3 严重,4 灾难
phonecalllevel=4
#默认拨打号码
defaultphone=15395105573
#故障恢复是否启用电话通知0为关闭,1为开启
phonecallresolved=1
phonecallresolved=0
#自动告警抑制(自动告警抑制是默认同一个告警源的告警信息只发送告警级别最高的第一条告警信息,其他消息默认屏蔽,这么做的目的是为了减少相同告警来源的消息数量,防止告警炸弹,0为关闭,1为开启)
silent=1
silent=0
#是否前台输出file or console
logtype=file
#日志文件路径
Expand All @@ -38,13 +40,13 @@ ddurl=https://oapi.dingtalk.com/robot/send?access_token=xxxxx
dd_isatall=1
#是否开启微信告警通道,可同时开始多个通道0为关闭,1为开启
open-weixin=0
open-weixin=1
#默认企业微信机器人地址
wxurl=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx
#---------------------↓腾讯云接口-----------------------
#是否开启腾讯云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-txdx=0
open-txdx=1
#腾讯云短信接口key
TXY_DX_appkey=xxxxx
#腾讯云短信模版ID 腾讯云短信模版配置可参考 prometheus告警:{1}
Expand All @@ -55,7 +57,7 @@ TXY_DX_sdkappid=xxxxx
TXY_DX_sign=腾讯云
#是否开启腾讯云电话告警通道,可同时开始多个通道0为关闭,1为开启
TXY_DH_open-txdh=0
TXY_DH_open-txdh=1
#腾讯云电话接口key
TXY_DH_phonecallappkey=xxxxx
#腾讯云电话模版ID
Expand All @@ -65,7 +67,7 @@ TXY_DH_phonecallsdkappid=xxxxx
#---------------------↓华为云接口-----------------------
#是否开启华为云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-hwdx=0
open-hwdx=1
#华为云短信接口key
HWY_DX_APP_Key=xxxxxxxxxxxxxxxxxxxxxx
#华为云短信接口Secret
Expand All @@ -81,7 +83,7 @@ HWY_DX_Sender=xxxxxxxxxx
#---------------------↓阿里云接口-----------------------
#是否开启阿里云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-alydx=0
open-alydx=1
#阿里云短信主账号AccessKey的ID
ALY_DX_AccessKeyId=xxxxxxxxxxxxxxxxxxxxxx
#阿里云短信接口密钥
Expand All @@ -92,7 +94,7 @@ ALY_DX_SignName=阿里云
ALY_DX_Template=xxxxxxxxxxxxxxxxxxxxxx
#是否开启阿里云电话告警通道,可同时开始多个通道0为关闭,1为开启
open-alydx=0
open-alydx=1
#阿里云电话主账号AccessKey的ID
ALY_DH_AccessKeyId=xxxxxxxxxxxxxxxxxxxxxx
#阿里云电话接口密钥
Expand Down
27 changes: 26 additions & 1 deletion doc/readme/tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,29 @@

ps:回调接口需对公网开放,否则云平台无法访问到接口.开启回调之后请务必创建user.csv文件

![tengxun2](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/tengxun2.png)
![tengxun2](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/tengxun2.png)

腾讯云短信和语音相关配置:

```
#---------------------↓腾讯云接口-----------------------
#是否开启腾讯云短信告警通道,可同时开始多个通道0为关闭,1为开启
open-txdx=1
#腾讯云短信接口key
TXY_DX_appkey=xxxxx
#腾讯云短信模版ID 腾讯云短信模版配置可参考 prometheus告警:{1}
TXY_DX_tpl_id=xxxxx
#腾讯云短信sdk app id
TXY_DX_sdkappid=xxxxx
#腾讯云短信签名 根据自己审核通过的签名来填写
TXY_DX_sign=腾讯云
#是否开启腾讯云电话告警通道,可同时开始多个通道0为关闭,1为开启
TXY_DH_open-txdh=1
#腾讯云电话接口key
TXY_DH_phonecallappkey=xxxxx
#腾讯云电话模版ID
TXY_DH_phonecalltpl_id=xxxxx
#腾讯云电话sdk app id
TXY_DH_phonecallsdkappid=xxxxx
```
10 changes: 10 additions & 0 deletions doc/readme/wechat.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@ PrometheusAlert全家桶企业微信配置说明

![wx1](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/wx1.png)
![wx2](https://raw.githubusercontent.com/feiyu563/PrometheusAlert/master/doc/wx2.png)

企业微信机器人相关配置:

```
#---------------------↓webhook-----------------------
#是否开启微信告警通道,可同时开始多个通道0为关闭,1为开启
open-weixin=1
#默认企业微信机器人地址
wxurl=https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxx
```
Loading

0 comments on commit 7d69c72

Please sign in to comment.