ElasticSearch로 서버로그를 분석하는 시스템 중 로그의 특정 키워드값을 읽어서 알람기능을 제공하는 것이 ElastAlert 이다.
$ yum install python3
$ yum install python-pip
$ pip -V => pip 21.0.1 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
$ pip install "setuptools>=11.3" python setup.py install
$ pip install elastalert
config 파일과 rule 파일을 작성해야 기본적인 테스트가 가능합니다.
/usr/local/lib/python3.6/site-packages/elastalert
filter:
- query:
query_string:
query: "username: bob"
- query:
query_string:
query: "_type: login_logs"
- query:
query_string:
query: "field: value OR otherfield: othervalue"
- query:
query_string:
query: "this: that AND these: those"
filter:
- term:
name_field: "bob"
- term:
_type: "login_logs"
filter:
- terms:
field: ["value1", "value2"] # value1 OR value2
- terms:
fieldX: ["value1", "value2"]
fieldY: ["something", "something_else"]
fieldZ: ["foo", "bar", "baz"]
*
문자를 사용하여 유사값을 매칭 시킬수있는 방식filter:
- query:
wildcard:
field: "foo*bar"
filter:
- range:
status_code:
from: 500
to: 599
filter:
- query:
query_string:
query: "somefield: somevalue OR foo: bar"
alert:
- "email"
email:
- "elastalert@example.com"
smtp_host:"smtp.gmail.com"
smtp_port: 465
smtp_ssl: true
from_addr: "user_from@gmail.com"
smtp_auth_file: "/home/user/mailauth.yaml"
$ python3.6 -m elastalert.elastalert --verbose --config config.yaml --rule rule.yaml
1 rules loaded
INFO:elastalert:Starting up
INFO:elastalert:Disabled rules are: []
INFO:elastalert:Sleeping for 59.999873 seconds
INFO:elastalert:Queried rule example_frequency.yaml from 2021-02-26 16:05 KST to 2021-02-26 16:06 KST: 35 / 35 hits
INFO:elastalert:Sent email to ['xxxxx@gmail.com']
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ignoring match for silenced rule example_frequency.yaml
INFO:elastalert:Ran example_frequency.yaml from 2021-02-26 16:05 KST to 2021-02-26 16:06 KST: 35 query hits (0 already seen), 35 matches, 1 alerts sent
참고로 테스트를 위해 임의의 값을 logstash로 던지는 파이썬 프로그램을 실행한 상태입니다.