Kibana插件sentinl實現郵件報警

1.安裝sentinl插件
到https://github.com/sirensolutions/sentinl/releases上選擇合適的版本,好比你的kibana是5.6.2的,那麼這裏也要選擇5.6.2的sentinl版本;複製zip包的連接地址,而後到kibana服務器(開通外網)上,執行下面的命令便可安裝:
/usr/share/kibana/bin/kibana-plugin install https://github.com/sirensolutions/sentinl/releases/download/tag-5.6.2/sentinl-v5.6.4.zip
安裝過程當中可能由於網絡緣由會中斷,多安裝幾回就好了。java

2.重啓kibana
安裝完畢後,systemctl restart kibana,而後http://kibana-server-ip:5601,界面上會多一個這個(下圖紅圈):
Kibana插件sentinl實現郵件報警git

3.在kibana界面上配置sentinl
點擊sentinl→watchers→New(右上角)→「+warcher」(左上角),到以下界面:
Kibana插件sentinl實現郵件報警
3.1 General
Title:這個watcher的標題
Schedule:檢測頻率,例如「every 5 minutes」、「at 17:15」、「at 10:15 am also at 5:15pm except on Tuesday」等。
3.2 Input
見下例,
{
"search": {
"request": {
"index": [
"java-log-*" //查詢以java-log開頭的全部索引
],
"body": {
"query": {
"bool": {
"must": [
{
"query_string": {
"analyze_wildcard": true,
"query": "\"Cannot connect to Hessian remote service\"" //查詢包含該字符串的行
}
},
{
"range": {
"@timestamp": {
"gte": "now-1h",
"lte": "now", //查詢最近一小時的數據
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
}
}
}
}
}
上面這些配置的結果是:查詢以java-log開頭的索引裏面的,最近一小時的,包含「Cannot connect to Hessian remote service」的文檔行。
這個配置內容是很靈活的,能夠配置只查詢某個日誌文件、只查詢最近一分鐘的數據等。
3.3 Condition
見下例,
{
"script": {
"script": "payload.hits.total > 1"
}
}
若是知足這個Condition的話,就觸發後面要配置的「Actions」。
"payload.hits.total"是以「Input」裏的配置爲條件,查詢出來的結果數,見下圖,
Kibana插件sentinl實現郵件報警
3.4 Transform
附屬條件,暫時沒用。
3.5 Actions
報警動做。
見下圖示例,
Kibana插件sentinl實現郵件報警
4.在kibana服務器上配置kibana和mail
4.1 以163郵箱爲例,163郵箱受權方式
Kibana插件sentinl實現郵件報警
Kibana插件sentinl實現郵件報警
配置完上面後,會獲取到一個客戶端受權碼,客戶端(如Foxmail)用163用戶名和受權碼登陸,直接用163用戶名和密碼登陸會提示「受權失敗」。github

4.2 安裝前置工具
yum install postfix mail cyrus-sasl-*
4.3 配置mail
vim /etc/mail.rc #在文件尾部追加下面的內容。
set from=test@163.com
set smtp=smtp.163.com
set smtp-auth-user=test
set smtp-auth-password=受權碼
set smtp-auth=login
4.4 配置postfix
vim /etc/postfix/main.cf
inet_interfaces = all
而後在文件尾部追加下面的內容,vim

relayhost = [smtp.163.com]:25
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_type = cyrus
sender_canonical_maps = hash:/etc/postfix/sender_canonical
4.5 配置postfix密碼
echo '[smtp.163.com]:25 test@163.com:受權碼' > /etc/postfix/sasl_passwd
echo 'root test@163.com' > /etc/postfix/sender_canonical
postmap /etc/postfix/sasl_passwd && postmap /etc/postfix/sender_canonical服務器

查看/etc/postfix有沒有生成sasl_passwd.db和sender_canonical.db文件肯定生成後重啓posftfix
systemctl restart postfix網絡

4.6 配置kibana.xml
vim /etc/kibana/kibana.cml #在文件尾部加入下面的內容,
sentinl:
settings:
email:
active: true
user: test@163.com
password: 受權碼
host: smtp.163.com
ssl: true
report:
active: true
tmp_path: /tmp/ide

重啓kibana,便可在kibana界面手動觸發報警測試郵件發送是否正常。工具

相關文章
相關標籤/搜索