Splunk Search

Looking for multiple results in query

pshangguan
New Member

I have the following query I use to get the latest status and time(_time).

index=jenkins |spath job_name | search job_name="job/utl-dataflow-check-TST6/" | sort -_time | stats latest(job_result) as status, latest(_time) as tst6t

Now, I want to get the time(_time) of the job that run successfully -> job_result=SUCCESS. I wanyt to seew if I can get those two times from the same query and display them inside the same dashboard panel. I tried different ways and could not get it working.

Thanks!

Tags (1)
0 Karma

Vijeta
Influencer

Try this :-

ME TOO
I have the following query I use to get the latest status and time(_time).

‘index=jenkins |spath job_name | search job_name="job/utl-dataflow-check-TST6/" | sort -_time | stats latest(job_result) as status, latest(eval(job_result=“SUCCESS”)) ,latest(_time) as tst6t`

0 Karma

pshangguan
New Member

I changed it to:

stats latest(job_result) as dev2status, latest(_time=if(eval(job_result=“SUCCESS”))) as dev2st, latest(_time) as dev2t

It did not pickup the _time for the latest successful job run...

0 Karma

Vijeta
Influencer

Can you do this and see if it suffices your requirement-

stats  latest(_time) as tst6t` by job_result
0 Karma

pshangguan
New Member

I used "latest(_time) as dev2st by job_result" in the stats command and the it did not get anything. I am getting "no results found" in the panel.

0 Karma

Vijeta
Influencer

Are you using this query?

    index=jenkins |spath job_name | search job_name="job/utl-dataflow-check-TST6/" | stats latest(_time) as tst6t by job_result
0 Karma

pshangguan
New Member

index=jenkins |spath job_name | search job_name="job/utl-dataflow-check-DEV2/" | sort -_time | stats latest(job_result) as dev2status, latest(_time) as dev2st by job_result, latest(_time) as dev2t

0 Karma

Vijeta
Influencer

Please try with the above query in my comments

0 Karma

pshangguan
New Member

How can I get two time values? one for the latest run, and one for the success run in your query?

0 Karma

Vijeta
Influencer

you will get the latest time for each unique value in job_result. Once you get that you need to sort - dev2t. This will give you the latest job result name and also the row with value SUCCESS will give you latest time for success.

Can you paste your results here with the above query

0 Karma

pshangguan
New Member

I got two results:

job_result . tst6t
FAILURE . 1539707765.083
SUCCESS . 1539704175.318

0 Karma

Vijeta
Influencer

This gives you the latest time of Failure and Success and if you sort - tst6t, it will give you the latest event among the 2 events.
Also you can convert the time in yyyy/mm/dd format using below command at end of yiur query

| eval tst6t = strftime(tst6t,"%Y/%m/%d %H:%M:%S")

0 Karma

pshangguan
New Member

tst6t only have the two times, how do i know which one is for "SUCCESS" and whicch one is for "FAILURE"?

0 Karma

Vijeta
Influencer

You have the job_result column in your output against the time .

0 Karma

pshangguan
New Member

sorry i am not sure how to retrieve them individually as i am new to splunk and xml 🙂

0 Karma

Vijeta
Influencer

I am not sure what your end goal is , the output you have is which gives you latest time of each job_result. Please specify what you need to do with this data

job_result . tst6t
FAILURE . 1539707765.083
SUCCESS . 1539704175.318

0 Karma

pshangguan
New Member

I want to display the last run time in the panel title field, and the last success run time in the single value title field.

0 Karma

pshangguan
New Member

In another word, I want to do something like:

index=jenkins |spath job_name | search job_name="job/utl-dataflow-check-TST6/" | stats latest(_time) as tst6t by job_result | ... tst6t_success_time ... | ... tst6t_failure_time...

tst6t_success_time and tst6t_failure_time are from tst6t. No idea how to pick them up from tst6t...

0 Karma
Get Updates on the Splunk Community!

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...