All Apps and Add-ons

Compare time fields from different sourcetypes

junchao
New Member

Hi,

I have two searches that output different things.

Search.1 is a DB query that returns the latest DB record modify time - the timefield in concern is the LATESTMODTS_Epoch.

| dbxquery shortnames=1 connection=Oracle-DB query="SELECT MAX(modify_ts) as LATESTMODTS FROM Database1" | eval LATESTMODTS_Epoch = strptime(LATESTMODTS, "%Y-%m-%d %H:%M:%S") | fields LATESTMODTS_Epoch

Search.2 is a normal search that returns a timefield from another sourcetype - the fimefield in concern is FailureTime_Epoch.

index=xxx sourcetype=abc | eval FailureTime_Epoch = strptime(FailureTime, "%Y-%m-%d %H:%M:%S") | stats count by users, FailureTime_Epoch

Now i have LATESTMODTS_Epoch from Search.1 and FailureTime_Epoch from Search.2, both in epoch time format which i want to compare these two time and produce another search with results, something like below.

index=xxx sourcetype=abc | stats count by users | where FailureTime_Epoch > LATESTMODTS_Epoch

My question is how would i correlate the two fields though to compare their value?

Search.1 and Search.2 are both indenpendent searches with no common shared fields or values.

I'd really appreacite if anyone would kindly give me a hint or advice.

Thanks very much.

0 Karma
1 Solution

arjunpkishore5
Motivator

Here is how you can do this. Since you don't have a common field between the 2 datasets, you need to create a common field to join them. I've done this by adding eval joiner=1 to both queries

index=xxx sourcetype=abc 
| eval FailureTime_Epoch = strptime(FailureTime, "%Y-%m-%d %H:%M:%S") 
| stats count by users, FailureTime_Epoch 
| eval joiner=1 
| join joiner 
    [| dbxquery shortnames=1 connection=Oracle-DB query="SELECT MAX(modify_ts) as LATESTMODTS FROM Database1" 
    | eval LATESTMODTS_Epoch = strptime(LATESTMODTS, "%Y-%m-%d %H:%M:%S") 
    | eval joiner=1 
    | fields joiner, LATESTMODTS_Epoch] 
| where FailureTime_Epoch > LATESTMODTS_Epoch

Please mark as answer if this works for you.

Cheers

View solution in original post

0 Karma

arjunpkishore5
Motivator

Here is how you can do this. Since you don't have a common field between the 2 datasets, you need to create a common field to join them. I've done this by adding eval joiner=1 to both queries

index=xxx sourcetype=abc 
| eval FailureTime_Epoch = strptime(FailureTime, "%Y-%m-%d %H:%M:%S") 
| stats count by users, FailureTime_Epoch 
| eval joiner=1 
| join joiner 
    [| dbxquery shortnames=1 connection=Oracle-DB query="SELECT MAX(modify_ts) as LATESTMODTS FROM Database1" 
    | eval LATESTMODTS_Epoch = strptime(LATESTMODTS, "%Y-%m-%d %H:%M:%S") 
    | eval joiner=1 
    | fields joiner, LATESTMODTS_Epoch] 
| where FailureTime_Epoch > LATESTMODTS_Epoch

Please mark as answer if this works for you.

Cheers

0 Karma

junchao
New Member

Thanks very much arjunpkishore5. This has worked well, just as needed! Good to know this usage.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

One cannot correlate events that have nothing in common.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

 Ready to master Kubernetes and cloud monitoring like the pros? Join Splunk’s Growth Engineering team for an ...

Update Your SOAR Apps for Python 3.13: What Community Developers Need to Know

To Community SOAR App Developers - we're reaching out with an important update regarding Python 3.9's ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...