Yelp / elastalert

Easy & Flexible Alerting With ElasticSearch
https://elastalert.readthedocs.org
Apache License 2.0
8k stars 1.73k forks source link

Elastalert is not triggering email to gmail account #3220

Closed MohdRashid01 closed 3 years ago

MohdRashid01 commented 3 years ago

Hi All,

I have setup elk with elastalert plugin install in elk as docker container and docker service is working fine. But email is not working.

Please tell me where im wrong and why email is not triggering previous few months back it was working due some issue it was not working. So i setup a new elastalert

Here is the elastalert.yml with the file is docker-compse.yml cat docker-compose.yml

version: '3.3'

services:

  elastalert:
    image: devopssysadmin/elastalert:latest 
#    ports:
#      - 3030:3030
    volumes:
      - ./config/elastalert.yaml:/opt/elastalert/config.yaml
      - ./config/config.json:/opt/elastalert-server/config/config.json
      - ./config/elastalert.yaml:/opt/elastalert-server/config/elastalert.yaml
      - ./rules:/opt/elastalert/rules:rw
      - ./config/smtp_auth_file.yml:/opt/elastalert/smtp_auth_file.yml
      - ./rule_templates:/opt/elastalert/rule_templates
    environment:
#      ES_JAVA_OPTS: "-Xmx256m -Xms256m"
      ELASTIC_USERNAME: "xxxxx"
      ELASTIC_PASSWORD: "xxxxx"

And Here is the smtp_auth_file.yml

smtp_host: smtp.gmail.com
from_addr: rashidmd777@gmail.com
user: rashidmd777@gmail.com
password: xxxxxxx

And Here is the Email Alert trigger to my gmail account added in ElastAlert Kibana Plugin

# Alert when the rate of events exceeds a threshold

# (Optional)
# Elasticsearch host
# es_host: elasticsearch.example.com

es_host: xxxxxx
# (Optional)
# Elasticsearch port
es_port: 14900

# (OptionaL) Connect with SSL to Elasticsearch
#use_ssl: True

# (Optional) basic-auth username and password for Elasticsearch
es_username: xxxxxx
es_password: xxxxx

# (Required)
# Rule name, must be unique
name: Exception Alert

# (Required)
# Type of alert.
# the frequency rule type alerts when num_events events occur with timeframe time
#type: blacklist
type: any
include: ["message"]

#aggregation: 
#   minutes: 1

# (Required)
# Index to search, wildcard supported
index: logstash*

# (Required, frequency specific)
# Alert when this many documents matching the query occur within a timeframe
#num_events: 1

# (Required, frequency specific)
# num_events must occur within this amount of time to trigger an alert
timeframe:
#  hours: 1
#  minutes: 1
  seconds: 1

#compare_key: "message"

#blacklist:

#- "error"

realert:
  minutes: 5

#This is send out all matches in one email

#  seconds: 0
#filter:
#- term:
#    message: "[error]"

#filter:
# - match:
#    message: "job"

filter:
 - query:
      query_string:
 #       query: "message: exception AND  message: control"
        query: "Received"

#filter:
#- query:
#   query_string:
#    query: "message: error"

##################################

#alert_subject: "Exception Alert on {0}"
#alert_subject_args:
# - hostname

#alert_text: |-
# Message: {0}
#  Exception Messages.
#  Details of the event:
#          Message: {0}

alert_text_args:
 - message
##################################

alert:

#- "slack"
- "email"

#  Exception Messages.
#  Details of the event:
#          Message: {0}

#alert_text_args:
 #- message

#- slack
slack_webhook_url: "https://hooks.slack.com/services/TE70E2AGM/z2iUkv2n"
slack_username_override: "ElastAlert"
#slack_username_override: "Mohd Rashid"

#- email
email: ["rashidmd777@gmail.com"]
smtp_host: "smtp.gmail.com"
smtp_port: "587"
from_addr: "test@gmail.com"

And Here is the elastalert.yaml inside config folder

cat config/elastalert.yaml

# The elasticsearch hostname for metadata writeback
# Note that every rule can have its own elasticsearch host
#es_host: localhost
es_host: xxxxx
# The elasticsearch port
es_port: 14900

# This is the folder that contains the rule yaml files
# Any .yaml file will be loaded as a rule
smtp_auth_file: /opt/elastalert/smtp_auth_file.yml
rules_folder: rules

# How often ElastAlert will query elasticsearch
# The unit can be anything from weeks to seconds
run_every:
  seconds: 5

# ElastAlert will buffer results from the most recent
# period of time, in case some log sources are not in real time
buffer_time:
  minutes: 1

# Optional URL prefix for elasticsearch
#es_url_prefix: elasticsearch

# Connect with TLS to elasticsearch
#use_ssl: True

# Verify TLS certificates
#verify_certs: True

# GET request with body is the default option for Elasticsearch.
# If it fails for some reason, you can pass 'GET', 'POST' or 'source'.
# See http://elasticsearch-py.readthedocs.io/en/master/connection.html?highlight=send_get_body_as#transport
# for details
#es_send_get_body_as: GET

# Option basic-auth username and password for elasticsearch
es_username: xxxxx
es_password: xxxxx

# The index on es_host which is used for metadata storage
# This can be a unmapped index, but it is recommended that you run
# elastalert-create-index to set a mapping
writeback_index: elastalert_status

# If an alert fails for some reason, ElastAlert will retry
# sending the alert until this time period has elapsed
alert_time_limit:

And Here is inside the elastalert docker container files

/opt/elastalert-server $ cat /opt/elastalert/smtp_auth_file.yml 
smtp_host: smtp.gmail.com
from_addr: rashidmd777@gmail.com
user: rashidmd777@gmail.com
password: xxxxxxx

/opt/elastalert-server $ cat /opt/elastalert-server/config/smtp_auth_file.yml 
smtp_host: smtp.gmail.com
from_addr: xxxxxxx
user: xxxxxxx
password: xxxxxxx

#smtp_host: smtp.gmail.com
#from_addr: xxxxxxx@gmail.com
#user: xxxxxxx@gmail.com
#password: xxxxxxx
/opt/elastalert-server $ 

And Here is the elastalert folder inside all files/folder which im using it CONTRIBUTING.md Dockerfile Dockerfile1 LICENSE.md Makefile README.md config docker-compose.yml elastalert_modules index.js package.json rule_templates rules scripts src

And For above "rules" folder i have given full permission

nsano-rururu commented 3 years ago

look https://github.com/Yelp/elastalert/issues/3178