lookupsplunk

Getting Splunk's Lookups' scheme in a single query


I want to create a query to fetch all the lookups that I have in my Splunk system (or even a predefined list) and their full scheme.

It should include the headers and the types for each column.

I tried multiple options but none of them worked.

any ideas?

Thanks


Solution

  • TL:DR this is the SPL:

    | rest/servicesNS/-/-/data/lookup-table-files
    | fields title
    | regex "title"="\.csv$"
    | map search="| inputlookup $title$| head 100| foreach mode=multifield * [    eval <<FIELD>>=typeof(<<FIELD>>)]| stats count by [| inputlookup $title$| head 1| transpose| stats values(column) AS column| nomv column | return $column]| foreach mode=multifield * [    eval <<FIELD>>#####{<<FIELD>>}=count]| fields *####*| fields - count*| stats sum(*) AS *| transpose| rename \"row 1\" AS count| rex field=\"column\" \"^(?P<column_name>[^#]+)#####(?P<type>.*)$\"| eventstats max(count) AS most_frequent BY column_name| where count=most_frequent| eval structure=column_name.\":\".'type'| stats values(structure) AS structure| eval name=$title$" maxsearches=1000
    

    Okay, so this is kind of a hacky solution :) I will try to walk through it step-by-step. There might be some SPL optimizations to be done, but for now I am satisfied with a sort of straight forward and robust solution.

    1. Find all CSV Lookup Files
    1. For each Lookup get column name and most frequent data type per column.