Splunk Search

eval / rex a field and change its output

spluzer
Communicator

hello all,

I have a lookup with two fields sourcetype and interval ( like below) ..some of the intervals are in seconds (which is great) - However some are in cron like (14 01 * * *) --I need to change the ones in cron to 86400 ...Any ideas

sourcetype          interval


blah                  300

blah2               15 01 * * * *

blah3               3600

blah4                18 02 * * *

Here is my comically bad regex I've been working with, but cant seem to make it work

| rest splunk_server=local /services/data/inputs/script
| search (disabled = 0 AND interval=*)
| dedup sourcetype
| eval output=if(match(interval="(\d+)(\d+).(\d).(*).(*).(*)")),"86400","interval")

| table sourcetype interval output

Thanks!

Tags (3)
0 Karma
1 Solution

to4kawa
Ultra Champion
| rest splunk_server=local /services/data/inputs/script
| search (disabled = 0 AND interval=*)
| eval output=if(match(interval,"^-?\d+$"),"interval","86400")
| stats values(interval) as interval values(output) as output by sourcetype

Hi, @spluzer
How about this?

View solution in original post

to4kawa
Ultra Champion
| rest splunk_server=local /services/data/inputs/script
| search (disabled = 0 AND interval=*)
| eval output=if(match(interval,"^-?\d+$"),"interval","86400")
| stats values(interval) as interval values(output) as output by sourcetype

Hi, @spluzer
How about this?

spluzer
Communicator

Awesome thanks!..You answered my question perfectly, and will accept accordingly. However, I now realize that it probably makes more sense for me to "replace" the intervals with a cron schedule with 86400 rather than create a new field called output ( for the sake of writing it to a lookup)...Do you have a way to do that...I can ask it in other question form if you prefer...Thanks again!

0 Karma

vnravikumar
Champion

Hi

Check this

| rest splunk_server=local /services/data/inputs/script 
| search (disabled = 0 AND interval=*) 
| eval interval=if(match(interval,"^-?\d+$"),'interval',"86400") 
| stats values(interval) as interval by sourcetype
0 Karma

spluzer
Communicator

Yep, that does it. I'm an idiot ..lol...Thanks!

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...