2016-04-29 44 views
3

我已經用我的elasticsearch主機配置了elastalert實例。 我還創建了一個示例規則,它將在日誌中匹配日誌時檢查日誌級別併發出警報。自定義彈性搜索彈性搜索插件收到的警報中的信息

一切工作正常,我正確地得到我的鬆弛通道上的警報。

唯一關心的是我收到的警報中的信息/數據。 elastalert插件發送與我正在尋找的模式相關的所有屬性;但我對所有的信息都不感興趣。我關心的只是一些特定的屬性。

這裏是我的規則的例子:

# Alert when the rate of events exceeds a threshold 

# (Optional) 
# Elasticsearch host 
es_host: 

# (Optional) 
# Elasticsearch port 
es_port: 

# (OptionaL) Connect with SSL to elasticsearch 
#use_ssl: True 

# (Optional) basic-auth username and password for elasticsearch 
#es_username: someusername 
#es_password: somepassword 

# (Required) 
# Rule name, must be unique 
name: DB2 test Rule 

# (Required) 
# Type of alert. 
# the frequency rule type alerts when num_events events occur with timeframe time 
type: frequency 

# (Required) 
# Index to search, wildcard supported 
index: logstash-* # logstash-2016.04.05 #logstash-YYYY.MM.DD # logstash-* 

# (Required, frequency specific) 
# Alert when this many documents matching the query occur within a timeframe 
num_events: 1 

# (Required, frequency specific) 
# num_events must occur within this amount of time to trigger an alert 
timeframe: 
    hours: 12 

# (Required) 
# A list of elasticsearch filters used for find events 
# These filters are joined with AND and nested in a filtered query 
# For more info: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html 
filter: 
- query: 
    query_string: 
     query: "type: db2 AND logLevel: Warning" 

# (Required) 
# The alert is use when a match is found 
alert: 
- "slack" 
slack: 
slack_webhook_url: "XYZ" 

而且我對我的鬆弛渠道獲得警報看起來像這樣:

DB2 test Rule 
DB2 test Rule 

At least 1 events occurred between 2016-04-29 07:51 UTC and 2016-04-29 19:51 UTC 

@timestamp: 2016-04-29T19:51:45.940Z 
@version: 1 
_id: 
_index: logstash-2016.04.29 
_type: db2 
apphdl: 
appid: 
authid: 
day: 29 
db: NEO 
eduid: 
eduname: 
function: 
host: 
hostname: 
hour: 14 
id: 
instance: 
logLevel: Warning 
logMessage: 
LOADID: 
DATA #2 : 
Completed 
message:  LEVEL: Warning 

和等等...

我想定製此警報消息,以便它只警告我關心的那些屬性。(對於時間線,日誌級別和幾個更多。)

有沒有辦法做到這一點?非常感謝一些幫助或指導。

回答

8

根據ElastAlert documentation,可以使用include將警報限制爲僅包含文檔中的某些字段。

你的情況,那就是:

include: ["@timestamp", "logLevel", "message"] 
+1

我將測試它和獎勵賞金,感謝分享。 –

+0

太棒了,謝謝! – Val