Alerting

Alert on Count and print a table

varunghai
Engager

Hi,

I want to create an alert where, I want to raise an alert if the count of total number of errors is greater than 10, then i want to print a table with error count on each host.

Query -
index=weblogs host="nlhypsewb*.*" sourcetype=web "The timeout specified has expired" earliest=-15m
| stats count(host) as COUNT
| where COUNT > 4

This query gives me correct results but it only gives me a column with total count
But when this query is giving some results then i want to generate an email which shows the count of errors on each host. How do I add those details in this query without using a Case if possible? I want to know if there is another option apart from using a switch Case.

Tags (1)
0 Karma
1 Solution

mayurr98
Super Champion

hey you can try something like this
If you want to see error count on each host then you should write

index=weblogs host="nlhypsewb*.*" sourcetype=web "The timeout specified has expired" earliest=-15m 
| stats count(host) as COUNT by host 
| eventstats sum(COUNT) as total_count | where total_count>10 | fields - total_count

let me know if this helps!

View solution in original post

0 Karma

mayurr98
Super Champion

hey you can try something like this
If you want to see error count on each host then you should write

index=weblogs host="nlhypsewb*.*" sourcetype=web "The timeout specified has expired" earliest=-15m 
| stats count(host) as COUNT by host 
| eventstats sum(COUNT) as total_count | where total_count>10 | fields - total_count

let me know if this helps!

0 Karma

varunghai
Engager

Hi Mayur, thanks for your answer, but using this query the fnal output table will be based on count per host so if for eg- host1 has count 11 and host2 has count 2 it will show only the host with count 11, which may lead to misinterpretation of the alert as the alert condition is when total number of errors overall on all the hosts is greater than 10.

0 Karma

mayurr98
Super Champion

Hey yeah i got it. I have changed my query pls check and let me know.. i have set the threshold on the total number of count !

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...