Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Implementing Splunk 7, Third Edition - Third Edition

You're reading from  Implementing Splunk 7, Third Edition - Third Edition

Product type Book
Published in Mar 2018
Publisher Packt
ISBN-13 9781788836289
Pages 576 pages
Edition 3rd Edition
Languages

Table of Contents (19) Chapters

Title Page
Packt Upsell
Contributors
Preface
The Splunk Interface Understanding Search Tables, Charts, and Fields Data Models and Pivots Simple XML Dashboards Advanced Search Examples Extending Search Working with Apps Building Advanced Dashboards Summary Indexes and CSV Files Configuring Splunk Advanced Deployments Extending Splunk Machine Learning Toolkit Index

Using macros to reuse logic


A macro serves the purpose of replacing bits of search language with expanded phrases (additionally, macros have other uses, such as assisting in workflow creation).

Using macros can help you reuse logic and greatly reduce the length of queries.

Let's use the following as our example case:

sourcetype="impl_splunk_gen_SomeMoreLogs" user=mary 
| transaction maxpause=5m user 
| stats avg(duration) avg(eventcount) 

Creating a simple macro

Let's take the last two lines of our query and convert them to a macro. First, navigate to Settings | Advanced search | Search macros and click on New:

Walking through our fields, we have the following:

  • Destination app: This is where the macro will live.
  • Name: This is the name we will use in our searches.
  • Definition: This is the text that will be placed in our search.
  • Use eval-based definition?: If checked, the Definition string is treated as an eval statement instead of the raw text. We'll use this option later.

The remaining fields are used...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}