- Splunk Operational Intelligence Cookbook
- Josh Diakun Paul R Johnson Derek Mock
- 353字
- 2025-04-04 16:53:01
How to do it...
Follow these steps to monitor and index the contents of a file:
- Log in to your Splunk server.
- From the menu in the top right-hand corner, click on the Settings menu and then click on the Add Data link:
- If you are prompted to take a quick tour, click on Skip.
- In the How do you want to add data section, click on monitor:
- Click on the Files & Directories section:
- In the File or Directory section, enter the path to the logfile (/var/log/messages or the location of the cp01_messages.log file), ensure Continuously Monitor is selected, and click on Next:
If you are just looking to do a one-time upload of a file, you can select Index Once instead. This can be useful to index a set of data that you would like to put into Splunk, either to backfill some missing or incomplete data or just to take advantage of its searching and reporting tools.
- If you are using the provided file or the native /var/log/messages file, the data preview will show the correct line breaking of events and timestamp recognition. Click on the Next button.
- A Save Source Type box will pop up. Enter linux_messages as the Name and then click on Save:
- On the Input Settings page, leave all the default settings and click Review.
- Review the settings and if everything is correct, click Submit.
- If everything was successful, you should see a File input has been created successfully message:
- Click on the Start searching button. The Search & Reporting app will open with the search already populated based on the settings supplied earlier in the recipe.
In this recipe, we could have simply used the common syslog source type or let Splunk choose a source type name for us; however, starting a new source type is often a better choice. The syslog format can look completely different depending on the data source. As knowledge objects, such as field extractions, are built on top of source types, using a single syslog source type for everything can make it challenging to search for the data you need.