Admin Manual

 


Set a default host for a file or directory input

This documentation does not apply to the most recent version of Splunk. Click here for the latest version.

Set a default host for a file or directory input

In certain situations you may want to explicitly set a host value for all data coming in to Splunk through a particular file or directory input. You can set the host statically or dynamically.

You can also assign host values to events coming through a particular file or directory input based on their source or sourcetype values (as well as other kinds of information). For more information, see "Overriding default host assignments based on event data," in this manual.

Note: Splunk currently does not enable the setting of default host values for event data received through TCP, UDP, or scripted inputs.

Statically setting the default host value for a file or directory input

This method applies a single default host value to each event received through a specific file or directory input.

Note:A static host value assignment only impacts new data coming in through the input with which it's associated. You cannot assign a default host value to data that has already been processed, split into events, and indexed.

If you need to assign a host value to data that's already been indexed, you need to tag the host value instead.

Via Splunk Web

You can statically define a host for a file or directory input whenever you add a new input of that type through the "Data inputs" page of Splunk Web's Manager interface:

1. In Splunk Web, click on the Manager link in the upper right-hand corner of the screen.

2. In Manager, click Data inputs under System configurations.

3. On the Data inputs page, select Files & Directories to go to the list page for that input type.

4. On the Files & directories page, you can either click the name of an input that you want to update, or click New to create a new file or directory input.

5. Once you're on the detail page for the file or directory input, select the Constant value option from the Set host dropdown.

6. Enter the static host value for the input in the Host field value field.

7. Save your changes.

For more information about inputs and input types, see "What Splunk can monitor" in the Admin guide.

Via configuration files

Edit inputs.conf to specify a host value for a monitored file or directory input. Include a host = attribute within the appropriate stanza.

[monitor://<path>]
host = $YOUR_HOST

Edit inputs.conf in $SPLUNK_HOME/etc/system/local/, or your own custom application directory in $SPLUNK_HOME/etc/apps/. For more information on configuration files in general, see "About configuration files" in the Admin manual.

For more information about inputs and input types, see "What Splunk can monitor" in the Admin manual.

Example of static host value assignment for an input

This example covers any events coming in from /var/log/httpd. Any events coming from this input will receive a host value of webhead-1.

[monitor:///var/log/httpd]
host = webhead-1


Dynamically setting the default host value for a file or directory input

Use this method if you want to dynamically extract the host value for a file or directory input, either from a segment of the source input path, or from a regular expression. For example, if you want to index an archived directory and the name of each file in the directory contains relevant host information, you can use Splunk to extract this information and assign it to the host field.

Via Splunk Web

Start by following the steps for setting up a static host assignment via Splunk Web, above. However, when you get to the Set host dropdown list on the input details page for a file or directory input, choose one of the following two values:

Note: For a primer on regular expression syntax and usage, see Regular-Expressions.info. You can test regexes by using them in searches with the rex search command. Splunk also maintains a list of useful third-party tools for writing and testing regular expressions.

Via configuration files

You can set up dynamic host extraction rules when you are configuring inputs.conf. Edit inputs.conf in $SPLUNK_HOME/etc/system/local/, or your own custom application directory in $SPLUNK_HOME/etc/apps/. For more information on configuration files in general, see "About configuration files" in the Admin manual.

Add host_regex = <regular expression> to override the host field with a value extracted using a regular expression.

[monitor://<path>]
host_regex = $YOUR_REGEX

The regular expression extracts the host value from the filename of each input. The first capturing group of the regex is used as the host.

Note: If the regex fails to match, the default host = attribute is set as the host.

Important: For a primer on regular expression syntax and usage, see Regular-Expressions.info. You can test regexes by using them in searches with the rex search command. Splunk also maintains a list of useful third-party tools for writing and testing regular expressions.

host_segment = <integer>

Define a host_segment instead of a host_regex if you want to override the host field with a value extracted using a segment of the data source path. For example, if the path to the source is /var/log/[host server name] and you want the third segment (the host server name) to be the host value, your input stanza would look like:

[monitor://var/log/]
host_segment = 3

Note: If the <integer> value is not an integer, or is less than 1, Splunk sets the default host = attribute as the host.

Note: You cannot simultaneously specify a host_regex and host_segment.

Examples of dynamic host assignment for an input

This example uses regex on the file path to set the host:

[monitor://var/log]
host_regex = /var/log/(\w+)

With that regex, all events from /var/log/foo.log are given the a host value of foo.

This example uses the segment of the data source filepath to set the host:

[monitor://apache/logs/]
host_segment = 3

It sets the host value to the third segment in the path apache/logs.

This documentation applies to the following versions of Splunk: 4.1 , 4.1.1 , 4.1.2 , 4.1.3 , 4.1.4 , 4.1.5 , 4.1.6 , 4.1.7 , 4.1.8 View the Article History for its revisions.


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

Was this documentation topic helpful?

If you'd like to hear back from us, please provide your email address:

We'd love to hear what you think about this topic or the documentation as a whole. Feedback you enter here will be delivered to the documentation team.

Feedback submitted, thanks!