Reporting

How to change timestamp to include another field value?

POR160893
Builder

Hi,

I have an index with one field as a timestamp, "SESSION_TIME", and another field, "SEQUENCE". The "SEQUENCE" field is unique for each event and i am tasked to replace the seconds part of each timestamp with the respective "SEQUENCE" number.

This is what I currently wrote but I clearly wrote it incorrect:
eval xxx = strftime(SESSION_TIMESTAMP,"%S" = "SEQUENCE")

Can you please help?


Thanks,
Patrick

Labels (1)
0 Karma

POR160893
Builder

The SESSION_timestamp is a String value like this 2022-04-20 12:23:43.
The SEQUENCE is an integer value like 101.
I need to replace the second part of each timestamp with the respective SEQUENCE value.
So, in this example, the value I would want is 2022-04-20 12:23:101.

Can you please help?

(I gave you Karma btw 😀)

0 Karma

sperkins
Path Finder

Convert the time to epoch, reformat it without the seconds, and then concatenate with strcat::
| eval time_epoch = strptime('SESSION_timestamp', "%Y-%m-%d %H:%M:%S")
| convert ctime(time_epoch) as hour_minute timeformat="%Y-%m-%d %H:%M"
| strcat hour_minute ":" SEQUENCE combo_time

 

combo_time= 2022-04-20 12:23:101

POR160893
Builder

When I run this query, it does not show the date before the SEQUENCE number ....

POR160893_0-1650481252477.png

 

0 Karma

sperkins
Path Finder

Does the strptime format match the time format of the SESSION_timestamp in your data?

 

POR160893
Builder

No worries, this worked when I capitalised the field nameL

POR160893_0-1650481998356.png

 

sperkins
Path Finder

Fantastic!! 

POR160893
Builder

SESSION_TIMESTAMP="2022-04-20 14:03:41" is the format

sperkins
Path Finder

Ahhh change the eval to capitalize the field name
| eval time_epoch = strptime(SESSION_TIMESTAMP, "%Y-%m-%d %H:%M:%S")

isoutamo
SplunkTrust
SplunkTrust

Hi

what is your actual issue which you are trying to solve? I suppose that you will get more issues with this e.g. when value of SEQUENCE is outside of 0 to 59?

Is your SESSION_TIME in epoc or human readable mode and if later what is the format?

r. Ismo

POR160893
Builder

The SESSION_timestamp is a String value like this 2022-04-20 12:23:43.
The SEQUENCE is an integer value like 101.
I need to replace the second part of each timestamp with the respective SEQUENCE value.
So, in this example, the value I would want is 2022-04-20 12:23:101.

Can you please help?

(I gave you Karma btw 

POR160893_0-1650477084063.png

 

)

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...