elastalert은 이제 지원하지 않습니다.

CentOS에서는 키바나 UI에서 설치하는 방법을 작성했었습니다.

 

이번에는 elastalert2로 설치하는 방법을 안내합니다.

kibana UI에서 설정 하지 않고, 터미널에서 직접 설정하는 방법으로 진행했습니다.

elastalert2로 설치하니까 금방이네요~

root@syslogserver:~# pip install elastalert2
root@syslogserver:~# cd /opt
root@syslogserver:~# git clone https://github.com/jertel/elastalert2.git
root@syslogserver:~# cd elastalert2
root@syslogserver:~/elastalert2# pip install "setuptools>=11.3"
root@syslogserver:~/elastalert2# python3 setup.py install
root@syslogserver:~/elastalert2# cd /opt
# elastalert 설치하신 후 "elastalert " 이라고 명령어를 치면 에러 메시지가 보입니다.
# 이때 경로 확인이 가능해요.
root@syslogserver:/opt# ln -s /usr/local/lib/python3.10/dist-packages/elastalert/ ./elastalert
root@syslogserver:/opt# ls -al
root@syslogserver:/opt# ls -al
total 8476
drwxr-xr-x  5 root    root       4096  1월 15 12:26 .
drwxr-xr-x 20 root    root       4096 12월 22 15:41 ..
lrwxrwxrwx  1 root    root         51  1월 15 12:26 elastalert -> /usr/local/lib/python3.10/dist-packages/elastalert/
drwxr-xr-x  3 grafana grafana    4096 12월 26 17:27 grafana-plugin
drwxr-xr-x  2 root    root       4096 12월 22 15:45 node_modules
drwxr-xr-x  2    1001    1002    4096 12월 21 12:55 snmp_exporter
root@syslogserver:/opt# cd elastalert
root@syslogserver:/opt/elastalert# cat ./config.yaml
# 폴더 명
# 폴더 경로를 설정할 경우, elastalert을 실행할 때 rule 옵션을 별도로 주지 않아도 됨
# 예: elastalert --config /opt/elastalert/config.yaml
rules_folder: /opt/elastalert/rules

# elasticsearch를 쿼리하는 빈도
run_every:
  minutes: 1

# 쿼리가 실행되는 시간부터 뒤로 늘어나는 쿼리 창의 크기
buffer_time:
  minutes: 15

# elasticsearch host
es_host: 192.168.000.000

# elasticsearch 사용 port
es_port: 9200

# elastalert2가 데이터를 저장할 index
# 굉장히 중요 합니다!!!!
writeback_index: elastalert_status

# 실패한 경고에 대한 재시도 기간
alert_time_limit:
  days: 2
root@syslogserver:/opt/elastalert#
# elasticsearch index를 생성하지 않으면 아래처럼 오류 발생
root@syslogserver:/opt/elastalert# elastalert


WARNING:elasticsearch:POST http://192.168.000.000:9200/elastalert_status/_search?size=1000 [status:404 request:0.027s]
ERROR:elastalert:Error finding recent pending alerts: NotFoundError(404, 'index_not_found_exception', 'no such index [elastalert_status]', elastalert_status, index_or_alias) {'query': {'bool': {'must': {'query_string': {'query': '!_exists_:aggregate_id AND alert_sent:false'}}, 'filter': {'range': {'alert_time': {'from': '2024-01-13T03:27:38.609562Z', 'to': '2024-01-15T03:27:38.609590Z'}}}}}, 'sort': {'alert_time': {'order': 'asc'}}}
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/elastalert/elastalert.py", line 1503, in find_recent_pending_alerts
    res = self.writeback_es.search(index=self.writeback_index, body=query, size=1000)
  File "/usr/local/lib/python3.10/dist-packages/elasticsearch/client/utils.py", line 152, in _wrapped
    return func(*args, params=params, headers=headers, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/elastalert/__init__.py", line 147, in search
    results = self.transport.perform_request(
  File "/usr/local/lib/python3.10/dist-packages/elasticsearch/transport.py", line 392, in perform_request
    raise e
  File "/usr/local/lib/python3.10/dist-packages/elasticsearch/transport.py", line 358, in perform_request
    status, headers_response, data = connection.perform_request(
  File "/usr/local/lib/python3.10/dist-packages/elasticsearch/connection/http_requests.py", line 199, in perform_request
    self._raise_error(response.status_code, raw_data)
  File "/usr/local/lib/python3.10/dist-packages/elasticsearch/connection/base.py", line 315, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
elasticsearch.exceptions.NotFoundError: NotFoundError(404, 'index_not_found_exception', 'no such index [elastalert_status]', elastalert_status, index_or_alias)
^C
root@syslogserver:/opt/elastalert#
# elasticsearch index 생성
root@syslogserver:/opt/elastalert# elastalert-create-index
Enter Elasticsearch host: 192.168.000.000
Enter Elasticsearch port: 9200
Use SSL? t/f: f
Enter optional basic-auth username (or leave blank):
Enter optional basic-auth password (or leave blank):
Enter optional Elasticsearch URL prefix (prepends a string to the URL of every request):
New index name? (Default elastalert_status)
Name of existing index to copy? (Default None)
Reading Elastic 8 index mappings:
Reading index mapping 'es_mappings/8/silence.json'
Reading index mapping 'es_mappings/8/elastalert_status.json'
Reading index mapping 'es_mappings/8/elastalert.json'
Reading index mapping 'es_mappings/8/past_elastalert.json'
Reading index mapping 'es_mappings/8/elastalert_error.json'
Deleting index elastalert_status_status.
Deleting index elastalert_status_error.
New index elastalert_status created
Done!
root@syslogserver:~#
# elastalert 명령어를 실행할 경우 기본적으로 현재의 경로에서 config.yaml을 찾게 됩니다.
# 그래서 아래와 같은 오류 메시지를 볼 수 있습니다.
root@syslogserver:~# elastalert
Traceback (most recent call last):
  File "/usr/local/bin/elastalert", line 33, in <module>
    sys.exit(load_entry_point('elastalert2==2.15.0', 'console_scripts', 'elastalert')())
  File "/usr/local/lib/python3.10/dist-packages/elastalert/elastalert.py", line 1900, in main
    client = ElastAlerter(args)
  File "/usr/local/lib/python3.10/dist-packages/elastalert/elastalert.py", line 127, in __init__
    self.conf = load_conf(self.args)
  File "/usr/local/lib/python3.10/dist-packages/elastalert/config.py", line 49, in load_conf
    conf = read_yaml(filename)
  File "/usr/local/lib/python3.10/dist-packages/elastalert/yaml.py", line 6, in read_yaml
    with open(path) as f:
FileNotFoundError: [Errno 2] No such file or directory: 'config.yaml'
root@syslogserver:~#
# 단발성으로 실행할 경우 아래의 명령어를 통해서 실행
root@syslogserver:~# python3 -m elastalert.elastalert --verbose --config /opt/elastalert/configy.yaml
# systemctl에 등록하여 실행할 경우
root@syslogserver:~# cd /etc/systemd/system
root@syslogserver:/etc/systemd/system# cat elastalert.service
[Unit]
Description=Severe_logalerts
After=elasticsearch.service

[Service]
Type=simple
WorkingDirectory=/opt/elastalert
ExecStart=/usr/local/bin/elastalert --verbose --config /opt/elastalert/config.yaml

[Install]
WantedBy=multi-user.target
root@syslogserver:/etc/systemd/system# systemctl daemon-reload
root@syslogserver:/etc/systemd/system# systemctl restart elastalert.service

 

아래 사이트 참고하세요.

https://elastalert2.readthedocs.io/en/latest/running_elastalert.html#downloading-and-configuring

 

Getting Started — ElastAlert 2 0.0.1 documentation

ElastAlert 2 can easily be run as a Docker container or directly on your machine as a Python package. If you are not interested in modifying the internals of ElastAlert 2, the Docker container is recommended for ease of use. As a Kubernetes deployment The

elastalert2.readthedocs.io

 

'기술 노트 > ubuntu' 카테고리의 다른 글

snmp-exporter에 MIB 등록하기  (0) 2024.02.07
elastalert2 rules 설정  (0) 2024.01.15
grafana 알람 설정  (0) 2024.01.08
apt로 grafana 설치하기  (1) 2024.01.08
grafana user admin 권한 부여하기  (0) 2023.12.21

+ Recent posts