How do you make a rule that sends an alert when there is, for example, only 80% disk space left? Low disk space rule
Assuming it's a numeric field called disk_used:
name: something
type: any
index: something
filter:
- range:
disk_used:
gt: .8
alert:
- something
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.
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: hostThe 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: hostIt'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?
You always need to specify an index. Everything in Elasticsearch has an index.
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 is it working example?
@mayank023 - yes, that is a working example, if you fill in the variables:
- $es_host
- $es_index
- $es_region
- $ea_hostname
- $slack_channel_url
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.
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
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
Thank you @Qmando and @itsecureadmin, After adding realert the things are perfect. Cheers!