Security

Browser Usage Statistics

mapugh73
Engager

Hello Splunkers,

I am new to Splunk and I'm having a hard time generating what should be a simple report. I'd like to produce a pie chart that shows browser usage by major browser (IE, Firefox, Chrome, Safari, etc.).

I started with the following mess of a query, but it doesn't give me "chartable" results:

sourcetype="access" useragent!="-"
AND useragent!="Apache*"
AND useragent!="Load-weight*"
AND useragent!="Java*"
AND useragent!="Jakarta Commons-HttpClient*"
AND useragent!="Mozilla/4.0 en"
| table SessionCookie, useragent
| dedup SessionCookie
| stats
count(eval(match(useragent, "Firefox"))) as "Firefox",
count(eval(match(useragent, "Chrome"))) as "Chrome",
count(eval(match(useragent, "Safari"))) as "Safari",
count(eval(match(useragent, "MSIE"))) as "IE",
count(eval(NOT match(useragent, "Chrome|Firefox|Safari|MSIE"))) as "Other"

Does anyone have an example query that could get me to my pie chart?

Thanks,
Mark

Tags (2)
0 Karma

totalnet32
New Member

,did anyone get this to work?
Regex: syntax error in subpattern name (missing terminator)

0 Karma

joshd
Builder

If you're copying/pasting the search I posted and answer for back in 2011 then the HTML chars in the regex are breaking it (dont know why those are there)... but also note there are addons and custom commands people have developed since there that are a bit more detailed/flexible than this post was...

If you want to use this search then it should be like this:

index=access_logs
 | fields + user_agent
 | rex field=user_agent "((?<browser_ff>Firefox\S+)|(?<browser_ie>MSIE [\d\.]+)|(?<browser_opera>Opera)|(?<browser_chrome>Chrome)|(?<browser_safari>Safari)|(?<browser_java>Java\S+)|(?<browser_nagios>nagios\S+)|(?<browser_nessus>[Nn][Ee][Ss][Ss][Uu][Ss])|(?<browser_apache>Apache\S+))"
 | eval browser_none=if(user_agent=="-","None","")
 | fillnull value="" browser_ff browser_ie browser_chrome browser_safari browser_opera browser_java browser_nagios browser_nessus broswer_none browser_apache
 | eval browser = browser_ff.browser_ie.browser_chrome.browser_safari.browser_opera.browser_java.browser_nagios.browser_nessus.browser_none.browser_apache
 | top 50 browser

richgalloway
SplunkTrust
SplunkTrust

This question is more than five years old. Please post a new question.

---
If this reply helps you, Karma would be appreciated.
0 Karma

Glenn
Builder

Justin Azoff has posted a very useful user agent translator script/custom splunk command here:

https://github.com/JustinAzoff/splunk-scripts/blob/master/ua2os.py

Translates the horrible useragent string into browser, os type and architecture. It works very well.

asarolkar
Builder

Hi. Did you ever get around to getting Splunk to run this python script ?

0 Karma

brettski
Explorer

I certainly like the looks of the script, I just have no idea what to do with it. Will you please assist?

0 Karma

joshd
Builder

I use a search like this to return the top 50 browsers:

index=access_logs
| fields + user_agent
| rex field=user_agent "((?&lt;browser_ff&gt;Firefox\S+)|(?&lt;browser_ie&gt;MSIE [\d\.]+)|(?&lt;browser_opera&gt;Opera)|(?&lt;browser_chrome&gt;Chrome)|(?&lt;browser_safari&gt;Safari)|(?&lt;browser_java&gt;Java\S+)|(?&lt;browser_nagios&gt;nagios\S+)|(?&lt;browser_nessus&gt;[Nn][Ee][Ss][Ss][Uu][Ss])|(?&lt;browser_apache&gt;Apache\S+))"
| eval browser_none=if(user_agent=="-","None","")
| fillnull value="" browser_ff browser_ie browser_chrome browser_safari browser_opera browser_java browser_nagios browser_nessus broswer_none browser_apache
| eval browser = browser_ff.browser_ie.browser_chrome.browser_safari.browser_opera.browser_java.browser_nagios.browser_nessus.browser_none.browser_apache
| top 50 browser
0 Karma

asarolkar
Builder

This query is erroring out currently.

0 Karma

Genti
Splunk Employee
Splunk Employee

since the useragent is being extracted already, you should be able to do a

sourcetype="access" useragent!="-" 
  AND useragent!="Apache" 
  AND useragent!="Load-weight" 
  AND useragent!="Java" 
  AND useragent!="Jakarta Commons-HttpClient" 
  AND useragent!="Mozilla/4.0 [en] (WinNT; I)"
| table SessionCookie, useragent 
| dedup SessionCookie 
| stats count by useragent

You also might want to add a case that if useragent does not match Chrome, Firefox, Safari, or MSIE, to call useragent as "Other"

0 Karma

Ayn
Legend

Could you provide more details on what the current result is and how it differs from the desired result?

0 Karma
Get Updates on the Splunk Community!

Enterprise Security Content Update (ESCU) | New Releases

In December, the Splunk Threat Research Team had 1 release of new security content via the Enterprise Security ...

Why am I not seeing the finding in Splunk Enterprise Security Analyst Queue?

(This is the first of a series of 2 blogs). Splunk Enterprise Security is a fantastic tool that offers robust ...

Index This | What are the 12 Days of Splunk-mas?

December 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...