2016-11-28 3 views
0

스파이크가 발생할 때 알리도록 알림을 설정하고 싶습니다.스파이웨어 광고에 스크립트를 통합하는 방법

"_source": { 
      "@timestamp": 2016-11-23T18:30:45.233Z, 
      "invalid_request": 400, 
      "total_request": 40000 
     } 

내가 설정에 유효하지 않은 요청 비율이 20 분 동안 스파이크가있는 경우 나에게 이메일을 발송 스파이크 경고를 원하지만, 다음과 같은 규칙 YAML은 나에게 어떤 타격을주지 않습니다 내 데이터는 다음과 같은 구성되어있다.

# (Required) 
# Rule name, must be unique 
name: Invlid Count Spike 

# (Required) 
# Type of alert. 
# (Required) 
# Index to search, wildcard supported 
index: logstash-* 

# (Required one of _cur or _ref, spike specific) 
# The minimum number of events that will trigger an alert 
threshold_cur: 1 
#threshold_ref: 5 
# The size of the window used to determine average event frequency 
# We use two sliding windows each of size timeframe 
# To measure the 'reference' rate and the current rate 
timeframe: 
    minutes: 20 

# (Required, spike specific) 
# The spike rule matches when the current window contains spike_height times more 
# events than the reference window 
spike_height: 2 

# (Required, spike specific) 
# The direction of the spike 
# 'up' matches only spikes, 'down' matches only troughs 
# 'both' matches both spikes and troughs 
spike_type: "both" 

# (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/c 
urrent/query-dsl.html 
script_fields: 
    invalid_ratio: 
    script: 
     doc['invalid_request'].value/doc['total_request'].value 
filter: 
- range: 
    invalid_ratio: 
     gt: 0 

# (Required) 
# The alert is use when a match is found 
alert: 
- "email" 

# (required, email specific) 
# a list of email addresses to send alerts to 
email: 
- "[email protected]" 

난 그냥 간단한 쿼리를 넣어 경우 이메일을 전송하기 때문에 내가 확인하고있다 보내는 내 이메일을 알고있다 (예 : 트리거로 total_request는 0보다 큰 경우),하지만 내가 넣어 스크립트를 보인다 내가 기대했던대로 일했다. 탄성 고무에 익숙한 사람이면 누구나이 문제에 큰 도움이 될 것입니다. 감사.

답변

0

실제로 이것을 시도하지는 않았지만 ES 필터가 잘못되었다고 생각합니다. script_fields은 Elastalert에서 지원하지 않습니다. 그렇다고하더라도 어쨌든 range 필터 안에 script_fields을 참조 할 수는 없습니다 (ES에서 지원하지 않음).

그래도 script query을 사용해 볼 수 있습니다. 당신의 script_fields 부분을 제거하고이 함께 filter 부분을 대체 :

filter: 
- script: 
    script: 
     inline: doc['invalid_request'].value/doc['total_request'].value > threshold 
     params: 
     threshold: 0 
+0

당신은이 일을 할 수 있었습니까? – Val