All Apps and Add-ons

How to update database table rows with Splunk data?

matstap
Communicator

I want to update a database table with data from Splunk. I need to join on an ID field. So if my data has a row with ID = A and the database table has a row with ID = A, that row should be updated with my new data. If my row has an ID that isn't already in the database table, add the new row.

I've tried dbxoutput, but that seems to only append all the new data without joining on any field. How have others achieved this?

0 Karma
1 Solution

kheo_splunk
Splunk Employee
Splunk Employee

If you want to upsert functionality in a database, "Enable Upsert" should be checked with a proper column name(in your case - ID column) under "Upsert Configuration" section in the 3rd step(Fields Mapping) when creating an database output.

Please check the following Splunk doc.
http://docs.splunk.com/Documentation/DBX/3.1.3/DeployDBX/Createandmanagedatabaseoutputs#Fields_mappi...

I have tested this funtionality using EMPLOYEES table on Oracle database and it worked for me. After configuring the database output using DB Connect UI, $SPLUNK_HOME/etc/apps/splunk_app_db_connect/local/db_outputs.conf shows the following. Please note that EMPLOYEE_ID is configured for unique_key and using_upsert as 1 below:

db_outputs.conf
[EMP]
connection = oracle
customized_mappings = COMMISSION_PCT:COMMISSION_PCT:3,DEPARTMENT_ID:DEPARTMENT_ID:3,EMAIL:EMAIL:12,EMPLOYEE_ID:EMPLOYEE_ID:3,FIRST_NAME:FIRST_NAME:12,JOB_ID:JOB_ID:12,LAST_NAME:LAST_NAME:12,HIRE_DATE:HIRE_DATE:93,PHONE_NUMBER:PHONE_NUMBER:12,SALARY:SALARY:3,MANAGER_ID:MANAGER_ID:3
disabled = 0
is_saved_search = 0
scheduled = 0
search = index=main sourcetype=dbx | search EMPLOYEE_ID=173
table_name = "SPLUNK"."EMPLOYEES"
ui_query_schema = SPLUNK
ui_query_table = EMPLOYEES
unique_key = EMPLOYEE_ID
using_upsert = 1

View solution in original post

0 Karma

kheo_splunk
Splunk Employee
Splunk Employee

If you want to upsert functionality in a database, "Enable Upsert" should be checked with a proper column name(in your case - ID column) under "Upsert Configuration" section in the 3rd step(Fields Mapping) when creating an database output.

Please check the following Splunk doc.
http://docs.splunk.com/Documentation/DBX/3.1.3/DeployDBX/Createandmanagedatabaseoutputs#Fields_mappi...

I have tested this funtionality using EMPLOYEES table on Oracle database and it worked for me. After configuring the database output using DB Connect UI, $SPLUNK_HOME/etc/apps/splunk_app_db_connect/local/db_outputs.conf shows the following. Please note that EMPLOYEE_ID is configured for unique_key and using_upsert as 1 below:

db_outputs.conf
[EMP]
connection = oracle
customized_mappings = COMMISSION_PCT:COMMISSION_PCT:3,DEPARTMENT_ID:DEPARTMENT_ID:3,EMAIL:EMAIL:12,EMPLOYEE_ID:EMPLOYEE_ID:3,FIRST_NAME:FIRST_NAME:12,JOB_ID:JOB_ID:12,LAST_NAME:LAST_NAME:12,HIRE_DATE:HIRE_DATE:93,PHONE_NUMBER:PHONE_NUMBER:12,SALARY:SALARY:3,MANAGER_ID:MANAGER_ID:3
disabled = 0
is_saved_search = 0
scheduled = 0
search = index=main sourcetype=dbx | search EMPLOYEE_ID=173
table_name = "SPLUNK"."EMPLOYEES"
ui_query_schema = SPLUNK
ui_query_table = EMPLOYEES
unique_key = EMPLOYEE_ID
using_upsert = 1

0 Karma

mchang_splunk
Splunk Employee
Splunk Employee

You can have dbxquery to call store procedure to achieve.

http://docs.splunk.com/Documentation/DBX/3.1.3/DeployDBX/Commands#Required_Arguments

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...