Splunk Search

How to extract fields at search-time and display values in one row without modifying props.conf?

chrismok
Path Finder

As this sourcetype is used for other searches, the props.conf cannot be modified for adding the line merger, how to I do to get the result in one row

Log

Deploy.name=ABC
Deploy.startime=20140101000000
Deploy.environment=QA3
Deploy.joblist=A,B,C,D,E,F
Deploy.jobselected=B,C,E,F
Deploy.job.A.start=true
Deploy.job.E.start=true
Deploy.job.B.start=true
Deploy.job.A.status=Completed
Deploy.job.C.start=true
Deploy.job.B.status=Failed
Deploy.job.A.start=true
Deploy.job.E.start=true
Deploy.job.B.start=true
Deploy.job.A.status=Completed
Deploy.job.C.start=true
Deploy.job.B.status=Failed
Deploy.job.A.start=true
Deploy.job.E.start=true
Deploy.job.B.start=true;
Deploy.job.A.status=Completed
Deploy.job.C.start=true
Deploy.job.B.status=Failed

Expected Result

Name          |   Startime            |         Environment      |          JobList             |      Jobselected
======================================================================================================================
ABC              2014-01-01 00:00                    QA3                   A,B,C,D,E,F                    B,C,E,F

Search query

 | stats count | eval data = 
       "Deploy.name=ABC;
        Deploy.startime=20140101000000;
        Deploy.environment=QA3;
        Deploy.joblist=A,B,C,D,E,F;
        Deploy.jobselected=B,C,E,F;
        Deploy.job.A.start=true;
        Deploy.job.E.start=true;
        Deploy.job.B.start=true;
        Deploy.job.A.status=Completed;
        Deploy.job.C.start=true;           Deploy.job.B.status=Failed;Deploy.job.A.start=true;Deploy.job.E.start=true;Deploy.job.B.start=true;Deploy.job.A.status=Completed;Deploy.job.C.start=true;Deploy.job.B.status=Failed"
   | makemv data delim=";" | mvexpand
   data | streamstats count | eval
   _time = now() + count | rename data as _raw | table _time _raw
1 Solution

somesoni2
Revered Legend

Gve this a try

sourcetype=test3  ("Deploy.name" OR "Deploy.startime" OR "Deploy.environment" OR "Deploy.joblist" OR "Deploy.jobselected")  | rex "Deploy.name=(?<Name>\S+)"
| rex "Deploy.startime=(?<Startime>\S+)"
| rex "Deploy.environment=(?<Environment>\S+)"
| rex "Deploy.joblist=(?<JobList>\S+)"
| rex "Deploy.jobselected=(?<Jobselected>\S+)"
| eval Startime=strftime(strptime(Startime,"%Y%m%d%H%M%S"),"%Y-%m-%d %H:%M")
| table Name Startime Environment JobList Jobselected | eval id=if(isnotnull(Name),1,0) | accum id | stats list(*) as * by id

View solution in original post

somesoni2
Revered Legend

Gve this a try

sourcetype=test3  ("Deploy.name" OR "Deploy.startime" OR "Deploy.environment" OR "Deploy.joblist" OR "Deploy.jobselected")  | rex "Deploy.name=(?<Name>\S+)"
| rex "Deploy.startime=(?<Startime>\S+)"
| rex "Deploy.environment=(?<Environment>\S+)"
| rex "Deploy.joblist=(?<JobList>\S+)"
| rex "Deploy.jobselected=(?<Jobselected>\S+)"
| eval Startime=strftime(strptime(Startime,"%Y%m%d%H%M%S"),"%Y-%m-%d %H:%M")
| table Name Startime Environment JobList Jobselected | eval id=if(isnotnull(Name),1,0) | accum id | stats list(*) as * by id

somesoni2
Revered Legend

Just add a sort on _time command before accum.

chrismok
Path Finder

Nearly finish~~ But the name field fall to row 2 now.
alt text

0 Karma

lguinn2
Legend

Try this then:

sourcetype=whateverItIs ("Deploy.name" OR "Deploy.startime" OR "Deploy.environment" OR "Deploy.joblist" OR "Deploy.jobselected")
| sort _time
| transaction startswith="Deploy.name=" endswith="Deploy.jobselected="
| rex "Deploy.name=(?<Name>\S+)"
| rex "Deploy.startime=(?<Startime>\S+)"
| rex "Deploy.environment=(?<Environment>\S+)"
| rex "Deploy.joblist=(?<JobList>\S+)"
| rex "Deploy.jobselected=(?<Jobselected>\S+)"
| eval Startime=strftime(strptime(Startime,"%Y%m%d%H%M%S"),"%Y-%m-%d %H:%M)
| table Name Startime Environment JobList Jobselected
0 Karma

chrismok
Path Finder

Sorry bother you again.

You can see that the splunk will descend the log seq as log don't provide the timestamp.
alt text

As a result, there's an error doing "transcation" command.

alt text

There may has another method to sort the log in ascending, but the other problem is the "Deploy.selected" may not append to log due to system in progress or system crashed.

To specific the wording in endswith is not prefect for all the cases.

No luck once delete the transaction command
alt text

0 Karma

lguinn2
Legend

This should do

sourcetype=whateverItIs
| rex "Deploy.name=(?<Name>\S+?);.*Deploy.startime=(?<Startime>\S+?);.*Deploy.environment=(?<Environment>\S+?);Deploy.joblist=(?<JobList>\S+?);.*Deploy.jobselected=(?<Jobselected>\S+?);"
| eval Startime=strftime(strptime(Startime,"%Y%m%d%H%M%S"),"%Y-%m-%d %H:%M)
| table Name Startime Environment JobList Jobselected
0 Karma

chrismok
Path Finder

Hi Iguinn,

Not work, also the log do not included a sybmol ";"

And please note each line is a single event

0 Karma

lguinn2
Legend

Well, you are showing a ";" in all your examples!!

0 Karma

sk314
Builder

what is the output that you get with your current search query?

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...