Alerting

help on alert message

jip31
Motivator

hello

 

I use the search below in order to generate an alert if disk size is > 20

search = `diskspace` \
| fields host FreeSpaceKB \
| eval host=upper(host) \
| eval time = strftime(_time, "%m/%d/%Y %H:%M") \
| eval FreeSpace = FreeSpaceKB/1024 \
| eval FreeSpace = round(FreeSpace/1024,1) \
| stats latest(time) as time latest(FreeSpace) as FreeSpace by host \
| where FreeSpace >= 20 \
| table host

 

In the alert message I need to display the host concerned by the alert

So I put : The $host$ encounter a disk size issue but the host is not displayed

Same thing in the object of the alert : Splunk Disk size alert for the $host$

What is the problem please??

0 Karma
1 Solution

rnowitzki
Builder

Ok, you could create a mv field from the resulting hosts. This should give you the possibility to add multiple hosts in one email.

Aadd this as last line to your SPL:

| stats values(host) as hosts


All hosts can be referenced as $result.hosts$ in the email. 

Hope it helps.

BR
Ralph
--
Karma and/or Solution tagging appreciated.



--
Karma and/or Solution tagging appreciated.

View solution in original post

0 Karma

rnowitzki
Builder

Hi @jip31,

You have to use $result.field$ to reference fields from the search results.
So, $result.host$ should work for you.

BR
Ralph
--
Karma and/or Solution tagging appreciated.

--
Karma and/or Solution tagging appreciated.
0 Karma

jip31
Motivator

Hi and thanks. I am going to test it

Last question : if I have many host results, all the host will be displayed?

0 Karma

rnowitzki
Builder

Nope, just the first result.

"First value for the specified field name from the first search result row."
https://docs.splunk.com/Documentation/Splunk/latest/Alert/EmailNotificationTokens#Result_tokens

BR
Ralph

--
Karma and/or Solution tagging appreciated.
0 Karma

jip31
Motivator

Thanks ralph 

But its a problem for me because I need to créate incident automatically in SNOW from this alert

So it means that i have to run this alert very often (actually one time per day) if i want to créate incident for each host when an event corresponding to the search occurs. BR

 

0 Karma

rnowitzki
Builder

Ok, you could create a mv field from the resulting hosts. This should give you the possibility to add multiple hosts in one email.

Aadd this as last line to your SPL:

| stats values(host) as hosts


All hosts can be referenced as $result.hosts$ in the email. 

Hope it helps.

BR
Ralph
--
Karma and/or Solution tagging appreciated.



--
Karma and/or Solution tagging appreciated.
0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...