In this recipe, you will install and leverage DB Connect to search an external database's product inventory table. You will then pull this data back into Splunk and turn it into a local lookup that harvests the data once per day. This product inventory table will be used in the next chapter.
DB Connect has a dedicated Splunk manual that can be found at http://docs.splunk.com/Documentation/DBX/latest/DeployDBX.
To step through this recipe, you will need a running Splunk Enterprise server, with the sample data loaded from Chapter 1, Play Time – Getting Data In. You should be familiar with navigating the Splunk user interface.
Additionally, it is recommended that you have one of the following supported databases installed:
DB Connect might work with other JDBC-compatible databases and data stores, but this is not guaranteed. DB Connect 2 has several prerequisites detailed in the installation manual. Before attempting this recipe, ensure that you have installed Java Platform, Standard Edition Development Kit (JDK) 8 (update 31 or later) from Oracle. Additionally, you will also need to download the database drivers for your particular database.
Assuming JDK 8 is installed and your needed database drivers are downloaded, follow the steps in this recipe to generate a local Splunk lookup using data from an external database and DB Connect:
productdb
, and within the database, create a new table called productInventory
. Insert the contents of the provided productInventory.csv
file into the new database table. The new table will resemble the following screenshot:Splunk DB Connect 2
application and then select it to install it. You will have to enter your http://www.splunk.com/ account credentials after hitting the Install button. When prompted, select to Restart Splunk.If your environment has no Internet access, you can download the DB Connect 2 application from the Splunk app store at https://splunkbase.splunk.com/app/2686. Once it is downloaded, you can upload and install the application to your Splunk environment by selecting Manage Apps from step 2.
1024m
, as this will allocate more memory and result in faster performance. Click Save and ensure JRE Status is green. Then click the Next button.productInventory
table in your database. The search should return the tabulated results.| dbxquery connection=product_database query="SELECT%20*%20FROM%20productInventory" shortnames=true| fields - _raw, _time | table *
productInventory
table should now be displayed inside Splunk.| dbxquery connection=product_database query="SELECT%20*%20FROM%20productInventory" shortnames=true| fields - _raw, _time | table *| outputlookup productInventory.csv
generate_productInventory_dblookup
.DB Connect enables real-time integration between Splunk and traditional relational databases. In this recipe, you installed the DB Connect application and configured it to talk to a product inventory table in your external productdb
database. When installed, DB Connect sets up something called a Java Bridge Server, which is essentially a Java Virtual Machine (JVM) that constantly runs in the background. The Java Bridge Server helps speed up connectivity to external databases by allocating memory and caching a lot of the metadata associated with the database tables. Once the productdb
database was configured through DB Connect, you were able to execute standard SQL inside a Splunk search and return the contents of the productInventory
table to Splunk. Once the data is in Splunk, it is treated the same as any other data inside of Splunk, and you were able to very easily turn the data into a local lookup using the outputlookup
command.
The approach used in this recipe leverages the dbxquery
command, which is limited by default to returning 100,000 rows. For larger datasets, a DB Input can be set up in the DB Connect application to index the data in bulk on a schedule, such as once per day. This indexed data can then be converted to a lookup using the outputlookup
command. Alternatively, the DB Lookup functionality of DB Connect can be leveraged and this is explained next.
In this recipe, we chose to pull the data out of the database and create a lookup locally in Splunk. However, rather than creating the lookup locally, DB Connect also allows you to look up data in the database directly and cache it, using the DB Lookups functionality. In addition, DB Connect is able to monitor external database tables and index content into Splunk either in bulk or in a polling capacity using the DB Inputs functionality.
Rather than creating the lookup locally inside Splunk, as we did with this recipe, Splunk DB Connect allows you to create a lookup table that uses an external database table as its source. This lookup can be cached so that the database is not continually searched by Splunk users.
productInventory_dblookup
into the Name field and select product_database in the Connection field.itemId
. Run the following search over Last 15 minutes and select the itemId
column in the results. This will then show 1 in the Fields Selected box.index=main sourcetype=log4j itemId=*
index=main sourcetype=log4j itemId=*| lookup local=1 db_connect_productInventory_dblookup itemId AS itemId
local=1
in the search. This is because DB Connect database lookups are constrained only to the search head where DB Connect is installed.3.17.150.89