Splunk Search

Convert data to hex with tostring inside chart

Voriaz
Engager

Hi,

Can we manipulate data with functions in a chart.
I have a chart table obtained with :

| chart count over user by date_wday

 

The result is the following :

usermondaythuesday
user13652
user228192
user3235492

 

Now  imagine that I want to convert the count field in hexadecimal with "tostring(count,"hex")".
How can I do ?

I already managed to do it with "foreach" statement but after that, I cannot use the Trellis view cause the chart command is not at the end of the search.

Thanks for yout help.

 

A.

Labels (2)
0 Karma
1 Solution

to4kawa
Ultra Champion

 

| makeresults
| eval _raw="user	monday	thuesday
user1	36	52
user2	28	192
user3	235	492"
| multikv forceheader=1
| table user	monday	thuesday
| untable user date_wday count
| eval count=mvrange(0,count)
| mvexpand count
| rename COMMENT as "this is your original sample. first, try chart. from here, the logic"
| stats count by user date_wday
| eval count = tostring(count,"hex")
| xyseries user date_wday count

 

try stats() ,eval and xyseries

| makeresults
| eval _raw="user	monday	thuesday
user1	36	52
user2	28	192
user3	235	492"
| multikv forceheader=1
| table user	monday	thuesday
| untable user date_wday count
| eval count=mvrange(0,count)
| mvexpand count
| rename COMMENT as "this is your original sample. from here, the logic"
| chart count over user by date_wday
| rename user as _user
| foreach * [ eval <<FIELD>> = tostring(<<FIELD>>,"hex")]
| rename _user as user

this is chart and foreach version.

 

View solution in original post

to4kawa
Ultra Champion

 

| makeresults
| eval _raw="user	monday	thuesday
user1	36	52
user2	28	192
user3	235	492"
| multikv forceheader=1
| table user	monday	thuesday
| untable user date_wday count
| eval count=mvrange(0,count)
| mvexpand count
| rename COMMENT as "this is your original sample. first, try chart. from here, the logic"
| stats count by user date_wday
| eval count = tostring(count,"hex")
| xyseries user date_wday count

 

try stats() ,eval and xyseries

| makeresults
| eval _raw="user	monday	thuesday
user1	36	52
user2	28	192
user3	235	492"
| multikv forceheader=1
| table user	monday	thuesday
| untable user date_wday count
| eval count=mvrange(0,count)
| mvexpand count
| rename COMMENT as "this is your original sample. from here, the logic"
| chart count over user by date_wday
| rename user as _user
| foreach * [ eval <<FIELD>> = tostring(<<FIELD>>,"hex")]
| rename _user as user

this is chart and foreach version.

 

Voriaz
Engager

Hello,

The first solution (with stats, eval and xyseries)  is working perfectly and is simpler.
I was not aware of the xyseries function.

For the second one, it is almost working as only the field "user" is available to trellis "splitBy" option ans this is not what I want.

But the first one is working, so thank you very much @to4kawa !

A.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

When I use foreach to convert the counts to hex the graph still displays the values in decimal.  And, yes, trellis format doesn't display correctly as I only see one day for each user.

---
If this reply helps you, Karma would be appreciated.
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!

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...

Best Practices: Splunk auto adjust pipeline queue

When you enable autoAdjustQueue in Splunk, maxSize should be understood as the queue size Splunk starts with ...