How to Create Alerts in the ELK Stack Using ElastAlert

The ELK Stack (Elasticsearch, Logstash, and Kibana) is a powerful suite for log aggregation and analysis—but by default, it lacks robust alerting features. That’s where ElastAlert comes in. Developed by Yelp, ElastAlert is a simple yet flexible tool to trigger alerts from Elasticsearch query results.

In this tutorial, we’ll walk through how to install ElastAlert and configure a basic alerting rule, helping you monitor your log data in near real-time.


🌐 Why Use ElastAlert with the ELK Stack?

While Kibana now offers basic alerting in newer versions via Kibana Alerting and Watcher, many users still rely on ElastAlert for its:

  • Lightweight setup
  • Highly customizable rules
  • Support for email, Slack, webhook, and other outputs
  • Ease of integration with Elasticsearch

⚙️ Prerequisites

Before starting, make sure you have the following:

  • A working ELK Stack (Elasticsearch v7.x or earlier is best)
  • Python 3.6+
  • pip installed
  • Access to the machine where Elasticsearch is running

🚀 Installing ElastAlert

Clone the Repository

$ git clone https://github.com/Yelp/elastalert.git
$ cd elastalert

Install Dependencies:

$ pip install -r requirements.txt

✅ Set up ElastAlert Index:

This index will store alert metadata in Elasticsearch.

$ python elastalert/elastalert.py --config config.yaml --verbose --start NOW

🛠️ Configuring ElastAlert

📁 Step 1: Configure config.yaml

es_host: localhost
es_port: 9200
writeback_index: elastalert_status
buffer_time:
  minutes: 15
run_every:
  minutes: 1

Tip: Adjust the buffer and run interval based on how frequently your logs are updated.


📄 Step 2: Create a Rule File

Save the following as rules/error_alert.yaml:

name: Error Alert
type: frequency
index: logstash-*
num_events: 3
timeframe:
  minutes: 5
filter:
- term:
    log.level: "error"
alert:
- "email"
email:
- "alerts@yourdomain.com"

This rule will send an email if three or more error-level logs appear in a 5-minute window.

📬 Alert Output Options

ElastAlert supports multiple alerting methods, including:

  • 📧 Email
  • 🧵 Slack
  • 🌐 Webhooks
  • 📞 PagerDuty
  • 📲 OpsGenie

Configuration for each can be added directly into the rule file.

✅ Running ElastAlert

Once configured, run ElastAlert using:

python -m elastalert.elastalert --config config.yaml

To run it as a background service, consider using supervisord, systemd, or Docker.

🧠 Pro Tips for Better Alerts

  • Use wildcard or regex filters to catch variable patterns.
  • Combine ElastAlert with Kibana dashboards to visualize the context behind alerts.
  • Set up rate-limiting to prevent alert fatigue.

🔍 Final Thoughts

Using ElastAlert with the ELK Stack provides a lightweight, customizable solution for proactive log monitoring. Whether you're tracking error spikes, failed login attempts, or traffic anomalies, ElastAlert can help you act before problems escalate.