Splunk Search

timechart - add some columns and values are 0

TSamon
Engager

Hello, 

Based on this Splunk Query:

 

index=* AND appid=127881 AND message="*|NGINX|*"

AND cluster != null AND namespace != null | eval server = (namespace + "@" + cluster)

| timechart span=1d count by server

Because the logs are only kept for 1 month, and in recent month, logs are only in server 127881-p@23p. So in the splunk query result, we only can see 1 column: 127881-p@23p

 

May I ask how to make the result has 3 columns: 127881-p@23p127881-p@24p, 127881-p@25p

And since there is no logs in 24p and 25p rencently, the values for 24p and 25p are 0.

 

Thanks a lot!

 

Labels (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

By "make the result has 3 columns," do you mean that when logs only come from less than 3 servers, you still want to display the one with no logs (with value 0)?

In that case, you must know the exact name of the three servers.  Then, use foreach to fill the values.

index=* AND appid=127881 AND message="*|NGINX|*"
  AND cluster != null AND namespace != null
| eval server = (namespace + "@" + cluster)
| timechart span=1d count by server
| foreach "127881-p@23p", "127881-p@24p", "127881-p@25p"
    [eval <<FIELD>> = if(isnull('<<FIELD>>'), 0, '<<FIELD>>')]

 

View solution in original post

Tags (1)

yuanliu
SplunkTrust
SplunkTrust

By "make the result has 3 columns," do you mean that when logs only come from less than 3 servers, you still want to display the one with no logs (with value 0)?

In that case, you must know the exact name of the three servers.  Then, use foreach to fill the values.

index=* AND appid=127881 AND message="*|NGINX|*"
  AND cluster != null AND namespace != null
| eval server = (namespace + "@" + cluster)
| timechart span=1d count by server
| foreach "127881-p@23p", "127881-p@24p", "127881-p@25p"
    [eval <<FIELD>> = if(isnull('<<FIELD>>'), 0, '<<FIELD>>')]

 

Tags (1)

TSamon
Engager

Many thanks! Yes, it is what I want, your answer is very helpful! Many thanks!

0 Karma
Get Updates on the Splunk Community!

What the End of Support for Splunk Add-on Builder Means for You

Hello Splunk Community! We want to share an important update regarding the future of the Splunk Add-on Builder ...

Solve, Learn, Repeat: New Puzzle Channel Now Live

Welcome to the Splunk Puzzle PlaygroundIf you are anything like me, you love to solve problems, and what ...

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...