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,界面上会多一个这个(下图红圈):git
3.在kibana界面上配置sentinl
点击sentinl→watchers→New(右上角)→“+warcher”(左上角),到以下界面:
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”里的配置为条件,查询出来的结果数,见下图,
3.4 Transform
附属条件,暂时没用。
3.5 Actions
报警动做。
见下图示例,
4.在kibana服务器上配置kibana和mail
4.1 以163邮箱为例,163邮箱受权方式
配置完上面后,会获取到一个客户端受权码,客户端(如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界面手动触发报警测试邮件发送是否正常。工具