All Apps and Add-ons

Splunk DB Connect: How to compare stored database queries to detect when field (column) values are changed, added, or removed?

mcomfurf
Path Finder

We're indexing a database table that stores saved database queries, and want to alert when the stored queries are changed. We are successfully doing so, but have experienced numerous false alarms when a change is made only to the order of columns (eg SELECT Address,Postalcode FROM Customers is changed to SELECT Postalcode,Address FROM Customers)

A simple character count comparison at the Query ID level would provide an 80% solution. What I need is to detect when the field (column) values have changed, or if fields are added or removed from the saved query.

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Perhaps this will help. The goal is to extract the column names, sort them, then compare them.

... | rex field=oldQuery "SELECT (?<oldColumns>.*) FROM" | eval oldColumnList=mvjoin(mvsort(split(oldColumns),","),",") | 
rex field=newQuery "SELECT (?<newColumns>.*) FROM" | eval newColumnList=mvjoin(mvsort(split(newColumns),","),",") | where oldColumnList<>newColumnList | ...
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Perhaps this will help. The goal is to extract the column names, sort them, then compare them.

... | rex field=oldQuery "SELECT (?<oldColumns>.*) FROM" | eval oldColumnList=mvjoin(mvsort(split(oldColumns),","),",") | 
rex field=newQuery "SELECT (?<newColumns>.*) FROM" | eval newColumnList=mvjoin(mvsort(split(newColumns),","),",") | where oldColumnList<>newColumnList | ...
---
If this reply helps you, Karma would be appreciated.
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...