Splunk Search

MAP command query

mprreddy51
Explorer

Hi,

why I am not able to extract date from _raw in MAP command(second part of query)

Below is my query:

index=abc sourcetype=pqr SERVICE_NAME=def |  rex "(?<precise_time>\d{8}T\d{6}\.\d{3})" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%f") |  transaction SERVICE_NAME startswith="WWW_REQ" endswith="WWW_RES" | sort _time |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |table ACCNO|map search="search index=abc sourcetype=pqr ACCNO=$ACCNO$ | rex "(?<precise_time>\d{8}T\d{6}\.\d{3})" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%f") |  transaction SERVICE_NAME startswith="AAA_REQ" endswith="AAA_RES" | sort _time |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |table ACCNO,SERVICE_NAME,duration"

If i remove rex part and duration in second query I am getting some results.But ultimately I need duration in my requirement. How to achieve this.

Thanks in advance.

-PR

0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try.

index=abc sourcetype=pqr SERVICE_NAME=def |  transaction SERVICE_NAME startswith="WWW_REQ" endswith="WWW_RES" | sort _time |table ACCNO|map search="search index=abc sourcetype=pqr ACCNO=$ACCNO$ | rex "(?<precise_time>\d{8}T\d{6}\.\d{3})\" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%N") |  transaction SERVICE_NAME startswith="AAA_REQ" endswith="AAA_RES" | sort _time |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |table ACCNO,SERVICE_NAME,duration"

Updated Answer
Map is expensive and has limitation. Give this one a try. Also adding the >30 sec constraints that you mentioned (missing in question)

index=abc sourcetype=pqr [search index=abc sourcetype=pqr SERVICE_NAME=def |  rex "(?<precise_time>\d{8}T\d{6}\.\d{3})" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%f") |  transaction SERVICE_NAME startswith="WWW_REQ" endswith="WWW_RES"  |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |search duration>30|table ACCNO] |  rex "(?<precise_time>\d{8}T\d{6}\.\d{3})" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%f") |  transaction SERVICE_NAME startswith="AAA_REQ" endswith="AAA_RES" | sort _time |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |table ACCNO,SERVICE_NAME,duration"

View solution in original post

0 Karma

somesoni2
Revered Legend

Give this a try.

index=abc sourcetype=pqr SERVICE_NAME=def |  transaction SERVICE_NAME startswith="WWW_REQ" endswith="WWW_RES" | sort _time |table ACCNO|map search="search index=abc sourcetype=pqr ACCNO=$ACCNO$ | rex "(?<precise_time>\d{8}T\d{6}\.\d{3})\" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%N") |  transaction SERVICE_NAME startswith="AAA_REQ" endswith="AAA_RES" | sort _time |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |table ACCNO,SERVICE_NAME,duration"

Updated Answer
Map is expensive and has limitation. Give this one a try. Also adding the >30 sec constraints that you mentioned (missing in question)

index=abc sourcetype=pqr [search index=abc sourcetype=pqr SERVICE_NAME=def |  rex "(?<precise_time>\d{8}T\d{6}\.\d{3})" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%f") |  transaction SERVICE_NAME startswith="WWW_REQ" endswith="WWW_RES"  |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |search duration>30|table ACCNO] |  rex "(?<precise_time>\d{8}T\d{6}\.\d{3})" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%f") |  transaction SERVICE_NAME startswith="AAA_REQ" endswith="AAA_RES" | sort _time |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |table ACCNO,SERVICE_NAME,duration"
0 Karma

mprreddy51
Explorer

@Somesh,

In the first part of the search, we are taking "duration">30sec

index=abc sourcetype=pqr SERVICE_NAME=def |  rex "(?\d{8}T\d{6}\.\d{3})" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%f") |  transaction SERVICE_NAME startswith="WWW_REQ" endswith="WWW_RES" | sort _time |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |table ACCNO,duration|search duration>30|table ACCNO

ACCNO     DURATION
1         31.22
2         34.89          (I am passing only ACCNO)
3         78.98

This part of the search states that:

index=abc sourcetype=pqr ACCNO=$ACCNO$ | rex "(?\d{8}T\d{6}\.\d{3})" | eval precise_epoch=strptime(precise_time, "%Y%m%dT%H%M%S.%f") |  transaction SERVICE_NAME startswith="AAA_REQ" endswith="AAA_RES" | sort _time |  eval duration = tonumber(mvindex(precise_epoch, -1)) - tonumber(mvindex(precise_epoch, 0)) |table ACCNO,SERVICE_NAME,duration"

ACCNO   SERVICE_NAME     duration
1       a                0.89
        b                1.09
        c                2.45

2       e                4.67
        f                0.11

This the output I am expecting.

First I need to check in SERVICE_NAME=def with WWW_req and WWW_res Account nos >30 sec
second if any account number is greater than 30 then I need to find for each accountnumber what are the services and time duration. I did it manually by copying one accno at a time,But there are 100's of accnos .By using MAP i am trying.
Thanks

0 Karma

somesoni2
Revered Legend

Try the updated answer.

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!

Quantify Your Splunk Investment Impact: Introducing Savings Metrics to Value Insights

Building on the foundation established in our initial Value Insights releases, we are introducing the Savings ...

Event Series: Telemetry Pipeline Management

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...