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!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...