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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Where Innovation Takes Flight: The Splunk4Aviation Flight Sim Lands at .conf26

If you hear someone at .conf26 shouting "gear down, GEAR DOWN" across the show floor, you have found us.  The ...

Turn Cisco Telemetry Into Action with Cisco Data Fabric, powered by the Splunk ...

The surge in machine data is already hitting enterprise budgets, and the agentic era will only intensify it. ...

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...