Splunk Dev

How to do time-based lookup using python?

Jeremiah
Motivator

Anyone out there doing time-based lookups with an external python script? How do you handle the time portion of the lookup configuration? Same as you would for a CSV lookup?

1 Solution

araitz
Splunk Employee
Splunk Employee

Per Steve Zhang, the Director of Search, there are two ways to do a time-based external lookup.

  • Have Splunk’s lookup mechanism handle the temporal aspect

    • In this case, the external lookup returns all relevant matches over all-time, and Splunk will constrain matches based on the time_field, time_format, etc specified in transforms.conf. This is analogous to how time-based CSV-based lookups work in Splunk.

    • The time-based configuration would perform the comparison on the time values and return the relevant results to search based on the lookup configuration.

  • Let the external script handle the temporal aspect implicitly by adding _time as a field to match on

    • In this case, the external script will need to know that the value of _time is not an exact match against the “time” column above, but rather “closest but no later than”


Which approach to implement depends on how often the matching field changes – in other words, over all time, how many different rows are there that contain a given value to be matched upon?

If the number of rows/changes is small, then either option above should be fine. It the number is large, then letting the script handle time matching is likely better.

In either case, it would be wise to implement caching to reduce calls to the DB.

View solution in original post

araitz
Splunk Employee
Splunk Employee

Per Steve Zhang, the Director of Search, there are two ways to do a time-based external lookup.

  • Have Splunk’s lookup mechanism handle the temporal aspect

    • In this case, the external lookup returns all relevant matches over all-time, and Splunk will constrain matches based on the time_field, time_format, etc specified in transforms.conf. This is analogous to how time-based CSV-based lookups work in Splunk.

    • The time-based configuration would perform the comparison on the time values and return the relevant results to search based on the lookup configuration.

  • Let the external script handle the temporal aspect implicitly by adding _time as a field to match on

    • In this case, the external script will need to know that the value of _time is not an exact match against the “time” column above, but rather “closest but no later than”


Which approach to implement depends on how often the matching field changes – in other words, over all time, how many different rows are there that contain a given value to be matched upon?

If the number of rows/changes is small, then either option above should be fine. It the number is large, then letting the script handle time matching is likely better.

In either case, it would be wise to implement caching to reduce calls to the DB.

Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...