Kibana插件sentinl使用教程

介绍

对于Kibana的一些数据我们有时候是想要对某些字段进行持续关注的,这时候通过报警的手段就可以大幅提升对这些信息状态了解的及时性及可靠性。使用sentinl插件就可以帮助我们实现这个功能。

此教程基于sentinl 6.2.3版本, sentinl版本最好与kibana的版本保持一致。

sentinl插件下载地址:https://github.com/sirensolutions/sentinl/releases。

sentinl文档地址:http://sentinl.readthedocs.io/en/latest/

使用步骤

1.在kibana界面上配置sentinl,点击右上角new创建watchers
在这里插入图片描述
2.点击 +watcher创建新的Watcher
在这里插入图片描述
3.填写General页面内容, title是watcher的名称,Schedule是执行周期。
在这里插入图片描述
4.填写input页面内容, body 里面填写ES查询语句,可根据具体业务编写相应的查询语句
在这里插入图片描述
5.填写Condition页面内容, payload.hits.total > 1 (当查询结果数大于1时,触发Actions),可以自己制定条件。
在这里插入图片描述
6.Transform 可对input查询的结果做一些处理,此处没有使用,可以不填写
在这里插入图片描述
7.填写Actions页面内容,Actions包括webhook,email,email html,report,slack,console,此处介绍webhook。
在这里插入图片描述
7.1 使用webhook发rest请求,可以选择 get或post两种方式。
在这里插入图片描述
7.1.1 填好对应数据之后,点击右上角的Save按钮。
在这里插入图片描述
7.1.2 可以点击单次执行按钮进行测试。如下显示接收到参数,测试成功
在这里插入图片描述
7.2 使用webhook执行新的watchers(仅执行一次),在新的watchers中发rest请求。
在这里插入图片描述
path: /api/sentinl/watcher/_execute(固定值)

body的内容如下:

 {
     "_source": {
         "actions": {
             "testRest": {
                 "throttle_period": "0h0m10s",
                 "webhook": {
                     "method": "POST",
                     "host": "10.16.232.66",
                     ,
                     "proxy": false,
                     "path": "/kyle",
                     "body": "{\n \"id\":100,\n \"name\":\"kyle20\"\n}"
                 }
             }
         },
         "input": {
             "search": {
                 "request": {
                     "index": [
                         "movies"
                     ],
                     "body": {
                         "query": {
                             "match_all": {}
                         }
                     }
                 }
             }
         },
         "condition": {
             "script": {
                 "script": "payload.hits.total > 1"
             }
         },
         "transform": {},
         "trigger": {
             "schedule": {
                 "later": "every 5 minutes"
             }
         },
         "disable": true,
         "report": false,
         "title": "watcher_title"
     }
 }

测试结果:
在这里插入图片描述
7.3 使用sentinl 执行多个watcher方案
在这里插入图片描述
原理:将第一个watcher的结果写入es index 中,以供其他watcher使用(可以作为触发其他watcher方式)

7.3.1 新建第一个watcher,内容如下:

{
   "actions": {
     "New console action txv1ad1yazr": {
       "throttle_period": "0h0m1s",
       "console": {
         "message": "{\n{{#payload.hits.hits}}\n\"name\":\"{{_source.name}}\",\n\"age\":{{_source.age}}\n{{/payload.hits.hits}}\n}"
       }
     },
     "New webhook action 20wm9sojv9j": {
       "throttle_period": "0h0m1s",
       "webhook": {
         "method": "POST",
         "host": "10.16.232.163",
         ,
         "proxy": false,
         "path": "/twoindex/doc",
         "body": "{\n{{#payload.hits.hits}}\n\"name\":\"{{_source.name}}\",\n\"age\":{{_source.age}}\n{{/payload.hits.hits}}\n}",
         "save_payload": false,
         "headers": {
           "content-type": "application/json"
         }
       }
     }
   },
   "input": {
     "search": {
       "request": {
         "index": [
           "trumantest"
         ],
         "body": {
           "query": {
             "match": {
               "
             }
           }
         }
       }
     }
   },
   "condition": {
     "script": {
       "script": "payload.hits.total > 0"
     }
   },
   "transform": {},
   "trigger": {
     "schedule": {
       "later": "every 1 minutes"
     }
   },
   "disable": false,
   "report": false,
   "title": "first_watcher"
 }

第一个watcher 主要是检测 trumantest是否含有"age": “19” 数据,如果有,将该结果写入twoindex 中。

7.3.2新建第二个watcher,主要检测index 数量,如果大于1,则在console 中输出

 {
   "actions": {
     "New console action 34fsgrz5dhd": {
       "throttle_period": "0h0m1s",
       "console": {
         "message": "this is a measage :{{payload.hits.total}}"
       }
     }
   },
   "input": {
     "search": {
       "request": {
         "index": [
           "twoindex"
         ],
         "body": {
           "query": {
             "match_all": {}
           }
         }
       }
     }
   },
   "condition": {
     "script": {
       "script": "payload.hits.total > 1"
     }
   },
   "transform": {},
   "trigger": {
     "schedule": {
       "later": "every 1 minutes"
     }
   },
   "disable": false,
   "report": false,
   "title": "two_watcher"
 }

7.3.3实验结果:

在这里插入图片描述

参考链接:

https://www.bbsmax.com/A/gGdXbgXmJ4/

Kibana插件sentinl实现邮件报警(centos) : https://www.bbsmax.com/A/kPzO731wzx/

发布了349 篇原创文章 · 获赞 60 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/qq_40907977/article/details/104721130
今日推荐