Knowledge Management

How can we check if tag exists?

danielbb
Motivator

We are trying the following -

index=<index name>
| head 4000 
| eval containstag = if(tag="*", "true", "false") 
| stats 
    count(eval(containstag="true")) as totaltags,
    count(_raw) as totalevents
    by index

Nothing comes back and removing the double quotes - if(tag=*, "true", "false") throws a syntax error.

What can we do?

Labels (1)
Tags (2)
0 Karma

to4kawa
Ultra Champion
index=<index name> | head 4000
 | eval containstag = if(isnull(tag), "false", "true")
 | stats count(eval(containstag="true")) as totaltags, count as totalevents by index

richgalloway
SplunkTrust
SplunkTrust

"*" is not a valid tag name and is not treated as a wildcard by if. Try this query:

... | eval containstag = if(match(tag, ".*"), 1, 0)
| stats sum(containstag) as totaltags, count as totalevents by index
---
If this reply helps you, Karma would be appreciated.

danielbb
Motivator

And -

 index=<index name> | head 4000
| eval containstag = if(tag::eventtype="*", "true", "false")
| stats 
  count(eval(containstag="true")) as totaltags,
  count(_raw) as totalevents
  by index 

Here, we get a syntax error on if(tag::eventtype="*", "true", "false").

0 Karma
Get Updates on the Splunk Community!

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 ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...