Splunk Search

How do I extract a Hostname from log where brakes are issue(?)

northwarks
Engager

Hi all -

I'm struggling to extract the hostname from a Dhcp request from my logs:

Mar 4 15:30:40 192.168.1.1 Mar 4 15:30:40 SecurityGateway dhcpd: execute_statement argv[2] = Nest-C256.Ourhouse

What I'm after is a count of the different hosts, I think its fair to assume they will contain Uppercase/Lowercase/Numbers and or : and .

I've tried all sorts and I can't extract Nest-C256.Ourhouse from the case above, I've tried the following with no result:

Base Search .... | rex "argv[2]s=\s(?.[a-z A-Z,-,.]+)"

What I'd like is a table with a count against each hostname

Tags (3)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Your regular expression is close, but needs a few escapes. Try argv\[2\]\s\=\s(?<Host>.[\w\-\.]+).

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

View solution in original post

0 Karma

northwarks
Engager

Guys - Thanks for the quick response for anyone else searching for the same the following worked a treat:

rex "argv[2]\s=\s(?.[\w-.]+)" | stats count by host_value

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Your regular expression is close, but needs a few escapes. Try argv\[2\]\s\=\s(?<Host>.[\w\-\.]+).

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

skoelpin
SplunkTrust
SplunkTrust

Try this

index=... sourcetype=...
| rex argv\[\d+\]\s=\s(?<host_value>\S+)
| stats count by host_value

northwarks
Engager

This looked like the bit I was struggling with _argv[2]\s_ but thanks for the additional bits

0 Karma

skoelpin
SplunkTrust
SplunkTrust

This works exactly as expected, I'm not sure why you skipped over this..

0 Karma

northwarks
Engager

You are right it worked however I was looking to only return those values following 'argv[2] =' and not 'argv' - Both worked I accepted the one which narrowed down my search - I did however use elements from both posts !

0 Karma

skoelpin
SplunkTrust
SplunkTrust

Brush up on your regex.. argv\[\d+\]\s=\s(?<host_value>\S+) applies to argv[2] = perfectly

Feel free to upvote if my answer helped you

0 Karma

northwarks
Engager

regex is my weak point plus new to Splunk .. I totally see the issue here d+ meaning any digit - The issue was it was returning values for multiple argv[1..2..3..4..5] etc.

Upvoted as you did help

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...