對於Kibana的一些數據咱們有時候是想要對某些字段進行持續關注的,這時候經過報警的手段就能夠大幅提高對這些信息狀態瞭解的及時性及可靠性。使用sentinl插件就能夠幫助咱們實現這個功能。html
此教程基於sentinl 6.2.3版本, sentinl版本最好與kibana的版本保持一致。git
sentinl插件下載地址:https://github.com/sirensolutions/sentinl/releases。github
sentinl文檔地址:http://sentinl.readthedocs.io/en/latest/web
7.1.1 填好對應數據以後,點擊右上角的Save按鈕。json
7.1.2 能夠點擊單次執行按鈕進行測試。以下顯示接收到參數,測試成功api
path: /api/sentinl/watcher/_execute(固定值)app
body的內容以下:post
1 { 2 "_source": { 3 "actions": { 4 "testRest": { 5 "throttle_period": "0h0m10s", 6 "webhook": { 7 "method": "POST", 8 "host": "127.0.0.1", 9 "port": 8030, 10 "proxy": false, 11 "path": "/kyle", 12 "body": "{\n \"id\":100,\n \"name\":\"kyle20\"\n}" 13 } 14 } 15 }, 16 "input": { 17 "search": { 18 "request": { 19 "index": [ 20 "movies" 21 ], 22 "body": { 23 "query": { 24 "match_all": {} 25 } 26 } 27 } 28 } 29 }, 30 "condition": { 31 "script": { 32 "script": "payload.hits.total > 1" 33 } 34 }, 35 "transform": {}, 36 "trigger": { 37 "schedule": { 38 "later": "every 5 minutes" 39 } 40 }, 41 "disable": true, 42 "report": false, 43 "title": "watcher_title" 44 } 45 }
測試結果:測試
原理:將第一個watcher的結果寫入es index 中,以供其餘watcher使用(能夠做爲觸發其餘watcher方式)this
7.3.1 新建第一個watcher,內容以下:
1 { 2 "actions": { 3 "New console action txv1ad1yazr": { 4 "throttle_period": "0h0m1s", 5 "console": { 6 "message": "{\n{{#payload.hits.hits}}\n\"name\":\"{{_source.name}}\",\n\"age\":{{_source.age}}\n{{/payload.hits.hits}}\n}" 7 } 8 }, 9 "New webhook action 20wm9sojv9j": { 10 "throttle_period": "0h0m1s", 11 "webhook": { 12 "method": "POST", 13 "host": "127.0.0.1", 14 "port": 9200, 15 "proxy": false, 16 "path": "/twoindex/doc", 17 "body": "{\n{{#payload.hits.hits}}\n\"name\":\"{{_source.name}}\",\n\"age\":{{_source.age}}\n{{/payload.hits.hits}}\n}", 18 "save_payload": false, 19 "headers": { 20 "content-type": "application/json" 21 } 22 } 23 } 24 }, 25 "input": { 26 "search": { 27 "request": { 28 "index": [ 29 "trumantest" 30 ], 31 "body": { 32 "query": { 33 "match": { 34 "age": "19" 35 } 36 } 37 } 38 } 39 } 40 }, 41 "condition": { 42 "script": { 43 "script": "payload.hits.total > 0" 44 } 45 }, 46 "transform": {}, 47 "trigger": { 48 "schedule": { 49 "later": "every 1 minutes" 50 } 51 }, 52 "disable": false, 53 "report": false, 54 "title": "first_watcher" 55 }
第一個watcher 主要是檢測 trumantest是否含有"age": "19" 數據,若是有,將該結果寫入twoindex 中。
7.3.2新建第二個watcher,主要檢測index 數量,若是大於1,則在console 中輸出
1 { 2 "actions": { 3 "New console action 34fsgrz5dhd": { 4 "throttle_period": "0h0m1s", 5 "console": { 6 "message": "this is a measage :{{payload.hits.total}}" 7 } 8 } 9 }, 10 "input": { 11 "search": { 12 "request": { 13 "index": [ 14 "twoindex" 15 ], 16 "body": { 17 "query": { 18 "match_all": {} 19 } 20 } 21 } 22 } 23 }, 24 "condition": { 25 "script": { 26 "script": "payload.hits.total > 1" 27 } 28 }, 29 "transform": {}, 30 "trigger": { 31 "schedule": { 32 "later": "every 1 minutes" 33 } 34 }, 35 "disable": false, 36 "report": false, 37 "title": "two_watcher" 38 }
7.3.3實驗結果: