Splunk Developer s Guide 2nd Edition Kyle Smith download pdf
Splunk Developer s Guide 2nd Edition Kyle Smith download pdf
com
https://textbookfull.com/product/splunk-developer-s-
guide-2nd-edition-kyle-smith/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/the-developer-s-guide-to-microsoft-
azure-microsoft/
textboxfull.com
https://textbookfull.com/product/beginning-power-apps-the-non-
developer-s-guide-to-building-business-applications-2nd-edition-tim-
leung/
textboxfull.com
https://textbookfull.com/product/sql-server-2016-developer-s-
guide-1st-edition-dejan-sarka/
textboxfull.com
https://textbookfull.com/product/soft-skills-the-software-developer-s-
life-manual-2nd-edition-john-sonmez/
textboxfull.com
AWS Certified Developer Associate Guide Your one stop
solution to pass the AWS developer s certification 1st
Edition Vipul Tankariya
https://textbookfull.com/product/aws-certified-developer-associate-
guide-your-one-stop-solution-to-pass-the-aws-developer-s-
certification-1st-edition-vipul-tankariya/
textboxfull.com
https://textbookfull.com/product/tom-smith-s-cricket-umpiring-and-
scoring-2017-code-2nd-edition-laws-edition-tom-smith/
textboxfull.com
Implementing Splunk 7 D.
https://textbookfull.com/product/implementing-splunk-7-d/
textboxfull.com
https://textbookfull.com/product/compact-key-for-schools-teacher-s-
book-2nd-edition-smith/
textboxfull.com
https://textbookfull.com/product/women-s-studies-the-basics-2nd-
edition-bonnie-g-smith/
textboxfull.com
Splunk Developer's Guide
Second Edition
Kyle Smith
BIRMINGHAM - MUMBAI
Splunk Developer's Guide
Second Edition
All rights reserved. No part of this book may be reproduced, stored in a retrieval
system, or transmitted in any form or by any means, without the prior written
permission of the publisher, except in the case of brief quotations embedded in
critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy
of the information presented. However, the information contained in this book is
sold without warranty, either express or implied. Neither the author, nor Packt
Publishing, and its dealers and distributors will be held liable for any damages
caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the
companies and products mentioned in this book by the appropriate use of capitals.
However, Packt Publishing cannot guarantee the accuracy of this information.
ISBN 978-1-78588-237-1
www.packtpub.com
Credits
Reviewer Proofreader
Marco Scala Safis Editing
Copy Editor
Trishya Hajare
About the Author
Kyle Smith is a self-proclaimed geek and has been working with Splunk
extensively since 2010. He enjoys integrating Splunk with new sources of data and
types of visualization. He has spoken numerous times at the Splunk User Conference
(most recently in 2014 on Lesser Known Search Commands) and is an active contributor
to the Splunk Answers community and also to the #splunk IRC channel. He was
awarded membership into the SplunkTrust as a founding member. He has published
several Splunk Apps and add-ons to Splunkbase, the Splunk community's premier
Apps and add-ons platform. He has worked in both higher education and private
industry; he is currently working as an integration developer for Splunk's longest
running professional services partner. He lives in central Pennsylvania with
his family.
I'd like to thank my wife who most graciously put up with all
my BS during the writing of this book. Without her, this effort is
meaningless.
About the Reviewer
Marco Scala has been working for more than 15 years delivering solutions to large
enterprise customers, first in the APM and J2EE fields and, since 2009, in the fields
of operational intelligence and Splunk. He has provided consultancy for big Splunk
installations for major customers, focusing on the best and most effective solutions
for each different customer's needs. Since 2012, he's also a certified Splunk trainer.
In the last few years, Marco's major focus has been to get Splunk customers to
gain the maximum value from their IT data and provide the business a better view
and insight. Big Data is another major field of interest, and his next challenge is
using Splunk to give customers useful insights and a practical implementation and
exploitation of Big Data.
www.PacktPub.com
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files
available? You can upgrade to the eBook version at www.PacktPub.com and as a print book
customer, you are entitled to a discount on the eBook copy. Get in touch with us at service@
packtpub.com for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range
of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
TM
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library.
Here, you can search, access, and read Packt's entire library of books.
Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser
[i]
Table of Contents
metadata 19
static 20
Application data 20
Indexes 20
Source types 23
Sources 23
Available Splunk knowledge objects 23
Macros 24
Event types 24
Tags 25
Saved searches 25
Dashboards 26
Lookups 26
Configurations 27
Object permissions 27
The setup screen 29
The endpoint 30
The setup file 31
Summary 32
Chapter 3: Enhancing Applications 33
Workflows 33
Custom alert actions 37
Enriched data 39
Event types 39
Tags 44
Macros 46
Lookups 48
Common Information Model 53
Branding your App 53
Logos 54
Navigation 56
CSS 58
JavaScript 58
Acceleration 58
Summary indexing 58
Accelerated reports 60
Summary 61
[ ii ]
Table of Contents
[ iii ]
Table of Contents
[ iv ]
Preface
Splunk is awesome. Not only can you consume virtually any data with it, you can
also extend and integrate Splunk with virtually any external system. Splunk uses sets
of configurations that are referred to as applications or add-ons, which is the primary
focus of this book. Leveraging these applications and add-ons is what gives Splunk
its unique ability to extend, learn, analyze, and visualize information.
Splunk helps users to determine the root cause of a failure, a quick overview of
system health, and dive deep into SQL statements and messages, just to name a
few. The aggregation and centralization of log and event management is a growing
trend in the Big Data space. By leveraging the combined intelligence gathered
from correlating disparate sets of data, businesses or individuals can make
data-based decisions. This book will help a Splunk developer, or even just a
curious end user, to develop different methods of consuming new data, design
new types of visualization, or even just offer tips and tricks that help the software
development lifecycle.
[v]
Preface
Splunk basics will not be covered. These include concepts such as searching (finding
data, using timecharts, stats, some eval commands, and so on), reporting (making
basic pie charts or line charts via the GUI), data inputs (basic file monitoring, TCP
and UDP inputs, Splunk forwarders, and so on), and configurations (GUI and web-
based configuration editing), to name a few. Creating dashboards via the GUI?
Nope. Python will be discussed and sample code will be provided, but this book will
not cover the nuances of the code, nor will it teach you Python syntax. We will not
cover statistical computation, other than how to practically apply some basic math
to create value-based visualizations. We will not cover using the SDKs (software
development kits) being used in custom Splunk applications that are external to
Splunk (for example, Angular, PHP, .NET, and others). These are out of the scope of
this book. Free as in beer? Nope, the choice of hops, starch, and oak-barrel aging for
the creation of beer will not be discussed, but rather consumed during the writing
and/or reading of this book.
Unless otherwise stated, this book uses Splunk version 6.3 as the
development environment.
Assumptions
There are a few basic assumptions that we are going to make. Having purchased or
otherwise obtained this book, we assume that you are interested in developing with
Splunk, and have a basic understanding of Splunk and how to navigate around the
software. Knowledge of saving searches, reports, and basic dashboarding is a must,
since most concepts and examples will be built upon the basics. We also assume
that you have basic knowledge of HTML, CSS, JS, and some XML. Here, XML will
be limited to the Splunk XML framework specifically. We would also recommend
you to have knowledge of, or proficiency in, Python, RequireJS, and other web
technologies such as Bower, npm, and Gulp. We will demonstrate how to use these
web technologies within a Splunk application.
[ vi ]
Preface
Chapter 2, Creating Applications, discusses the basic methods of App and add-on
creation, along with an explanation of the structure of an App or add-on.
Chapter 4, Basic Views and Dashboards, goes through the basics of SimpleXML
dashboard creation and development.
Chapter 5, The Splunk Web Framework, details the various SplunkJS Stack components
and shows examples of how to use them within an HTML dashboard.
Chapter 7, Packaging Applications, lists the items needed to package an App or add-on,
in order to get it ready for publishing.
°° Python
°° JavaScript
°° HTML
°° CSS
[ vii ]
Preface
Conventions
In this book, you will find a number of text styles that distinguish between different
kinds of information. Here are some examples of these styles and an explanation of
their meaning.
Code words in text, database table names, folder names, filenames, file extensions,
pathnames, dummy URLs, user input, and Twitter handles are shown as follows:
"Copy the file to $SPLUNK_HOME/etc/apps."
New terms and important words are shown in bold. Words that you see on the
screen, for example, in menus or dialog boxes, appear in the text like this: "Simply
click on the Browse button."
[ viii ]
Preface
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or disliked. Reader feedback is important for us as it helps
us develop titles that you will really get the most out of.
If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to
help you to get the most from your purchase.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you could report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/submit-errata, selecting your book, clicking on the Errata Submission Form
link, and entering the details of your errata. Once your errata are verified, your
submission will be accepted and the errata will be uploaded to our website or added
to any list of existing errata under the Errata section of that title.
[ ix ]
Preface
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all
media. At Packt, we take the protection of our copyright and licenses very seriously.
If you come across any illegal copies of our works in any form on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.
We appreciate your help in protecting our authors and our ability to bring you
valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at
questions@packtpub.com, and we will do our best to address the problem.
[x]
Application Design
Fundamentals
Hello there, Splunk developer! If you are like us, we know you have a love of Splunk
and all of the endless possibilities that present themselves! The Big Data world is
exploding around us, and it always feels like a tireless battle when keeping up to
date with advances in technologies, platforms, and concepts. Here, we will discuss
none of those. This book is dedicated solely to Splunk and the development of
applications for Splunk. Onward and upward!
[1]
Application Design Fundamentals
Why applications?
Applications allow us to quickly share configurations, focus on the context of
available data, limit data access to specific individuals or groups, and organize
similar dashboards and views into a cohesive presentation of data within Splunk.
Sharing applications can be as easy as just zipping it up and sending it out. Splunk
applications could be said to be open source, due to the fact that almost all of the
configurations, custom scripts, and any other knowledge object contained within
the applications, are readable on the filesystem. This allows for customization for an
individual instance while maintaining an overall master configuration.
Definitions
To get started, we should define a few naming conventions typically used when
naming applications. Note that while we will use these naming conventions as
the best practice, your application can really be named anything at all, which
may conflict with other applications of the same name, or violate Splunk usage
agreements or publishing guidelines. In particular, the name Splunk cannot be
present in your application or add-on name. Additionally, in the past, Splunk has
referred to add-ons as technology add-ons, and has since moved to just add-ons.
The following list of add-on types is our way to distinguish the different uses
of each add-on:
[2]
Chapter 1
• Supporting add-ons (SA): Supporting add-ons are also not full applications;
these contain data definitions, such as macros, saved searches, event types,
and tags. These describe how to correlate the data, normalize the data, and
consolidate the data to be usable in the domain add-on.
• Technology add-ons (TA): Technology add-ons provide extraction, data
massage, and index-time configurations. These can also be referred to as
technical add-ons. These contain the configuration options required to
properly break events, extract search fields, and create timestamps, among
other functions. These are the building blocks for the SA and DA add-ons,
as well as full-blown applications.
Thus end the official naming conventions as normally seen in a Splunk installation.
We will now discuss some other naming conventions that have been found to help in
the wild west of various Splunk installations. These two naming conventions are of
the author's own design, which have helped in some of his deployments:
• Input add-ons (IA): Input add-ons are just that—configurations that assist
in the collection of data, known as inputs. These add-ons are most likely
found on a deployment server and are used to collect data from universal
forwarders. One of the advantages to splitting your IAs from your TAs is
a reduced size in the add-on being sent to the universal forwarder. This
is especially useful if your TA contains lookups that aren't needed on the
universal forwarder but are several megabytes in size.
• Admin add-ons (ADMIN): This add-on is a very special add-on. It would
typically contain administrative configurations that might be needed in a
variety of locations. Such configurations could be the web server SSL port,
deployment client information, or anything in web.conf or server.conf
format. It can be used to send index information to a set of non-clustered
indexers, or possibly to scale the addition of more search heads by setting
all relevant settings from a central location.
[3]
Application Design Fundamentals
While this may not be a complete list of naming conventions, it should be enough
to recognize any that are seen in the wild. An additional aspect of the naming
conventions that we recommend is the addition of company information. This will
help your Splunk admins differentiate between Splunk add-ons and custom add-ons.
Just as an example, let's say you built a TA for Cisco, specific to your company (the
ACME company). Splunk's provided add-on is entitled TA-cisco, but you don't want
to modify a vendor's offering. So, your new add-on's name could be A-ACME-TA-
cisco. This gives you two things: an easy-to-see custom TA that relates to Cisco and
the ability to override any TA-cisco settings based on application precedence.
Let's discuss application precedence for a moment. Splunk uses a merged configuration
when applying configurations that are installed via the applications. The
methodology that Splunk chose to implement conflict resolution is pretty simple.
There are two different methods of precedence. The first is directory structure. If you
have an input located in the default folder of an application (more on default in
the later chapters), you can place a matching configuration in the local folder of the
application to override the default configuration. The same method is applied to
the applications themselves. Splunk uses the ASCII values of the names to determine
precedence. On *nix, you can sort the applications in the apps folder of Splunk using
the LC_COLLATE=C ls command. This will show you the ASCII-sorted order of the
applications, and the first in the list will be highest priority. A has a higher priority
than Z, but Z has a higher priority than a. So, the A at the beginning of the add-on
name gives your add-on the highest precedence, so you can override any setting
as needed.
[4]
Chapter 1
These questions can help you spark an idea of what internal resources would need to
be engaged, as well as any kind of documentation and educational requirements.
There is a lot of data out in the wild, but not all of it may be relevant to your use case.
You may find that of a service that has 100 endpoints available for data collection,
you only need 10. Not only will you save on license usage, but your indexers will
thank you for it as well.
[5]
Application Design Fundamentals
There are so many options available to brand your App, but all customizations
should conform to the Splunk branding guidelines for developers. Visit http://
www.splunk.com/view/SP-CAAAFT9 to read through Splunk's guidelines.
[6]
Chapter 1
Such a small list of questions hardly precludes any other relevant discussion within
your organization. The more internal discussion that can take place, the better and
more thought-out your App may turn out.
Installing Apps
As a Splunk developer, you should be aware of the three methods to install Apps.
There are advantages and disadvantages to each method, but no required method.
It is mostly personal preference as to which method is used by the end user, but,
typically, newer Splunk users will use the Web interface, while advanced users
will use the command line. Let's review those methods, just to keep them fresh in
your mind.
Splunk Web
Installing Apps via Splunk Web is simple. Once you have downloaded the App from
its source, you navigate to the Manage Apps section of Splunk. You will find this at
the top-left of Splunk Web, as shown in the following screenshot:
Once you have clicked on Manage Apps, you will see a button to install the app
from a file. You can also browse the Splunk App store, using the first button:
[7]
Application Design Fundamentals
This brings you to a form that you can use to actually install the App. Simply click on
the Browse button, select the file you downloaded, check the Upgrade button if this
App has already been installed, and then click on Upload. That's it! Splunk takes the
App, installs it, and prompts to restart if needed:
1. Copy the App file (either a *.tgz or *.spl file) to the filesystem.
2. Run the ./bin/splunk install app <path_to_file> command.
Splunk will install the App. You may be prompted to restart, depending on the
contents of the App. Index-time configurations require a restart, whereas search-time
configurations do not.
[8]
Chapter 1
Summary
In this chapter, we covered the basic fundamentals of designing and installing
Splunk Apps. Apps can be broken down into domains, each with a naming
convention that allows you to quickly determine what the App can do, and what is
contained within it, so that new users to your environment don't have to look for
configurations. We learned how to approach App design to make sure that the App
is planned beforehand, which will eliminate the need to refactor major portions of
the App later, when it may already be in production. We also went over the three
different methodologies available to install Apps to give a basic understanding of
user experience related to the installation of any App you may build.
Now that you've acquired an understanding of what an App consists of, in the
coming chapters, we will discuss creating, enhancing, and customizing them.
[9]
Creating Applications
In this chapter, we will begin covering how to build an actual application. There are
many different ways to create an App, ranging from GUI creation to manual editing
of configuration files. We will cover the structure of an application, what each folder
should contain within the application, and why this is important. Another aspect
that will be touched on will be the data that your application will consume. Setting
up the data structures beforehand may save you time and energy later on if you have
to refactor. It is crucial to get the data in correctly the first time, as any subsequent
release of your app will need to make use of the data. We will cover various methods
for data consumption, as well as the types of Splunk knowledge objects that can be
included in your application. Restricting access to your application may be a priority,
so we will also cover metadata and object permissions. Getting your application
installed may require your end user to perform some additional configuration before
it can be used, so we will review how to configure the setup screen as well.
A brief clarification
As we continue to progress through this book, we will create an App from the
ground up. The App's name is SDG (from a filesystem perspective) and the App label
will be Developer's Guide for Splunk. It will be available in its entirety on Splunkbase
at https://splunkbase.splunk.com/app/2693/. Additionally, we will be using
an API provided by meh.com, a daily deal site that was kind enough to build an API
to their website. They were chosen primarily because they fit the geek culture pretty
well, and provide a very simple-to-consume API. The data that will be consumed is
pulled from their website's API using scripted inputs located in the bin folder of the
sample SDG application.
[ 11 ]
Creating Applications
Let's recall the questions from Chapter 1, Application Design Fundamentals, that revolve
around App creation. We should answer some of them in preparation for building
our demo App:
Now that we have answered some preliminary questions, we are ready to begin
creating our App. We can clearly see what is needed at the very basic level, and can
continue to add to the specification as we go ahead.
[ 12 ]
Exploring the Variety of Random
Documents with Different Content
entire Solar System but for some deep understanding on the part of
an alien culture.
He—Al Weston, psychoneurotic—in the position of being an
emissary!
He took the glass offered by Jasentor, lifted it to the four of them and
drained it with a gesture.
And for the first time in more than a year, the sound of Weston's
honest laughter filled the room.
Cured!
*** END OF THE PROJECT GUTENBERG EBOOK QUEST TO
CENTAURUS ***
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the terms
of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth in
paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com