ElastAlert๋?
- Elasticsearch์ ๋ฐ์ดํฐ์์ ์์ฑํ ๊ท์น์ ๋ฐ๋ผ์ ์๋ฆผ์ ์ ์กํ๋ ํ๋ ์์ํฌ.
- Elasticsearch์ ์ค์๊ฐ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋กํ๊ณ ์๊ณ ํด๋น ๋ฐ์ดํฐ๊ฐ ํน์ ํจํด(๊ท์น)๊ณผ ์ผ์นํ ๋ ์๋ฆผ์ ๋ฐ๊ณ ์ถ์ ๋ ์ฌ์ฉํ ์ ์์.
ElastAlert ์๋ ๋ฐฉ์
๋ฐ์ดํฐ ์์ค๋ฅผ ์ฃผ๊ธฐ์ ์ผ๋ก ์ฟผ๋ฆฌ
โ ์ ์ํ ๊ท์น ์ ํ์ ์ผ์นํ๋ ์ง๋ฅผ ๊ฒ์ฌ
โ ์ผ์นํ๋ค๋ฉด ์ ์ํ ๋ฐฉ๋ฒ์ผ๋ก alert ๋ฐ
ElastAlert ๊ท์น ๊ตฌ์ฑ
name
: ๊ท์น์ ๊ณ ์ ํ ์ด๋ฆ. ๋์ผํ ์ด๋ฆ์ด 2๊ฐ ์ด์์ผ ๊ฒฝ์ฐ ElastAlert๊ฐ ์์๋์ง ์๋๋ค.index
: ์ฟผ๋ฆฌํ ๋ฐ์ดํฐ ์์ค์ ์์น. ์์ผ๋ ์นด๋, ์ฌ๋ฌ๊ฐ ์ฌ์ฉ ๊ฐ๋ฅ
index: topbeat-*,packetbeat-*
type
: ๊ท์น์ ์ ํ. type์ ๋ฐ๋ผ ๋ค์ํ ๋ฐฉ๋ฒ์ผ๋ก alert๋ฅผ ๋ฐ์์ํฌ ์ ์์ต๋๋ค.
realert
: ํด๋น ๊ท์น์ผ๋ก ์ธํ alert๊ฐ ๋ค์ ๋ณด๋ด์ง๋๊น์ง์ ์ต์ ์๊ฐ
filter
: ๋ฐ์ดํฐ์์ ๊ฒฐ๊ณผ๋ฅผ ํํฐ๋ง ํ๋๋ฐ ์ฌ์ฉํ๋ ๊ธฐ์ค.
alert
: alert ์ ํ (Slack, AWS SES, AWS SNS, Discord, Email, GoogleChat, HTTP POST ๋ฑ๋ฑ)
alert_text
: alert ๋ฉ์ธ์ง ๊ตฌ์ฑ
alert_text_type
: ๋ฉ์ธ์ง์ ํ์
alert_text_args
: ๋ฉ์ธ์ง์์ ์ฌ์ฉํ ๋งค๊ฐ๋ณ์
- Jinja Template (alert_text_jinja)
alert_text_type: alert_text_jinja
alert_text:
Alert triggered! *({{num_hits}} Matches!)*
Something happened with {{username}} ({{email}})
{{description|truncate}}
- ํ์ด์ Formatting ๋ฌธ๋ฒ (alert_text_only)
alert_text: "Something happened with {0} at {1}"
alert_text_type: alert_text_only
alert_text_args: ["username", "@timestamp"]
Filter ์ ํ
query_string
filter:
- query:
query_string:
query: "field: value OR otherfield: otherval
term
filter:
- term:
name_field: "bob"
terms
- terms:
fieldX: ["value1", "value2"]
wildcard
filter:
- query:
wildcard:
field: "foo*bar"
range
filter:
- range:
status_code:
from: 500
to: 599
Rule Type
any
ํ์ ์ผ์นํ๋ ๋ชจ๋ ๋ฐ์ดํฐ์ ๋ํด์ alert ๋ฐ์
blacklist
๋ชจ๋ํฐ๋ง ํ๋๋ฅผ ํ์ธํ๊ณ ๋ฐ์ดํฐ๊ฐ ๋ธ๋๋ฆฌ์คํธ์ ์์ผ๋ฉด alert ๋ฐ์
- compare_key : ๋ชจ๋ํฐ๋ง ํ๋, ํด๋น ํ๋๊ฐ null์ด๋ฉด ๋ฐ์ดํฐ๊ฐ ๋ฌด์๋๋ค.
- blacklist : ๋ธ๋๋ฆฌ์คํธ ๊ฐ or ๋ธ๋๋ฆฌ์คํธ ๊ฐ์ ํฌํจํ๋ ํ์ผ์ ๊ฒฝ๋ก
# (Required)
type: **blacklist**
# (Required)
****compare_key: filed1
# (Required)
blacklist:
- value1
- value2
- "!file /tmp/blacklist1.txt"
- "!file /tmp/blacklist2.txt"
whitelist
๋ชจ๋ํฐ๋ง ํ๋๋ฅผ ํ์ธํ๊ณ ๋ฐ์ดํฐ๊ฐ ํ์ดํธ๋ฆฌ์คํธ์ ์์ผ๋ฉด alert ๋ฐ์
- compare_key : ๋ชจ๋ํฐ๋ง ํ๋
- ignore_null : true์ผ ๋ ํด๋น ํ๋๊ฐ null์ด๋ฉด ๋ฐ์ดํฐ๊ฐ ๋ฌด์๋๋ค.
- whitelist : ํ์ดํธ๋ฆฌ์คํธ ๊ฐ or ํ์ดํธ๋ฆฌ์คํธ ๊ฐ์ ํฌํจํ๋ ํ์ผ์ ๊ฒฝ๋ก
# (Required)
type: **whitelist**
ignore_null: true
# (Required)
compare_key: filed1
# (Required)
whitelist:
- value1
- value2
- "!file /tmp/whitelist1.txt"
- "!file /tmp/whitelist2.txt"
change
๋ชจ๋ํฐ๋ง ํ๋์ ๋ํด์ ๊ฐ์ด ๋ฌ๋ผ์ง๋ฉด alert ๋ฐ์
- compare_key : ๋ชจ๋ํฐ๋ง ํ๋, ํ๋๋ฅผ ์ฌ๋ฌ๊ฐ ์ ์ ๊ฐ๋ฅ
- ignore_null : ํ๋๊ฐ ์์ผ๋ฉด ๋ฐ์ดํฐ ๋ฌด์
- query_key : ํด๋น ํ๋์ ๊ฐ์ด ๊ฐ์ ๊ฒฝ์ฐ์ compare_key๋ฅผ ๋น๊ต
- timeframe : query_key์ ๋ํ ๋ง์ง๋ง ๊ฒฐ๊ณผ๋ฅผ ์ผ๋ง๋ ์ ์ง์ํฌ์ง. (Optional)
# (Required)
name: New country login
# (Required)
type: change
# (Required)
index: logstash-*
# (Required)
compare_key: country_name
# (Required)
ignore_null: true
# (Required)
query_key: username
timeframe:
days: 1
# (Required)
filter:
- query:
query_string:
query: "document_type: login"
frequency
ํํฐ์ ์ผ์นํ๋ ์ด๋ฒคํธ์ ์๊ฐ ์ผ์ ์๋ฅผ ๋๊ธฐ๋ฉด alert ๋ฐ์
- num_events : alert๋ฅผ ๋ฐ์์ํฌ ์ด๋ฒคํธ์ ์
- timeframe : num_events์ ์๋ฅผ ์ธก์ ํ๋ ์๊ฐ
# (Required)
name: Example frequency rule
# (Required)
type: frequency
# (Required)
index: logstash-*
# (Required, frequency specific)
num_events: 50
# (Required, frequency specific)
timeframe:
hours: 4
# (Required)
filter:
- term:
some_field: "some_value"
spike
ํน์ ๊ธฐ๊ฐ์ ์ด๋ฒคํธ ์๊ฐ, ํน์ ๋ฐฐ์๋งํผ ์ฆ๊ฐํ๊ฑฐ๋ ์ค์ด๋ค์์ ๋ alert ๋ฐ์
- spike_height : alert๋ฅผ ๋ฐ์์ํฌ ์ด๋ฒคํธ ๋ฐฐ์
- spike_type : 'up' or 'down' or 'both'
up ์ ์ฆ๊ฐํ์ ๋
down์ ๊ฐ์ํ์ ๋
both๋ ์ฆ๊ฐ, ๊ฐ์ ํ์ ๋ - timeframe : ๋น๊ตํ ๊ธฐ๊ฐ ์ ์
- threshold_ref : reference์ ํด๋นํ๋ ์ต์ ์ด๋ฒคํธ ์
- threshold_cur : current์ ํด๋นํ๋ ์ต์ ์ด๋ฒคํธ ์
- field_value : ์ด๋ฒคํธ์ ์๊ฐ ์๋ ํด๋น ํ๋์ ๊ฐ์ ๊ธฐ์ค์ผ๋ก alert๋ฅผ ๋ฐ์ -> ์จ๋๋ฅผ ๋ชจ๋ํฐ๋งํ ๋ ์ ์ฉ
# (Required)
name: Event spike
# (Required)
type: spike
# (Required)
index: logstash-*
# (Required one of _cur or _ref, spike specific)
threshold_cur: 15
#threshold_ref: 5
# (Required, spike specific)
timeframe:
hours: 2
# (Required, spike specific)
spike_height: 4
# (Required, spike specific)
spike_type: "up"
# (Required)
filter:
- query:
query_string:
query: "field: value"
# 10:00 ~ 11:00 : 5 events (ref: 0, cur: 5) - Alert X
# 11:00 ~ 12:00 : 5 events (ref: 0, cur: 10) - Alert X
# 12:00 ~ 13:00 : 10 events (ref: 5, cur: 15) - Alert X
# 13:00 ~ 14:00 : 35 events (ref: 10, cur: 45) - Alert O
flatline
์ด๋ฒคํธ์ ์ด ์๊ฐ ์ผ์ ๊ธฐ๊ฐ ๋์ ์ง์ ๋ ์๊ณ๊ฐ ์๋์ ์์ ๋ alert ๋ฐ์
- threshold : alert๊ฐ ๋ฐ์๋์ง ์์ ์ต์ ์ด๋ฒคํธ ์
- timeframe : ๋ชจ๋ํฐ๋ง ๊ธฐ๊ฐ
# (Required)
name: Event flatline
# (Required)
type: flatline
# (Required)
index: logstash-*
# (Required)
threshold: 15
# (Required)
timeframe:
hours: 2
# (Required)
filter:
- query:
query_string:
query: "field: value"
new_term
์๋ก์ด ๊ฐ์ด ๋ค์ด์ค๋ฉด alert ๋ฐ์
- fileds : ๋ชจ๋ํฐ๋ง filed, ์์ผ๋ฉด query_key ์ฌ์ฉ
# (Required)
name: Event newterm
# (Required)
type: new_term
# (Required)
index: logstash-*
fileds: ["field1"]
# (Required)
filter:
- query:
query_string:
query: "field: value"
cardinality
ํน์ ํ๋์ ์ ๋ํฌํ ๊ฐ์ ์๊ฐ ์๊ณ๊ฐ๋ณด๋ค ๋๊ฑฐ๋ ๋ฎ์ ๋ alert ๋ฐ์
# Alert when the rate of events exceeds a threshold
# (Required)
# Index to search, wildcard supported
index: logstash-*
# (Required)
# Rule name, must be unique
name: Example cardinality rule
# (Required)
type: cardinality
# (Required, cardinality specific)
# Count the number of unique values for this field
cardinality_field: "Hostname"
# (Required, frequency specific)
# Alert when there less than 15 unique hostnames
min_cardinality: 15
max_cardinality: 15
# (Required, frequency specific)
# The cardinality is defined as the number of unique values for the most recent 4 hours
timeframe:
hours: 4
# (Required)
filter:
- term:
status: "active"
metric_aggregation
ํน์ ํ๋๋ค์ ํฉ, ํ๊ท , ์ต์, ์ต๋ ๋ฑ์ ๊ณ์ฐํ์ฌ ๊ธฐ์ค์ ์ถฉ์กฑํ๋ฉด alert ๋ฐ์
# (Required)
name: Metricbeat CPU Spike Rule
# (Required)
type: metric_aggregation
# (Required)
index: metricbeat-*
buffer_time:
hours: 1
# (Required)
metric_agg_key: system.cpu.user.pct (๊ณ์ฐํ ์ ์๋ ๊ฐ์ด์ฌ์ผํจ.)
# (Required)
metric_agg_type: avg
query_key: beat.hostname
bucket_interval:
minutes: 5
# (Required)
min_threshold: 0.1
# (Required)
max_threshold: 0.8
# (Required)
filter:
- term:
metricset.name: cpu
# (Required)
# The alert is use when a match is found
alert:
- "debug"
spike_aggregation
ํน์ ํ๋๋ค์ ํฉ, ํ๊ท , ์ต์, ์ต๋ ๋ฑ์ ๊ณ์ฐํ ๊ฐ์ด spike_height๋ฐฐ ๋งํผ ์ฆ๊ฐํ๊ฑฐ๋ ์ค์ด๋ค์์ ๋ alert ๋ฐ์
percentage_match
์ฟผ๋ฆฌ or ํ๋์ ๊ฐ์ด ์ค์ ํ ๊ธฐ๊ฐ๋์์ ๋น์จ์ด ์ค์ ํ ๋น์จ๋ณด๋ค ์๊ฑฐ๋, ํด ๋ alert ๋ฐ์
# (Required)
name: Example Percentage Match
# (Required)
type: percentage_match
# (95% ์์ผ๋ฉด alert)
# (Required)
index: logstash-http-request-*
# (Required)
filter:
- term:
_type: http_request
buffer_time:
minutes: 5
query_key: Hostname.keyword
# (Required)
match_bucket_filter:
- terms:
ResponseStatus: [200]
# (Required)
min_percentage: 95
#max_percentage: 60
#bucket_interval:
# minutes: 1
# (Required)
# The alert is use when a match is found
alert:
- "debug"
์ฐธ๊ณ ์ฌ์ดํธ
ElastAlert2 ๊ณต์๋ฌธ์: https://elastalert2.readthedocs.io/en/latest/elastalert.html
'Back-end' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์น์๋ฒ(Web Server)์ ์น ์ดํ๋ฆฌ์ผ์ด์ ์๋ฒ(Web Application Server) (0) | 2023.06.25 |
---|---|
Slack์ผ๋ก OAuth ์ฌ์ฉํ๊ธฐ (0) | 2022.10.31 |
[HTTP] ์๋ต ์ํ ์ฝ๋ ์ ๋ฆฌ (0) | 2021.09.14 |
[REST API]REST API๋? (0) | 2021.08.29 |
[WEB] HTTPS์ SSL์ธ์ฆ์ (0) | 2021.08.29 |