elastalert icon indicating copy to clipboard operation
elastalert copied to clipboard

How do you make a rule that sends an alert when there is, for example, only 80% disk space left? Low disk space rule

Open rokstar1254 opened this issue 8 years ago • 11 comments

rokstar1254 avatar Jul 16 '18 20:07 rokstar1254

Assuming it's a numeric field called disk_used:

name: something
type: any
index: something
filter:
 - range:
      disk_used:
        gt: .8
alert:
 - something

Qmando avatar Jul 17 '18 22:07 Qmando

I have two rules defined for disk space (and two for inode usage). Warning on 75-84% and critical on 85%+ - this is the warning rule:

filter:
-query
  - query_string:
      query: "type:metricsets AND system.filesystem.used.pct:[0.75 TO 0.84]"

query_delay:
  minutes: 1
query_key: host

The critical rule is:

filter:
-query
  - query_string:
      query: "type:metricsets AND system.filesystem.used.pct:[0.85 TO 1.0]"

query_delay:
  minutes: 1
query_key: host

It's important to use query_key so that each host can be alerted on.

I use query_delay since indexing is delayed on ElasticSearch.

itsecureadmin avatar Aug 01 '18 17:08 itsecureadmin

I have two rules defined for disk space (and two for inode usage). Warning on 75-84% and critical on 85%+ - this is the warning rule:

filter:
-query
  - query_string:
      query: "type:metricsets AND system.filesystem.used.pct:[0.75 TO 0.84]"

query_delay:
  minutes: 1
query_key: host

The critical rule is:

filter:
-query
  - query_string:
      query: "type:metricsets AND system.filesystem.used.pct:[0.85 TO 1.0]"

query_delay:
  minutes: 1
query_key: host

It's important to use query_key so that each host can be alerted on.

I use query_delay since indexing is delayed on ElasticSearch.

do we need to specify index: something? or query: "type:metricsets AND system.filesystem.used.pct:[0.85 TO 1.0]" is enough?

pingwang avatar Dec 22 '18 07:12 pingwang

You always need to specify an index. Everything in Elasticsearch has an index.

Qmando avatar Jan 03 '19 23:01 Qmando

Yes, a more complete example might be the following, which also includes the index, alert information, and a higher threshold for larger disks:

es_host: $es_host

es_port: 80
aws_region: $es_region

name: "$ea_hostname:  CRITICAL : Disk Usage Alert"
index: $es_index

type: any 

realert:
  minutes: 15

filter:
- query:
  - query_string:
      query: "type:metricsets"
- query:
  - query_string:
      query: "(system.filesystem.used.pct:[0.85 TO 1.0] AND system.filesystem.total: <2000000000001) OR (system.filesystem.used.pct:[0.95 TO 1.0] AND system.filesystem.total: >2000000000000)"

query_delay:
  minutes: 1
query_key: host

alert_text_type: alert_text_only
include : ["host","system.filesystem.used.pct","system.filesystem.mount_point"]

alert:
- "slack"
alert_text: "
*Used %*        : {0}\n
*Mount Point*   : {2}\n
*Host*          : {1}\n
*ElastAlert Node*  : $ea_hostname"

alert_text_args: ["system.filesystem.used.pct","host","system.filesystem.mount_point"]

slack_webhook_url: $slack_channel_url
slack_emoji_override: ":heavy_exclamation_mark:"

itsecureadmin avatar Jan 04 '19 16:01 itsecureadmin

@itsecureadmin is it working example?

mayank023 avatar Sep 20 '19 12:09 mayank023

@mayank023 - yes, that is a working example, if you fill in the variables:

  • $es_host
  • $es_index
  • $es_region
  • $ea_hostname
  • $slack_channel_url

itsecureadmin avatar Sep 20 '19 16:09 itsecureadmin

Assuming it's a numeric field called disk_used:

name: something
type: any
index: something
filter:
 - range:
      disk_used:
        gt: .8
alert:
 - something

Hello @Qmando , I am using the above as a rule for alerting, but the problem that I am facing is that I am receiving alarms for one and the same state every minute, although the value of the usage has no change.

For the test I am using: filter:

  • range: system.filesystem.used.pct: gt: 0.1 And in mine case, I am receiving emails with value 0.172

I guess this should be in "already seen" section as per my understanding. Can you help me to fix this issue?

Thanks.

tilchev avatar Apr 02 '20 16:04 tilchev

I am using the above as a rule for alerting, but the problem that I am facing is that I am receiving alarms for one and the same state every minute, although the value of the usage has no change.

... I guess this should be in "already seen" section as per my understanding.

What is the value of realert? The default of 1 minute would cause this rule to alert each minute until the alert condition was resolved.

https://elastalert.readthedocs.io/en/latest/ruletypes.html

itsecureadmin avatar Apr 02 '20 18:04 itsecureadmin

Pretty much your only option is realert

For example:

realert:
  hours: 8

If you want that realert to only apply to a single host, you could add

query_key:
 - hostname

Such that you only get a maximum of one alert per host per 8 hours

Qmando avatar Apr 02 '20 23:04 Qmando

Thank you @Qmando and @itsecureadmin, After adding realert the things are perfect. Cheers!

tilchev avatar Apr 03 '20 08:04 tilchev