1 Splunk Power User Flash Cards
Splunk Power User Flashcards(Own)
1. eval command
• Calculations, Convert values, Round values, Format Values , Conditional
statements.
• eval field_name=expression
• Results of eval
...
1 Splunk Power User Flash Cards
Splunk Power User Flashcards(Own)
1. eval command
• Calculations, Convert values, Round values, Format Values , Conditional
statements.
• eval field_name=expression
• Results of eval written to either new or existing field you specify
• If the destination field exists, the values of the field are replaced by the
results of eval
• Indexed data is not modified, and no new data is written into the index
• Field values are treated in a case-sensitive manner
eval round Function
• round(field/number, decimals) function sets the value of a field to the
number of decimals you specify
• If the number of decimals is unspecified, the result is a whole number
eval tostring function
• tostring(field,”option”)
• “commas” – applies commas – If the number includes decimals, it rounds
to two decimal places
• “duration” – formats the number as “hh:mm:ss”
• “hex” – formats the number in hexadecimal
eval if function
• if(boolean,”true”,”false”)
• Non-numeric values must be enclosed in "double quotes"
• Field values are treated in a case-sensitive manner
eval lower function
• lower(field_name)
eval concatenate function
• eval full_name=”first_name”.”last_name”
Multiple eval functions:
• eval full_name=”first_name”.”last_name”, low_name = lower(full_name)
Multiple eval commands
Each subsequent command references the results of previous commands
eval Command –case Function
case(X1,Y1,X2,Y2…)
• The first argument, X1, is a Boolean expression
• If it evaluates to TRUE, the result evaluates to Y1
• If it evaluates to FALSE, the next Boolean expression, X2, is evaluated, etc.
• If you want an “otherwise” clause, just test for a condition you know is true at
the end (e.g., 0=0)
eval function
2 Splunk Power User Flash Cards
• To count the number of events that contain a specific field value, use the
count and eval functions
–Used within a transforming command, such as stats
–Requires an as clause
–Double quotes are required for character field values
–Field values are case-sensitive
2. Filtering Results – search and where
The search and where commands can be used at any point in the search pipeline
to filter results.
–search
May be easier if you’re familiar with basic search syntax
Treats field values in a case-insensitive manner
Allows searching on keyword
–where
Can compare values from two different fields
Functions are available, such as isnotnull ()
Field values are case-sensitive
search Command
• To filter results, use search at any point in the search pipeline
• Behaves exactly like search strings before the first pipe
–Uses the "*" wildcard
–Treats field values in a case-insensitive manner
where command
where eval – expression
• Uses same expression syntax as eval command
• Uses boolean expressions to filter search results and only keeps results that are
True
• Double quoted strings are interpreted as field values
–Treats field values in a case-sensitive manner
• Unquoted or single-quoted strings are treated as fields
where Command -Example
• Filters search results using eval expressions
• Used to compare two different fields
where Command With like Operator
• Can do wildcard searches with where command
• Use (_) for one characte r and (%) for multiple characters
• Must use the like operator with wildcards
3 Splunk Power User Flash Cards
fillnull command
• Use fillnull to replace null values in fields
• Use value=string to specify string you want displayed instead
Example: fillnull value=NULL
• If no value=clause, default replacement value is 0
• Optionally, restrict which field(s) fillnull applies to by listing them at end of
command
fillnull value=”Unknown” City, Country
replace “” with “Unknown” in City, Country
3. transaction command
• A transaction is any group of related events that span time
• Events can come from multiple applications or hosts
• transaction field-list
• field-list can be one field name or a list of field names
• Events are grouped into transactions based on the values of these fields
• –If multiple fields are specified and a relationship exists between those
fields, events with related field values will be grouped into a single
transaction
• Common constraints:
• maxspan maxpause startswith endswith
• –search uses the "*" wildcard and treats field values in a case-insensitive
manner
• –status=404 finds the errors
• –highlight highlights the terms you specify
index=main sourcetype=access_combined
| transaction JSESSIONID
| search status=404
| highlight JSESSIONID, 404
transaction command – specific fields
• duration – the difference between the timestamps for the first and last
event in the transaction
• eventcount – the number of events in the transaction
• maxspan – Maximum total time between the earliest and latest events
• ▸If not specified, default is -1 (or no limit)
maxspan=10m
• maxpause – Maximum total time between events
• ▸If not specified, default is -1 (or no limit)
maxpause=1m
• startswith/endswith – To form transactions based on terms, field values,
or evaluations, use startswith and endswith options
4 Splunk Power User Flash Cards
startswith=”” , endswith=””
• Transactions can be useful when a single event does not provide enough
information
• You can use statistics and reporting commands with transactions
• Transactions spanning more than 10 minutes with the same client IP are
considered Unrelated
transaction vs. Stats
• Use transaction when you:
–Need to see events correlated together
–Must define event grouping based on start/end values or chunk on time
–Have fewer than 1,000 events for each correlated transaction
By default, transaction displays a maximum event count of 1,000
Admins can configure max_events_per_bucket in limits.conf
• Use stats when you:
–Want to see the results of a calculation
–Can group events based on a field value (e.g. "by src_ip")
–Have more than 1,000 events for each grouped set of events
• When you have a choice, always use stats as it is faster and more efficient,
especially in large Splunk environments
• __________ should be used when you want to see the results of a calculation,
or you need to group events on a field value. Stats
• __________ should be used when you need to see events correlated together,
or when events need to be grouped on start and end values.
Transaction
• This stats function will return unique values for a given field.
Value
• When using a .csv file for lookups, the first row in the file represents this.
Field names
4. Knowledge Objects
Knowledge objects are tools you use to discover and analyze various aspects of
your data
–Data interpretation – Fields and field extractions
–Data classification – Event types
–Data enrichment – Lookups and workflow actions
–Normalization – Tags and field aliases
–Datasets – Data models
•Shareable–Can be shared between users
•Reusable–Persistent objects that can be used by multiple people or apps, such
as macros and reports
•Searchable–Since the objects are persistent, they can be used in a search
What is a Knowledge Manager?
• Oversees knowledge object creation and usage for a group or deployment
• Normalizes event data
5 Splunk Power User Flash Cards
• Creates data models for Pivot users
Defining Naming Conventions
Group → Object Type → Description
Example: SEG_Alert_WinEventLogFailure
Permissions:
Description Create Read Write
Private The person who created
the object
User
Power
Admin
Person who
created it
Admin
Person who
created it
Admin
This App Only Object persists in a
specific app
Power
Admin
User*
Power*
Admin
User*
Power*
Admin
All Apps Available globally in all
apps
Admin User*
Power*
Admin
User*
Power*
Admin
* Permission to read and/or write if creator gives permission to that role
• When an object is created, the permissions are set to Keep private by default
• When an object’s permissions are set to This app only and All apps, all roles
are given read permission. Write permission is reserved for admin and the object
creator unless the creator edits permissions
• Only the admin role can promote an object to All apps
Managing Knowledge Objects
• Knowledge objects are centrally managed from Settings> Knowledge
• Your role and permissions determine your ability to modify an object’s
setting
• By default, objects of all owners are listed.
Using the Splunk Common Information Model (CIM)
• Methodology for normalizing data
• Easily correlate data from different sources and source types
• Leverage to create various objects discussed in this course—field extractions,
field aliases, event types, tags
• More details discussed in Module 13
6 Splunk Power User Flash Cards
5. Field Extractor Methods
1. Regex (Regular Expression)
2. Delimiters
The regular expression method works best with unstructured event
data. You select a sample event and highlight one or more fields to extract
from that event, and the field extractor generates a regular expression that
matches similar events in your dataset and extracts the fields from them.
The regular expression method provides several tools for testing and
refining the accuracy of the regular expression. It also allows you to
manually edit the regular expression.
The delimiters method is designed for structured event data: data from
files with headers, where all of the fields in the events are separated by a
common delimiter, such as a comma or space. You select a sample event,
identify the delimiter, and then rename the fields that the field extractor
finds. data that resides in a file that has headers and fields separated by
specific characters
Regular Expression Extraction Method:
select Sample → Select Method → Select Fields → Validate → Save
Delimiter Extraction
select Sample → Select Method →Rename Fields → Save
How to go to the Field Extractor:
1. Settings → Fields
2. Fields Sidebar
3. Event Actions
Field Auto-Extraction
• Splunk automatically discovers many fields based on source type and key/value
pairs found in the data
• Prior to search time, some fields are already stored with the event in the index:
–Meta fields, such as host , source , and sourcetype
–Internal fields such as _time and _raw
• At search time, field discovery discovers fields directly related to the search’s
results
• Splunk may also extract other fields from raw event data that aren’t directly
related to the search
Performing Field Extractions
• In addition to the many fields Splunk auto-extracts, you can also extract your
own fields with the Field Extractor (FX)
• Use FX to extract fields that are static and that you use often in searches
-Graphical UI
-Extract fields from events using regex or delimiter
-Extracted fields persist as knowledge objects
7 Splunk Power User Flash Cards
-Can be shared and re-used in multiple searches
• Access FX via Settings, Fields Sidebar, or Event Actions menu
Field Extraction Methods
• Regex
–Use this option when your event contains unstructured data like a system
log file
–FX attempts to extract fields using a Regular Expression that matches
similar events
• Delimiter
-Use this option when your event contains structured data like a .csv file
-The data doesn’t have headers and the fields must be separated by
delimiters (spaces, commas, pipes, tabs, or other characters)
Regex Field Extractions from Settings
Settings > Fields > Field extractions > Open Field Extractor
1.Select the Data Type
–sourcetype
–source
2.Select the Source Type
-access_combined
Regex Field Extractions from Settings –Select Sample
3.Select a sample event by clicking on it
4.Click Next >
Regex Field Extractions from Settings – Select Method
5.Select Regular Expression
6.Click Next>
Regex Field Extractions from Settings – Select Values
7.Select the value(s) you want to extract. In this example, two fields are being
extracted
8.Provide a field name
9.Click Add Extraction
Require Option: Only events with the highlighted string will be included in the
extraction.
Regex Field Extractions from Settings –Preview
10.Preview the sample events
11.Click Next
Regex Field Extractions from Settings –Validate
12.Validate the proper field values are extracted
13.Click Next
Regex Field Extractions from Settings –Save
14.Review the name for the newly extracted fields and set permissions
15.Click Finish
8 Splunk Power User Flash Cards
Note: An extractions name is provided by default. This name can be changed.
Using the Extracted Fields
index=main sourcetype=access_combined | table clientip gethome
Editing Regex for Field Extractions
1.From Select Method, click Regular Expression
2.Click Next >
Editing Regex for Field Extractions – Select Field
3.Select the field to extract
4.Provide a Field Name
5.Click Add Extraction
Editing Regex for Field Extractions – Show Regex
6.Click Show Regular Expression >
7.Click Edit the Regular Expression
Editing Regex for Field Extractions – Modify RegEx
8.Update the regular expression
9.Click Save
Warning: Once you edit the regular expression, you cannot go back to the
Field Extractor UI.
Editing Regex for Field Extractions – Save
10.Review the Extractions Name and set permissions
11.Click Finish
Delimited Field Extractions
• Use delimited field extractions when the event log does not have a header and
fields are separated by spaces, commas, or characters
• In this example, the fields are separated by commas
Field Extraction Workflows -Delimiters
Delimited Field Extractions from Settings
Settings > Fields > Field extractions > Open Field Extractor
Delimited Field Extractions (Settings) – Select Sample
1.Select the Data Type –sourcetype–source
2.Select the Source Type
Delimited Field Extractions (Settings) – Select Event
3.Select a sample event
9 Splunk Power User Flash Cards
4.Click Next >
Delimited Field Extractions (Settings) – Select Method
5.Select Delimiters
6.Click Next >
Delimited Field Extractions (Settings) – Select Delimiter
7. Select the Delimiter used in your event.
Delimited Field Extractions (Settings) – Rename Field
8.Click the icon next to the default field name
9.Enter a new field name
10.Click Rename Field
11.Repeat these steps for all fields
12.After all the fields are renamed, click Next >
Delimited Field Extractions (Settings) – Save
13.Review the name for your extraction and click Finish >
Using a Delimited Field Extraction
• Use the rex command to either extract fields using regular expression
named groups, or replace or substitute characters in a field using sed
expressions
6. Field Aliases
• A way to normalize data over any default field (host, source or sourcetype)
• Multiple aliases can be applied to one field
• Applied after field extractions, before lookups
• Can apply field aliases to lookups
Creating a Field Alias
Settings > Fields > Field Aliases > New
• A new field alias is required for each sourcetype
Testing the Field Alias
After the field alias is created, perform a search using the new field alias.
field_aliases=field_value
Field Alias and Original Fields
• When you create a field alias, the original field is not affected
• Both fields appear in the All Fields and Interesting Fields lists, if they appear in at
least 20% of events
Field Aliases and Lookups
After you have defined your field aliases, you can reference them in a lookup table
10 Splunk Power User Flash Cards
What is a Calculated Field?
• Shortcut for performing repetitive, long, or complex transformations using the
eval command
• Must be based on an extracted field
–Output fields from a lookup table or fields/columns generated from
within a search string are not supported
Calculated fields are fields added to events at search time that perform
calculations with the values of two or more fields already present in those events.
The eval command enables you to write an expression that uses extracted fields
and creates a new field that takes the value that is the result of that expression's
evaluation
Calculated fields enable you to define fields with eval expressions. When writing a
search, you can cut out the eval expression and reference the field like any other
extracted field. The fields are extracted at search time and added to events that
include the fields in the eval expressions.
Calculated Fields will perform some calculation taking one or more existing fields
of the events. These fields can be used in future instead of writing eval command.
Suppose you are performing a complex or long eval expression on regular basis, it
will be difficult to write that eval expression everyday. So rather than that you can
use a Calculated Fields instead of writing that eval expression.
You can create a new Calculated Field by taking the existing fields of events or
you can override an existing field of events by a Calculated Field.
In Search, just write the name of the calculated field.
Creating a Calculated Field
Settings > Fields > Calculated Fields > New
1. Select the app that will use the calculated field
2. Select host, source, or sourcetype to apply to the calculated field and specify
the related name
3. Name the calculated field
4. Define the eval expression
7. Describing Tags
• Tags are like nicknames that you create for related field/value pairs
• Tags make your data more understandable and less ambiguous
• You can create one or more tags for any field/value combination
• Tags are case sensitive tag=value (both tag names and value are case sensitive)
Viewing Tags
When tagged field/value pairs are selected, the tags appear:
A. In the results as tags
B. In parentheses next to the associated field/value pairs
11 Splunk Power User Flash Cards
Using Tags
To use tags in a search, use the syntax: tag=
Searching for Tags
• To search for a tag associated with a value:
–tag=
• To search for a tag associated with a value on a specific field:
–tag::=
• To search for a tag using a partial field value:
–Use (*) wildcard
Adding/Changing the Tag Name
Click List by field value pair to add another tag or change the name of the tag
Adding/Changing the Field Value Pair
Click List by tag name to add or edit the field value pair for the tag
8. Describing Event Types
• A method of categorizing events based on a search
• A useful method for institutional knowledge capturing and sharing
• Can be tagged to group similar types of events
Creating an Event Type from the Search Page
1.Run a search and verify that all results meet your event type criteria
2.From the Save As menu, select Event Type
3.Provide a name for your event type (name should not contain space).
Using the Event Type Builder
1.From the event details, select Event Actions > Build Event Type
2.Refine the criteria for your event type such as:
•Search string
•Field values
•Tags
3.Verify your selections and click Save
Using Event Types
• To verify the event type, search for eventtype=web_error
• ‘eventtype’ displays in the Fields sidebar and can be added as a selected field
12 Splunk Power User Flash Cards
• Splunk evaluates the events and applies the appropriate event types at search
time
• Using the Fields sidebar, you can easily view the individual event types, the
number of events, and percentage.
• Eventtype allows you to categorize events based on search terms.
•
Tagging Event Types
You can tag event types two ways:
1.Settings > Event Types
2.Event details > Actions
Event Types vs. Saved Reports
• Event Types
–Categorize events based on a search string
–Tag event types to organize data into categories
–The eventtype field can be included in a search string
–Does not include a time range
• Saved Reports
–Search criteria will not change
–Includes a time range and formatting of the results
–Can be shared with Splunk users and added to dashboards
9. Macros Overview
• Useful when you frequently run searches or reports with similar search syntax
• The time range is selected at search time
• Macros can be a full search string or a portion of a search that can be reused in
multiple places
• Allows you to define one or more arguments within search segment
–Pass parameter values to macro at execution time
–Macro uses values to resolve search string
Settings → Advanced Search → Search Macros
• Test your search string before saving your macro. You can check the
contents of your macro with keyboard shortcuts (Command-Shift-E on MAC
or Ctrl-Shift-E on Linux or Windows) from the search bar in the Search Page
Creating a Basic Macro
Settings > Advanced search > Search Macros
1.Click New
2.Select the destination app
3.Enter a name
4.Type the search string
5.Save
Using a Basic Macro
13 Splunk Power User Flash Cards
• Type the macro name into the search bar
• Surround the macro name with the backtick (or grave accent)character
-`macroname` != ‘macroname’
-Do not confuse with single-quote character (‘)
• Pipe to more commands, or precede with search string
Adding Arguments
• Include the number of arguments in parentheses after the macro name
-monthly_sales(3)
• Within the search definition, use $arg$
-currency=$currency$
-symbol=$symbol$
-rate=$rate$
• In the Arguments field, enter the name of the argument(s)
• Provide one or more variables of the macro at search time
Using Arguments
• When using a macro with arguments, include the argument(s) in parentheses
following the macro name
• Be sure to pass in the arguments in the same order as you defined them
Argument names may only contain alphanumeric, '_' and '-' characters.
Validating Macros
• You can validate the argument values in your macro
–Validation Expression
You can enter an expression for each argument (Eval or boolean
expression)
–Validation Error Message
Message that appears when you run the macro
Note: Don’t create macros with leading pipes – someone may put a pipe
in front of the macro when using it in the actual search string.
10. Creating and using Workflow Actions
What are Workflow Actions?
14 Splunk Power User Flash Cards
• Execute workflow actions from an event in your search results to interact with
external resources or run another search
–GET – pass information to an external web resource
–POST – send field values to an external resource
–Search- use field values to perform a secondary search
• Workflow names without space or special characters.
• Specify a comma-separated list of fields that must be present in an event
for the workflow action to apply to it.
• When fields are specified, the workflow action only appears in the field
menus for those fields; otherwise it appears in all field menus.
Creating a GET Workflow Action
Settings > Fields > Workflow actions > New
1.Select the app
2.Name the workflow action with no spaces or special characters
3.Define the label, which will appear in the Event Action menu
4.Determine if your workflow action applies to a field or event type
5. From the Show action in drop down list, select Event menu
6. Select link as the Action type
7. Enter the URI of where the user will be directed
8. Specify if the link should open in a New window or Current window
9. Select the Link method of get
10.Save
Creating a Post Workflow Action
Settings > Fields > Workflow actions > New
Complete steps 1 – 6 as described in the previous example, Creating a GET
Workflow Action
11.Creating Data Models
Reviewing Pivot
• Used for creating reports and dashboards
Overview of Data Models
• Hierarchically structured datasets that generate searches and drive Pivot
–Pivot reports are created based on datasets
–Each event, search or transaction is saved as a separate dataset
Data Model Dataset Types
• Data models consist of 3 types of datasets
1.Events
2.Searches
3.Transactions
Data Model Events
•Event datasets contain constraints and fields
•Constraints are essentially the search broken down into a hierarchy
15 Splunk Power User Flash Cards
•Fields are properties associated with the events
Dataset Fields
• Select the fields you want to include in the dataset
• Like constraints, fields are inherited from parent objects
•Auto-Extracted – can be default fields or manually extracted fields
•Eval Expression – a new field based on an expression that you define
•Lookup – leverage an existing lookup table
•Regular Expression – extract a new field based on regex
•Geo IP – add geographical fields such as latitude/longitude, country, etc
Data Model Search Datasets
• Arbitrary searches that include transforming commands to define the dataset
that they represent
• Search datasets can also have fields, which are added via the Add Field button
Data Model Transaction Datasets
• Enable the creation of datasets that represent transactions
• Use fields that have already been added to the model using event or search
datasets
Search and Transaction Dataset Considerations
•There must be at least one event or search dataset before adding a transaction
dataset
• Search and Transaction datasets cannot benefit from persistent data model
acceleration
–Acceleration is discussed later in the module
• Think carefully about the reports your users will run
–Can the same report be achieved with event datasets?
• As you learn to create data models, consider the types of reports your users will
run
–Will they need raw events or transactional data?
Adding a Root Event
The Inherited attributes are default fields
• Use Add Field > Auto-Extracted to add more fields
Adding Fields –Auto-Extracted
Fields that already exist for the constraint can be added as attributes to the data
model.
Field Types
•String: Field values are recognized as alpha-numeric
•Number: Field values are recognized as numeric
•Boolean: Field values are recognized as true/false or 1/0
16 Splunk Power User Flash Cards
•IPV4: Field values are recognized as IP addresses–This is an important field type,
as at least one IPV4 attribute type must be present in the data model in order to
add a Geo IP attribute
Field Flags
•Optional: This field doesn't have to appear in every event
•Required: Only events that contain this field are returned in Pivot
•Hidden: This field is not displayed to Pivot users when they select the dataset in
Pivot
–Use for fields that are only being used to define another field, such as an
eval expression
•Hidden & Required: Only events that contain this field are returned, and the
fields are hidden from use in Pivot
Adding Fields –Eval Expressions
• You can define a new field using an eval expression
–In this example, you create a field named Error Reason that evaluates
the value of the status field
Adding Fields –Lookups
• Leverage an existing lookup definition to add fields to your event object
• Configure the lookup attribute in the same way as an automatic lookup
• Use Preview to test your lookup settings
• Use the Events and Values tab to verify your results
Adding Fields –Regular Expression
You can define a new field using a regular expression
Adding Fields -GeoIP
• Map visualizations require latitude/longitude fields
• To use Geo IP Lookup, at least one IP field must be configured as an IPv4 type
• While the map function isn't available in Pivot, the data model can be called
using the
| pivot command and
[Show More]