-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c5ca73f
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[Info]D:/godata/golearn/4.常用示例/zabbix叮叮告警/main.go:20: message send start! | ||
[Info]D:/godata/golearn/4.常用示例/zabbix叮叮告警/main.go:53: 消息发送完成:{"errmsg":"ok","errcode":0} | ||
[Info]2018/09/24 15:57:49 main.go:20: message send start! | ||
[Info]2018/09/24 15:57:49 main.go:53: 消息发送完成:{"errmsg":"ok","errcode":0} | ||
[Info]2018/09/24 15:58:13 message send start! | ||
[Info]2018/09/24 15:58:13 消息发送完成:{"errmsg":"ok","errcode":0} | ||
[Info]2018/09/24 15:58:41 开始发送消息! | ||
[Info]2018/09/24 15:58:41 消息发送完成:{"errmsg":"ok","errcode":0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
zabbix告警参数:1.{ALERT.SENDTO} 2.{ALERT.MESSAGE} | ||
|
||
告警内容参考: | ||
操作----------- | ||
智享云告警平台告警提醒 | ||
{TRIGGER.NAME} | ||
故障时间:{EVENT.DATE} {EVENT.TIME} | ||
告警级别:{TRIGGER.SEVERITY} | ||
故障前状态:{ITEM.LASTVALUE} | ||
故障事件ID:{EVENT.ID} | ||
故障主机IP:{HOST.IP} | ||
故障主机名:{HOST.NAME} | ||
故障时长:{EVENT.AGE} | ||
{EVENT.STATUS} | ||
故障是否确认:{EVENT.ACK.STATUS} | ||
|
||
恢复操作 | ||
智享云告警平台恢复提醒 | ||
{TRIGGER.NAME} 已经恢复! | ||
恢复时间:{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME} | ||
故障前状态:{ITEM.LASTVALUE} | ||
故障事件ID:{EVENT.ID} | ||
故障主机IP:{HOST.IP} | ||
故障主机名:{HOST.NAME} | ||
故障时长:{EVENT.AGE} | ||
{EVENT.STATUS} | ||
故障是否确认:{EVENT.ACK.STATUS} | ||
|
||
确认操作 | ||
智享云告警平台确认提醒 | ||
管理员{USER.FULLNAME} 已经发布故障原因! | ||
确认时间:{ACK.DATE} {ACK.TIME} | ||
故障前状态:{ITEM.LASTVALUE} | ||
故障事件ID:{EVENT.ID} | ||
故障主机IP:{HOST.IP} | ||
故障主机名:{HOST.NAME} | ||
故障时长:{EVENT.AGE} | ||
故障原因:{ACK.MESSAGE} | ||
{EVENT.STATUS} | ||
故障是否确认:{EVENT.ACK.STATUS} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[setup] | ||
url=https://oapi.dingtalk.com/robot/send?access_token=94605c3d8aac1adde9ff9e116d21a34bda541a94e2151e5f02eabb752f29f915 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"bytes" | ||
"net/http" | ||
"io/ioutil" | ||
"github.com/Unknwon/goconfig" | ||
"log" | ||
"time" | ||
) | ||
func main() { | ||
//取输入参数1和2 | ||
user:=os.Args[1] | ||
text:=os.Args[2] | ||
fileName := time.Now().Format("20060102") +".dingding.log" | ||
logFile,_:= os.OpenFile(fileName, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0766) | ||
defer logFile.Close() | ||
Log := log.New(logFile,"[Info]", log.Ldate|log.Ltime) // log.Ldate|log.Ltime|log.Lshortfile | ||
Log.Println("开始发送消息!") | ||
SendMsg(user,text,Log) | ||
} | ||
|
||
//发送消息到钉钉 | ||
func SendMsg(user,text string,Log *log.Logger) { | ||
jsonstring:=`{ | ||
"msgtype": "markdown", | ||
"markdown": {"title":"DF云告警信息", | ||
"text":"`+text+`" | ||
}, | ||
"at": { | ||
"atMobiles": [ | ||
"`+user+`" | ||
], | ||
"isAtAll": true | ||
} | ||
}` | ||
reader:=bytes.NewReader([]byte(jsonstring)) | ||
cfg, err :=goconfig.LoadConfigFile("dingding.conf") | ||
if err != nil { | ||
Log.SetPrefix("[Err]") | ||
Log.Println("读取配置文件失败[config.ini]") | ||
return | ||
} | ||
url,err:=cfg.GetValue("setup","url") | ||
if err != nil { | ||
Log.SetPrefix("[Err]") | ||
Log.Fatalf("无法获取键值(%s):%s", "url", err) | ||
return | ||
} | ||
resp:=Post(url,reader) | ||
Log.SetPrefix("[Info]") | ||
Log.Fatalf("消息发送完成,服务器返回内容:%s", string(resp)) | ||
} | ||
|
||
func Post(url string,reader *bytes.Reader) []byte { | ||
request,_ := http.NewRequest("POST", url, reader) | ||
request.Header.Set("Content-Type", "application/json") | ||
client := http.Client{} | ||
resp, _ := client.Do(request) | ||
respBytes, _ := ioutil.ReadAll(resp.Body) | ||
return respBytes | ||
} |