Whitelist or blacklist specific incoming data

You can use whitelist and blacklist rules to specify which files to consume or exclude when monitoring directories. You can also apply these settings to batch inputs. When you define a whitelist, Splunk Enterprise only indexes the files you specify. When you define a blacklist, the software ignores the specified files and processes all other files. You define whitelists and blacklists in the input stanza in inputs.conf. If you want to apply the same blacklists and whitelists across all your forwarders, you can set up a deployment server.

It is not necessary to define both a whitelist and a blacklist in a stanza. They are independent settings. If you do define both and a file matches both, Splunk Enterprise does not index that file as blacklist overrides whitelist.

Whitelist and blacklist rules use regular expression syntax to define the match on the file name/path. They must be contained within a configuration stanza, for example [monitor://<path>]. Splunk software whitelists and blacklists outside of stanzas. When you define whitelist and blacklist entries, you must use exact regular expression syntax.

Route and filter data

Instead of whitelisting or blacklisting your data inputs, you can filter specific events and send them to different queues or indexes. You can also use the crawl feature to predefine files you want to index or to exclude from indexing when they get added to your file system.

Whitelist (allow) files

Add the following line to your monitor stanza in the /local/inputs.conf file for the app context that you defined the input.

whitelist = <your_custom regex>

For example, to monitor only files with the .log extension:

[monitor:///mnt/logs]
whitelist = \.log$

Whitelist multiple files

You can whitelist multiple files in one line, using the "|" (OR) operator. For example, to whitelist filenames that contain query.log OR my.log.

whitelist = query\.log$|my\.log$

Or, you can whitelist an exact match.

whitelist = /query\.log$|/my\.log$

Note: The "$" anchors the regular expression to the end of the line. There is no space before or after the "|" operator.

Blacklist (ignore) files

Add the following line to your monitor stanza in the /local/inputs.conf file for the app context that you defined the input in.

blacklist = <your_custom_regex>

If you create a blacklist line for each file you want to ignore, Splunk Enterprise activates only the last filter.

Example: Blacklist only files with a .txt extension

To ignore and not monitor only files with the .txt extension:

[monitor:///mnt/logs]
blacklist = \.txt$

Example 2: Blacklist files with either a .txt or .gz extension

To ignore and not monitor all files with either the .txt extension OR the .gz extension (note that you use the "|" for this):

[monitor:///mnt/logs]
blacklist = \.(?:txt|gz)$

Example 3: Blacklist an entire directory

To ignore entire directories beneath a monitor input:

[monitor:///mnt/logs]
blacklist = archive|historical|\.bak$

This example tells Splunk Enterprise to ignore all files under /mnt/logs/ within the archive or historical directories and all files ending in *.bak.

Example 4: Blacklist a file whose name contains a string

To ignore files whose names contain a specific string, you can do:

[monitor:///mnt/logs]
blacklist = 2009022[89]file\.txt$

This example ignores the webserver20090228file.txt and webserver20090229file.txt files under /mnt/logs/.

Enter your email address, and someone from the documentation team will respond to you:

Send me a copy of this feedback

Please provide your comments here. Ask a question or make a suggestion.

Feedback submitted, thanks!

You must be logged into splunk.com in order to post comments.
Log in now.

Please try to keep this discussion focused on the content covered in this documentation topic.
If you have a more general question about Splunk functionality or are experiencing a difficulty with Splunk,
consider posting a question to Splunkbase Answers.

0
out of 1000 Characters

Your Comment Has Been Posted Above

We use our own and third-party cookies to provide you with a great online experience. We also use these cookies to improve our products and services, support our marketing campaigns, and advertise to you on our website and other websites. Some cookies may continue to collect information after you have left our website.
Learn more (including how to update your settings) here »