Use stats with eval expressions and functions (2024)

You can embed eval expressions and functions within any of the stats functions. This is a shorthand method for creating a search without using the eval command separately from the stats command.

For example, the following search uses the eval command to filter for a specific error code. Then the stats function is used to count the distinct IP addresses.

status=* | eval dc_ip_errors=if(status=404,clientip,NULL()) | stats dc(dc_ip_errors)

As an alternative, you can embed an eval expression using eval functions in a stats function directly to return the same results. For example:

status=* | stats dc(eval(if(status=404, clientip, NULL()))) AS dc_ip_errors

Use eval expressions to count the different types of requests against each Web server

This example uses the sample data from the Search Tutorial but should work with any format of Apache web access log. To try this example on your own Splunk instance, you must download the sample data and follow the instructions to get the tutorial data into Splunk. Use the time range All time when you run the search.

Run the following search to use the stats command to determine the number of different page requests, GET and POST, that occurred for each Web server.

sourcetype=access_* | stats count(eval(method="GET")) AS GET, count(eval(method="POST")) AS POST BY host

This example uses eval expressions to specify the different field values for the stats command to count.

  • The first clause uses the count() function to count the Web access events that contain the method field value GET. Then, using the AS keyword, the field that represents these results is renamed GET.
  • The second clause does the same for POST events.
  • The counts of both types of events are then separated by the web server, using the BY clause with the host field.

The results appear on the Statistics tab and look something like this:

hostGETPOST
www184315197
www280974815
www383384654

Use eval expressions to categorize and count fields

This example uses sample email data. You should be able to run this search on any email data by replacing the sourcetype=cisco:esa with the sourcetype value and the mailfrom field with email address field name in your data. For example, the email might be To, From, or Cc).

Find out how much of the email in your organization comes from .com, .net, .org or other top level domains.

The eval command in this search contains two expressions, separated by a comma.

sourcetype="cisco:esa" mailfrom=* | eval accountname=split(mailfrom,"@"), from_domain=mvindex(accountname,-1) | stats count(eval(match(from_domain, "[^\n\r\s]+\.com"))) AS ".com", count(eval(match(from_domain, "[^\n\r\s]+\.net"))) AS ".net", count(eval(match(from_domain, "[^\n\r\s]+\.org"))) AS ".org", count(eval(NOT match(from_domain, "[^\n\r\s]+\.(com|net|org)"))) AS "other"

  • The first part of this search uses the eval command to break up the email address in the mailfrom field. The from_domain is defined as the portion of the mailfrom field after the @ symbol.
    • The split() function is used to break the mailfrom field into a multivalue field called accountname. The first value of accountname is everything before the "@" symbol, and the second value is everything after.
    • The mvindex() function is used to set from_domain to the second value in the multivalue field accountname.
  • The results are then piped into the stats command. The stats count() function is used to count the results of the eval expression.
  • Theeval eexpression uses the match() function to compare the from_domain to a regular expression that looks for the different suffixes in the domain. If the value of from_domain matches the regular expression, the count is updated for each suffix, .com, .net, and .org. Other domain suffixes are counted as other.

The results appear on the Statistics tab and look something like this:

.com.net.orgother
4246989003543

See also

Commands
eval command in the Search Reference
Related information
Statistical and charting functions in the Search Reference
Evaluation functions in the Search Reference
About evaluating and manipulating fields
Use stats with eval expressions and functions (2024)
Top Articles
Refinery - Space Engineers Wiki
Instructional Support Specialist III-Special Education PAF#1250903 at El Monte City School District
Kmart near me - Perth, WA
I Make $36,000 a Year, How Much House Can I Afford | SoFi
Live Basketball Scores Flashscore
Hk Jockey Club Result
Activities and Experiments to Explore Photosynthesis in the Classroom - Project Learning Tree
Top 10: Die besten italienischen Restaurants in Wien - Falstaff
Sissy Transformation Guide | Venus Sissy Training
P2P4U Net Soccer
Marist Dining Hall Menu
Nation Hearing Near Me
Magic Mike's Last Dance Showtimes Near Marcus Cedar Creek Cinema
What is IXL and How Does it Work?
Lost Pizza Nutrition
Craigslist Estate Sales Tucson
Power Outage Map Albany Ny
Jasmine Put A Ring On It Age
Industry Talk: Im Gespräch mit den Machern von Magicseaweed
2016 Ford Fusion Belt Diagram
Webcentral Cuny
Ally Joann
Craigslist Southern Oregon Coast
Kirksey's Mortuary - Birmingham - Alabama - Funeral Homes | Tribute Archive
Drift Boss 911
Theater X Orange Heights Florida
Bennington County Criminal Court Calendar
Jobs Hiring Near Me Part Time For 15 Year Olds
Jeff Nippard Push Pull Program Pdf
The Banshees Of Inisherin Showtimes Near Broadway Metro
Temu Seat Covers
Marlene2995 Pagina Azul
Keshi with Mac Ayres and Starfall (Rescheduled from 11/1/2024) (POSTPONED) Tickets Thu, Nov 1, 2029 8:00 pm at Pechanga Arena - San Diego in San Diego, CA
John Philip Sousa Foundation
HP PARTSURFER - spare part search portal
Gyeon Jahee
Pickle Juiced 1234
Texas Baseball Officially Releases 2023 Schedule
Unlock The Secrets Of "Skip The Game" Greensboro North Carolina
Andhra Jyothi Telugu News Paper
Google Chrome-webbrowser
Craigslist Tulsa Ok Farm And Garden
Doordash Promo Code Generator
Anhedönia Last Name Origin
Weather Underground Cedar Rapids
Traumasoft Butler
Nami Op.gg
Penny Paws San Antonio Photos
Air Sculpt Houston
Bonecrusher Upgrade Rs3
Hughie Francis Foley – Marinermath
Rétrospective 2023 : une année culturelle de renaissances et de mutations
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6046

Rating: 4.1 / 5 (72 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.