接上一篇崎脉,我們繼續(xù)解釋如何把ELK跟釘釘及發(fā)送郵件功能結(jié)合起來勘究,讓我們及時(shí)的了解重要日志并快速反饋抒倚。
- Sentinel 安裝躬充,項(xiàng)目介紹在https://github.com/sirensolutions/sentinl,點(diǎn)擊可以詳細(xì)介紹脾歧。
運(yùn)行命令轉(zhuǎn)到kibana的bin目錄
cd /usr/share/kibana/bin
甲捏,這里是默認(rèn)安裝路徑,然后執(zhí)行如下命令
./kibana-plugin install https://github.com/sirensolutions/sentinl/releases/download/tag-6.3.2-beta-1/sentinl-v6.3.1.zip
鞭执,這里根據(jù)服務(wù)器性能及網(wǎng)絡(luò)環(huán)境司顿,可能要等一會(huì)才能看到成功的信息芒粹,成功后會(huì)自動(dòng)刷新kibana服務(wù),再次打開kibana大溜,如圖所示說明安裝成功
- 郵件通知
a) 要發(fā)送郵件化漆,得先有一臺(tái)SMTP發(fā)送服務(wù),我這里用的是163,現(xiàn)在幾乎提供郵件功能的服務(wù)商都可以啟動(dòng)SMTP功能,開通即可。
b) 郵件配置,打開/etc/kibana/kibana.yml 文件刁笙,添加如下設(shè)置
sentinl:
settings:
email:
active: true
user: lznboy-123@163.com
password: 123456
host: smtp.163.com
ssl: false #根據(jù)實(shí)際情況添加
report:
active: true
千萬注意設(shè)置級(jí)別,不然會(huì)出現(xiàn)莫名的錯(cuò)誤耀销。
c) 點(diǎn)擊sentinl淹接,添加一個(gè)Watcher,我這里配置信息如下限佩。
{
"actions": {
"Alerm": {
"throttle_period": "1h0m0s",
"email": {
"to": "lznboy-123@163.com",
"from": "lznboy-123@163.com",
"subject": "業(yè)務(wù)系統(tǒng)告警",
"priority": "high",
"html": "系統(tǒng)程序錯(cuò)誤告警: 一共發(fā)生{{payload.hits.total}} 次葵诈,請(qǐng)登錄核查<a herf=\"http://192.168.1.215:5601\" target=\"_blank\">點(diǎn)擊登錄</a>"
}
}
},
"input": {
"search": {
"request": {
"index": [
"nlog*"
],
"body": {
"query": {
"bool": {
"must": [
{
"query_string": {
"analyze_wildcard": true,
"query": "\"error\""
}
},
{
"range": {
"@timestamp": {
"gte": "now-1h",
"lte": "now",
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
}
}
}
}
},
"condition": {
"script": {
"script": "payload.hits.total >= 5"
}
},
"trigger": {
"schedule": {
"later": "every 2 minutes"
}
},
"disable": true,
"report": false,
"title": "nlog",
"wizard": {},
"save_payload": false,
"spy": false,
"impersonate": false
}
主要是配置接收者郵箱,判斷依據(jù)祟同,判斷條件作喘,觸發(fā)間隔
d) 開啟Watcher并執(zhí)行,如下圖所示晕城。
等一會(huì)泞坦,就會(huì)在alarms下看到告警信息。
打開配置文件中接收者的郵件砖顷,可以看到收到的信息贰锁,我的信息如下
,說明郵件告警功能運(yùn)行正常滤蝠。
2. 釘釘消息
a) 釘釘接收消息豌熄,主要是利用釘釘?shù)臋C(jī)器人功能,首先開通機(jī)器人物咳,我的機(jī)器人設(shè)置如下
主要是利用webhook锣险,接下來在設(shè)置發(fā)送消息中用到。
b) 釘釘Watcher設(shè)置览闰,設(shè)置如下
{
"actions": {
"Webhook_683bd385-86b3-46ba-8e1b-f89cccccbbec": {
"name": "WatcherName",
"throttle_period": "1m",
"webhook": {
"priority": "high",
"stateless": false,
"method": "POST",
"host": "oapi.dingtalk.com",
"port": "443",
"path": "/robot/send?access_token=ec5fe24b4a218f71bca667975850cbf3f2830b9bd2bd91f60ca07fab28a3d439",
"body": " {\"msgtype\": \"text\",\r\n \"text\": {\r\n \"content\":\"業(yè)務(wù)系統(tǒng)告警\"\r\n }\r\n}",
"params": {
"watcher": "{{watcher.title}}",
"payload_count": "{{payload.hits.total}}"
},
"headers": {
"Content-Type": "application/json"
},
"auth": "釘釘賬號(hào)名:密碼",
"message": "業(yè)務(wù)功能告警",
"use_https": true
}
}
},
"input": {
"search": {
"request": {
"index": [
"nlog*"
],
"body": {
"query": {
"bool": {
"filter": {
"range": {
"@timestamp": {
"gte": "now-15m/m",
"lte": "now/m",
"format": "epoch_millis"
}
}
}
}
},
"size": 0,
"aggs": {
"dateAgg": {
"date_histogram": {
"field": "@timestamp",
"time_zone": "Europe/Amsterdam",
"interval": "1m",
"min_doc_count": 1
}
}
}
}
}
}
},
"condition": {
"script": {
"script": "payload.aggregations.dateAgg.buckets.some(b => b.doc_count>=5)"
}
},
"trigger": {
"schedule": {
"later": "every 1 minutes"
}
},
"disable": true,
"report": false,
"title": "nlog_dingding",
"wizard": {},
"save_payload": false,
"spy": false,
"impersonate": false
}
c) 開啟并執(zhí)行Watcher芯肤,注意觀察釘釘,如果收到如下信息压鉴,則說明該功能運(yùn)行成功崖咨。
這樣,ELK跟業(yè)務(wù)系統(tǒng)對(duì)接晴弃,及郵件掩幢、釘釘告警已經(jīng)介紹完了逊拍,其實(shí)發(fā)揮想想并根據(jù)業(yè)務(wù)需求,可以延伸出更有用的功能际邻。如果更好的建議歡迎交流并共同進(jìn)步芯丧。