Route and filter data
This documentation does not apply to the most recent version of Splunk. Click here for the latest version.
Contents
- Configure routing
- Filter and route event data to target groups
- Replicate a subset of data to a third-party system
- Filter event data and send to queues
- Discard specific events and keep the rest
- Keep specific events and discard the rest
- Filter WMI events
- Filter data by target index
- Forward all external and internal index data
- Forward data for a single index only
- Use the forwardedindex attributes with local indexing
- Route inputs to specific indexers based on the data's input
- Perform selective indexing and forwarding
- Configure selective indexing
- Index one input locally and then forward the remaining inputs
- Index one input locally and then forward all inputs
- Another way to index one input locally and then forward all inputs
- Selective indexing and internal logs
Route and filter data
Forwarders can filter and route data to specific receivers based on criteria such as source, source type, or patterns in the events themselves. For example, a forwarder can send all data from one group of hosts to one Splunk server and all data from a second group of hosts to a second Splunk server. Heavy forwarders can also look inside the events and filter or route accordingly. For example, you could use a heavy forwarder to inspect WMI event codes to filter or route Windows events. This topic describes a number of typical routing scenarios.
Besides routing to receivers, forwarders can also filter and route data to specific queues or discard the data altogether by routing to the null queue.
Important: Only heavy forwarders can route or filter data at the event level. Universal forwarders and light forwarders do not have the ability to inspect individual events, but they can still forward data based on a data stream's host, source, or source type. They can also route based on the data's input stanza, as described here.
Here's a simple illustration of a forwarder routing data to three Splunk receivers:
This topic describes how to filter and route event data to Splunk instances. See "Forward data to third-party systems" in this manual for information on routing to non-Splunk systems.
This topic also describes how to perform selective indexing and forwarding, in which you index some data locally on a heavy forwarder and forward the non-indexed data to one or more sepearate indexers. See "Perform selective indexing and forwarding" later in this topic for details.
Configure routing
This is the basic pattern for defining most routing scenarios (using a heavy forwarder):
1. Determine what criteria to use for routing. How will you identify categories of events, and where will you route them?
2. Edit props.conf to add a TRANSFORMS-routing attribute to determine routing based on event metadata:
[<spec>] TRANSFORMS-routing=<transforms_stanza_name>
<spec> can be:
-
<sourcetype>, the source type of an event -
host::<host>, where <host> is the host for an event -
source::<source>, where <source> is the source for an event
Use the <transforms_stanza_name> specified here when creating an entry in transforms.conf (below).
Examples later in this topic show how to use this syntax.
3. Edit transforms.conf to specify target groups and to set additional criteria for routing based on event patterns:
[<transforms_stanza_name>] REGEX=<routing_criteria> DEST_KEY=_TCP_ROUTING FORMAT=<target_group>,<target_group>,....
Note:
-
<transforms_stanza_name>must match the name you defined inprops.conf. - In
<routing_criteria>, enter the regex rules that determine which events get routed. This line is required. Use "REGEX = ." if you don't need additional filtering beyond the metadata specified inprops.conf. -
DEST_KEYshould be set to_TCP_ROUTINGto send events via TCP. It can also be set to_SYSLOG_ROUTINGor_HTTPOUT_ROUTINGfor other output processors. - Set
FORMATto a<target_group>that matches a target group name you defined inoutputs.conf. A comma separated list will clone events to multiple target groups.
Examples later in this topic show how to use this syntax.
4. Edit outputs.conf to define the target group(s) for the routed data:
[tcpout:<target_group>] server=<ip>:<port>
Note:
- Set
<target_group>to match the name you specified intransforms.conf. - Set the IP address and port to match the receiving server.
The use cases described in this topic generally follow this pattern.
Filter and route event data to target groups
In this example, a heavy forwarder filters three types of events, routing them to different target groups. The forwarder filters and routes according to these criteria:
- Events with a source type of "syslog" to a load-balanced target group
- Events containing the word "error" to a second target group
- All other events to a default target group
Here's how you do it:
1. Edit props.conf in $SPLUNK_HOME/etc/system/local to set two TRANSFORMS-routing attributes — one for syslog data and a default for all other data:
[default] TRANSFORMS-routing=errorRouting [syslog] TRANSFORMS-routing=syslogRouting
2. Edit transforms.conf to set the routing rules for each routing transform:
[errorRouting] REGEX=error DEST_KEY=_TCP_ROUTING FORMAT=errorGroup [syslogRouting] REGEX=. DEST_KEY=_TCP_ROUTING FORMAT=syslogGroup
Note: In this example, if a syslog event contains the word "error", it will route to syslogGroup, not errorGroup. This is due to the settings previously specified in props.conf. Those settings dictated that all syslog events be filtered through the syslogRouting transform, while all non-syslog (default) events be filtered through the errorRouting transform. Therefore, only non-syslog events get inspected for errors.
3. Edit outputs.conf to define the target groups:
[tcpout] defaultGroup=everythingElseGroup [tcpout:syslogGroup] server=10.1.1.197:9996, 10.1.1.198:9997 [tcpout:errorGroup] server=10.1.1.200:9999 [tcpout:everythingElseGroup] server=10.1.1.250:6666
syslogGroup and errorGroup receive events according to the rules specified in transforms.conf. All other events get routed to the default group, everythingElseGroup.
Replicate a subset of data to a third-party system
This example uses data filtering to route two data streams. It forwards:
- All the data, in cooked form, to a Splunk indexer (10.1.12.1:9997)
- A replicated subset of the data, in raw form, to a third-party server (10.1.12.2:1234)
The example sends both streams as TCP. To send the second stream as syslog data, first route the data through an indexer.
1. Edit props.conf:
[syslog] TRANSFORMS-routing = routeAll, routeSubset
2. Edit transforms.conf:
[routeAll] REGEX=(.) DEST_KEY=_TCP_ROUTING FORMAT=Everything [routeSubset] REGEX=(SYSTEM|CONFIG|THREAT) DEST_KEY=_TCP_ROUTING FORMAT=Subsidiary,Everything
3. Edit outputs.conf:
[tcpout] defaultGroup=nothing [tcpout:Everything] disabled=false server=10.1.12.1:9997 [tcpout:Subsidiary] disabled=false sendCookedData=false server=10.1.12.2:1234
For more information, see "Forward data to third party systems" in this manual.
Filter event data and send to queues
Although similar to forwarder-based routing, queue routing can be performed by an indexer, as well as a heavy forwarder. It does not use the outputs.conf file, just props.conf and transforms.conf.
You can eliminate unwanted data by routing it to nullQueue, Splunk's /dev/null equivalent. When you filter out data in this way, the filtered data is not forwarded or added to the Splunk index at all, and doesn't count toward your indexing volume.
Discard specific events and keep the rest
This example discards all sshd events in /var/log/messages by sending them to nullQueue:
1. In props.conf, set the TRANSFORMS-null attribute:
[source::/var/log/messages] TRANSFORMS-null= setnull
2. Create a corresponding stanza in transforms.conf. Set DEST_KEY to "queue" and FORMAT to "nullQueue":
[setnull] REGEX = \[sshd\] DEST_KEY = queue FORMAT = nullQueue
That does it.
Keep specific events and discard the rest
Here's the opposite scenario. In this example, you use two transforms to keep only the sshd events. One transform routes sshd events to indexQueue, while another routes all other events to nullQueue.
Note: In this example, the order of the transforms in props.conf matters. The null queue transform must come first; if it comes later, it will invalidate the previous transform and route all events to the null queue.
1. In props.conf:
[source::/var/log/messages] TRANSFORMS-set= setnull,setparsing
2. In transforms.conf:
[setnull] REGEX = . DEST_KEY = queue FORMAT = nullQueue [setparsing] REGEX = \[sshd\] DEST_KEY = queue FORMAT = indexQueue
Filter WMI events
To filter on WMI events, use [WMI:WinEventLog:Security] source type stanza in props.conf. The following example uses regex to filter out two Windows event codes, 592 and 593:
In props.conf:
[WMI:WinEventLog:Security] TRANSFORMS-wmi=wminull
Note: In pre-4.2.x versions of Splunk, you must use [wmi] as the sourcetype in order to send events to nullQueue.
In transforms.conf:
[wminull] REGEX=(?m)^EventCode=(592|593) DEST_KEY=queue FORMAT=nullQueue
Filter data by target index
Forwarders have a forwardedindex filter that allows you to specify whether data gets forwarded, based on the data's target index. For example, if you have one data input targeted to "index1" and another targeted to "index2", you can use the filter to forward only the data targeted to index1, while ignoring the index2 data. The forwardedindex filter uses whitelists and blacklists to specify the filtering. For information on setting up multiple indexes, see the topic "Set up multiple indexes".
Note: The forwardedindex filter is only applicable under the global [tcpout] stanza. This filter does not work if it is created under any other stanza in outputs.conf.
Use the forwardedindex.<n>.whitelist|blacklist attributes in outputs.conf to specify which data should get forwarded on an index-by-index basis. You set the attributes to regexes that filter the target indexes. By default, the forwarder forwards data targeted for all external indexes, as well as the data for the _audit internal index. It does not forward data to other internal indexes. The default outputs.conf file specifies that behavior with these attributes:
[tcpout] forwardedindex.0.whitelist = .* forwardedindex.1.blacklist = _.* forwardedindex.2.whitelist = _audit
In most deployments, you will not need to override the default settings. See outputs.conf for more information on how to whitelist and blacklist indexes.
Forward all external and internal index data
If you want to forward all internal index data (and not just the internal data in _audit), as well as all external data, you can override the default forwardedindex filter attributes like this:
#Forward everything [tcpout] forwardedindex.0.whitelist = .* # disable these forwardedindex.1.blacklist = forwardedindex.2.whitelist =
Forward data for a single index only
If you want to forward only the data targeted for a single index (for example, as specified in inputs.conf), and drop any data that's not target for that index, here's how to do it:
[tcpout] #Disable the current filters from the defaults outputs.conf forwardedindex.0.whitelist = forwardedindex.1.blacklist = forwardedindex.2.whitelist = #Forward data for the "myindex" index forwardedindex.0.whitelist = myindex
This first disables all filters from the default outputs.conf file. It then sets the filter for your own index. Be sure to start the filter numbering with 0: forwardedindex.0.
Note: If you've set other filters in another copy of outputs.conf on your system, you must disable those as well.
You can use the CLI btools command to ensure that there aren't any other filters located in other outputs.conf files on your system:
splunk btools outputs list tcpout
This command returns the content of the tcpout stanza, after all versions of the configuration file have been combined.
Use the forwardedindex attributes with local indexing
On a heavy forwarder, you can index locally. To do that, you must set indexAndForward attribute to "true". Otherwise, the forwarder just forwards your data and does not save it on the forwarder. On the other hand, the forwardedindex attributes only filter forwarded data; they do not filter any data that gets saved to the local index.
In a nutshell, local indexing and forwarder filtering are entirely separate operations, which do not coordinate with each other. This can have unexpected implications when you're performing blacklist filtering:
- If you set
indexAndForwardto "true" and then filter out some data throughforwardedindexblacklist attributes, the blacklisted data will not get forwarded, but it will still get locally indexed. - If you set
indexAndForwardto "false" (no local indexing) and then filter out some data, the filtered data will get dropped entirely, since it doesn't get forwarded and it doesn't get saved (indexed) on the forwarder.
Route inputs to specific indexers based on the data's input
There is one type of routing that doesn't require a heavy forwarder. In this scenario, you use inputs.conf and outputs.conf to route data to specific indexers, based on the data's input.
Here's an example that shows how this works.
1. In outputs.conf, you create stanzas for each receiving indexer:
[tcpout:systemGroup] server=server1:9997 [tcpout:applicationGroup] server=server2:9997
2. In inputs.conf, you use _TCP_ROUTING to specify the stanza in outputs.conf that each input should use for routing:
[monitor://.../file1.log] _TCP_ROUTING = systemGroup [monitor://.../file2.log] _TCP_ROUTING = applicationGroup
The forwarder will route data from file1.log to server1 and data from file2.log to server2.
Perform selective indexing and forwarding
With a heavy forwarder only, you can index and store data locally, as well as forward the data onwards to a receiving indexer. There are two ways to do this:
- Index all the data before forwarding it. To do this, just enable the
indexAndForwardattribute inoutputs.conf.
- Index a subset of the data before forwarding it or other data. This is called selective indexing. With selective indexing, you can index just some of the data locally and then forward it on to a receiving indexer. Alternatively, you can choose to forward only the data that you don't index locally.
Important: Do not enable the indexAndForward attribute in the [tcpout] stanza if you're also enabling selective forwarding.
Configure selective indexing
To use selective indexing, you need to modify both your inputs.conf and outputs.conf files:
1. In outputs.conf:
a. Add the [indexAndForward] stanza:
[indexAndForward] index=true selectiveIndexing=true
The presence of this stanza, including the index and selectiveIndexing attributes, turns on selective indexing for the forwarder. It enables local indexing for any input (specified in inputs.conf) that has the _INDEX_AND_FORWARD_ROUTING attribute. Use the entire [indexAndForward] stanza exactly as shown here.
Note: This is a global stanza, which only needs to appear once in outputs.conf.
b. Include the usual target group stanzas for each set of receiving indexers:
[tcpout:<target_group>] server = <ip address>:<port>, <ip address>:<port>, ... ...
The named <target_group> is used in inputs.conf to route the inputs, as described below.
2. In inputs.conf:
a. Add the _INDEX_AND_FORWARD_ROUTING attribute to the stanzas of each input that you want to index locally:
[input_stanza] _INDEX_AND_FORWARD_ROUTING=<any_string> ...
The presence of the _INDEX_AND_FORWARD_ROUTING attribute tells the heavy forwarder to index that input locally. You can set the attribute to any string value you want. Splunk just looks for the attribute itself; the string value has no effect at all on behavior.
b. Add the _TCP_ROUTING attribute to the stanzas of each input that you want to forward:
[input_stanza] _TCP_ROUTING=<target_group> ...
The <target_group> is the name used in outputs.conf to specify the target group of receiving indexers.
The next several sections show how to use selective indexing in a variety of scenarios.
Index one input locally and then forward the remaining inputs
In this example, the forwarder indexes data from one input locally but does not forward it. It also forwards data from two other inputs but does not index those inputs locally.
1. In outputs.conf, create these stanzas:
[tcpout] defaultGroup=noforward disabled=false [indexAndForward] index=true selectiveIndexing=true [tcpout:indexerB_9997] server = indexerB:9997 [tcpout:indexerC_9997] server = indexerC:9997
Since the defaultGroup is set to the non-existent group "noforward" (meaning that there is no defaultGroup), the forwarder will only forward data that's been routed to explicit target groups in inputs.conf. All other data will get dropped.
2. In inputs.conf, create these stanzas:
[monitor:///mydata/source1.log] _INDEX_AND_FORWARD_ROUTING=local [monitor:///mydata/source2.log] _TCP_ROUTING=indexerB_9997 [monitor:///mydata/source3.log] _TCP_ROUTING=indexerC_9997
The result:
- Splunk indexes the
source1.logdata locally but does not forward it (because there's no explicit routing in its input stanza and there's no default group inoutputs.conf). - Splunk forwards the
source2.logdata to indexerB but does not index it locally. - Splunk forwards the
source3.logdata to indexerC but does not index it locally.
Index one input locally and then forward all inputs
This example is nearly identical to the previous one. The difference is that here, you index just one input locally, but then you forward all inputs, including the one you've indexed locally.
1. In outputs.conf, create these stanzas:
[tcpout] defaultGroup=noforward disabled=false [indexAndForward] index=true selectiveIndexing=true [tcpout:indexerB_9997] server = indexerB:9997 [tcpout:indexerC_9997] server = indexerC:9997
This outputs.conf is identical to the previous example.
2. In inputs.conf, create these stanzas:
[monitor:///mydata/source1.log] _INDEX_AND_FORWARD_ROUTING=local _TCP_ROUTING=indexerB_9997 [monitor:///mydata/source2.log] _TCP_ROUTING=indexerB_9997 [monitor:///mydata/source3.log] _TCP_ROUTING=indexerC_9997
The only difference from the previous example is that here, you've specified the _TCP_ROUTING attribute for the input that you're indexing locally. Splunk will route both source1.log and source2.log to the indexerB_9997 target group, but it will only locally index the data from source1.log.
Another way to index one input locally and then forward all inputs
You can achieve the same result as in the previous example by setting the defaultGroup to a real target group.
1. In outputs.conf, create these stanzas:
[tcpout] defaultGroup=indexerB_9997 disabled=false [indexAndForward] index=true selectiveIndexing=true [tcpout:indexerB_9997] server = indexerB:9997 [tcpout:indexerC_9997] server = indexerC:9997
This outputs.conf sets the defaultGroup to indexerB_9997.
2. In inputs.conf, create these stanzas:
[monitor:///mydata/source1.log] _INDEX_AND_FORWARD_ROUTING=local [monitor:///mydata/source2.log] _TCP_ROUTING=indexerB_9997 [monitor:///mydata/source3.log] _TCP_ROUTING=indexerC_9997
Even though you haven't set up an explicit routing for source1.log, Splunk will still forward it to the indexerB_9997 target group, since outputs.conf specifies that group as the defaultGroup.
Selective indexing and internal logs
Once you enable selective indexing in outputs.conf, the forwarder will only index locally those inputs with the _INDEX_AND_FORWARD_ROUTING attribute. This applies to the internal logs in the /var/log/splunk directory (specified in the default etc/system/default/inputs.conf). By default, they will not be indexed. If you want to index them, you must add their input stanza to your local inputs.conf file (which takes precedence over the default file) and include the _INDEX_AND_FORWARD_ROUTING attribute:
[monitor://$SPLUNK_HOME/var/log/splunk] index = _internal _INDEX_AND_FORWARD_ROUTING=local
This documentation applies to the following versions of Splunk: 4.2 , 4.2.1 , 4.2.2 , 4.2.3 , 4.2.4 , 4.2.5 , 4.3 , 4.3.1 , 4.3.2 , 4.3.3 , 4.3.4 , 4.3.5 , 4.3.6 View the Article History for its revisions.
Comments
Tzhmaba2,
Thanks for your comment. The intent of the example was to show how to forward all internal data as well as all external data. I've clarified that in the explanation for the example, rather than changing the example itself. In the normal case, you would want to forward your external data, not just the internal data.
A small (but VERY important typo) I guess...
In the paragraph http://docs.splunk.com/Documentation/Splunk/latest/Deploy/Routeandfilterdatad?r=searchtip#Forward_all_internal_index_data
#Forward everything
[tcpout]
forwardedindex.0.whitelist = .*
# disable these
forwardedindex.1.blacklist =
forwardedindex.2.whitelist =
This will route EACH and EVERY (.*) index and not just the internal indexes as stated. In my opinion It should read the following:
#Forward everything
[tcpout]
forwardedindex.0.whitelist = _.*
# disable these
forwardedindex.1.blacklist =
forwardedindex.2.whitelist =
Note the underline '_' before .* as all internal indexes begin with '_'. This can lead to loss of data if you do this e.g. on a search head where you have local summary indexes which do not exist on your indexers.
This doesn't work.
One indexer server and one universal forwarder. The configuration is being done in the Indexer since universal forwarder according to the docs doesn't do parsing.
REGEX is set to "." to test if the filtering is working.
SPLUNK\etc\system\local\props.conf
[WinEventLog:Security]
TRANSFORMS-setnull = setnull
SPLUNK\etc\system\local\transforms.conf
[setnull]
REGEX = .
DEST_KEY = queue
FORMAT = nullQueue
This configuration is supposed to filter everything from WinEventLog:Security.

Error in REGEX for filtering WMI events.
[wminull]
REGEX=(?m)^EventCode=(592|593)
Should read:
[wminull]
REGEX=(?m)^EventCode=(592|593)$
Note the $ sign, meaning end of the line. Otherwise, the numbers like these would be matched: 5923 5932 etc...