Splunk Search

timefield in lookup

krugger
Communicator

I have created a lookup to represent the holidays of a year, however I can't match the date to the _time. I have defined that the field holiday in the lookup holiday is a timefield.

holidays.csv:
holiday,type,desc
25-12-2012,global,Christmas
...

query:
index="physical" | lookup holidays holiday
produces error: "You cannot use timefield as a lookup field"

transform.conf:
[holidays]
filename = holidays.csv
time_field = holiday
time_format = %m-%d-%Y

The objective is to have all logs related to weekends and holidays.

Tags (1)
1 Solution

lguinn2
Legend

Hmmm, in your transforms.conf, you have the date as month-day-year, but in the csv file, the date is day-month-year. Perhaps that is the problem?

Or, try this query instead

index="physical" 
| eval holiday=strftime(_time,"%d-%m-%Y")
| lookup holidays holiday

This creates a field named holiday for each event, with a string format that matches the string format in your lookup table. Therefore, you should be able to change your transforms.conf to

[holidays]
filename = holidays.csv
default=not a holiday
min_matches = 1

And no time-based lookup will be needed. Note that this also will return the value "not a holiday" for any date that doesn't match an item in the table.

View solution in original post

lguinn2
Legend

Hmmm, in your transforms.conf, you have the date as month-day-year, but in the csv file, the date is day-month-year. Perhaps that is the problem?

Or, try this query instead

index="physical" 
| eval holiday=strftime(_time,"%d-%m-%Y")
| lookup holidays holiday

This creates a field named holiday for each event, with a string format that matches the string format in your lookup table. Therefore, you should be able to change your transforms.conf to

[holidays]
filename = holidays.csv
default=not a holiday
min_matches = 1

And no time-based lookup will be needed. Note that this also will return the value "not a holiday" for any date that doesn't match an item in the table.

krugger
Communicator

Done. Added the content of transform.conf

0 Karma

lguinn2
Legend

Can we see the transforms.conf entry that defines this lookup table? My guess is that something is missing, but there isn't quite enough info in your question. Thanks!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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