본문 바로가기

Elastic Stack

elastalert 설치하기

os : centos7
python : python3
elasticsearch : elasticsearch7.10.2

1. 가상 환경 설치
(로컬에 설치 시 모듈의 상대경로 문제나 패키지 에러가 발생할 수 있음)
#python3 -m pip install virtualenv or pip instll virtualenv
# virtualenv test
# ll test
bin
lib
lib64
# source test/bin/activate

2. elastalert 설치 (가상환경 활성화 후 진행)
(test)[localhost ~]# pip install elastalert
기본 디렉토리 -> test/lib/python3.6/site-packages/elastalert/

3. config 디렉터리 생성 및 config 파일 생성
#mkdir /test/lib/python3.6/site-packages/elastalert/config
#vi /test/lib/python3.6/site-packages/elastalert/config/config.yaml

#rules_folder: rule 파일이 위치한 폴더 rules_folder: test/lib/python3.6/site-packages/elastalert/rules #run_every: 알람의 주기를 설정하는 옵션, python 문법으로 timedelta 옵션에 쓸수있는 값들을 넣으면된다. #days, seconds, microseconds, milliseconds, minutes, hours, weeks run_every: minutes: 1 #buffer_time : 일부 로그소스가 실시간이 아닌 경우 결과를 버퍼링할 최근기간 buffer_time: minutes: 15 #es_host : elasticsearch 호스츠 es_host: elasticsearch.example.com #es_port : elasticsearch 포트 es_port: 9200 #whiteback_index 메타데이터 저장에 사용하는 index #elastalert-create-index 로 아래의 인덱스를 생성해줘야 한다. writeback_index: elastalert_status writeback_alias: elastalert_alerts #alert_time_limit: 알람 실패시 재시도할 주기 alert_time_limit: minuites : 5

#elastalert-create-index

https://github.com/Yelp/elastalert/blob/master/config.yaml.example 참고

Yelp/elastalert

Easy & Flexible Alerting With ElasticSearch. Contribute to Yelp/elastalert development by creating an account on GitHub.

github.com

4. rules 디렉터리 생성 및 rule.yaml 파일 생성
mkdir test/lib/python3.6/site-packages/elastalert/rules
vi test/lib/python3.6/site-packages/elastalert/rules/rule.yaml

#name : 알람명 고유한 이름으로 사용 name: test-alert #type : 알람의 타입, 다양한 타입이 있는데 이것은 다음 게시글에 따로 정리하겠다.. #frequency - Y 시간에 X 개의 이벤트가있는 위치 일치할때 노티, timeframe, num_events 옵션을 사용한다. type: frequency #index : 해당 rule이 탐색할 elasticsearch의 인덱스 index: filebeat-* # use_strftime_index: true #num_events : 정해진 time_frame 시간동안 일정 횟수이상 document 매치시 알람 발생. num_events: 1 #timeframe : num_events 카운트를측정할 시간 단위 timeframe: hours: 1 #filter : 인덱스에서 매칭시킬 조건. #filter 조건도 자세하게 다음 게시글에 다루겠음.. filter: - query: query_string: query: "src_country: cn" #alert_text: 알람 메시지 형식 alert_text : "\nAttack_name: {0} \nSrc_IP: {1} \nDst_IP: {2} \n Dst_Port: {3}" #alert_text_type: "alert_text_only" - 인덱스 전체 필드 중 설정한 필드만 알람 받음 alert_text_type: "alert_text_only" #alert_text_args : 알람 받을 인덱스 필드 리스트 형식 alert_text_args : ["attack_name', "src_ip", "dst_ip", "dst_port"] # alert : 알람 받을 채널 alert: - command - email - telegram - slack # 알람 행위 command: "echo test >> /home/alert.log" email : test@test.kr telegram_bot_token : "122499....." telegram_room_id : "8011...." slack_webhook_url: "https://hooks.slack.com/services/SLA......." slack_username_override: "ElastAlert-Bot" slack_channel_override: "#monitoring" slack_emoji_override: ":robot_face:" slack_msg_color: "danger"






5. 실행
#elastalert --verbode --rule rules/test.yaml --config config/config.yaml
실행 안될시 디버깅 로그 보기
#elastalert -debug --rule rules/test.yaml --config config/config.yaml








docker 설치
https://github.com/johnsusek/elastalert-server <-
xpack 인증 되는 이미지로 설치해야한다 아니면 인증에러남..



https://githubmemory.com/repo/johnsusek/elastalert-server