Splunk Search

How to create a new fields based on some characters in _raw log

splunker12er
Motivator

I wanted to create a new field name like 'Country' from the incoming logs based on some characters in the hostname.

Raw logs:

Timestamp                    Type         Hostname   Service     Status    
Fri Mar 14 11:16:16 2014 $ SERVICEALERT $ AU_DC_1    $ SERVICE1  $ OK
Fri Mar 14 11:17:11 2014 $ HOSTALERT    $ IN_DC_2    $ SERVICE2  $ WARNING
Fri Mar 14 11:18:12 2014 $ HOSTEALERT   $ SG_DC_1    $ SERVICE3  $ OK

From the above logs from the HOSTNAME (AU_DC,IN_DC,SG_DC) represents Country (Australia,India,Singapore)

I wanted to create a new fields with this how can create it ?

i tried to tag this , but each time the HOSTNAME may differ , is there any eval commands help?

please help.

Tags (3)
0 Karma

somesoni2
Revered Legend

You want to add new field, say country with values AU/IN/SG or Australia/India/Singapore? If first, then you just need field extraction (using rex/props.conf). If second, then you need field extraction and lookups both.

0 Karma

gnovak
Builder

I think you could use Lookups for this. If you have a large list, I think lookups would be the better option for you.

http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/Usefieldlookupstoaddinformationtoyourev...
http://docs.splunk.com/Documentation/Splunk/6.0.2/Knowledge/Addfieldsfromexternaldatasources

You could do a static lookup. You'd have to make the CSV list of all the hostnames and the country they are associated with, but it would provide you with the data you are looking for and create the Country field automatically.

To test it you could start off with just a small list.

This is also a great blog on how this works. The example is very similar to what you are trying to do.

http://blogs.splunk.com/2009/07/27/enriching-data-with-lookups-part-1/

rakesh_498115
Motivator

Hi splunker12er,

If there only three specfic hosts as you say to can use the eval statment like this in your search
query

[your search ] | eval NEWHOSTNAME=case(hostname==AU_DC,"Australia",hostname==IN_DC,"India",hostname==SD_DC,"Singapore")

or if the no of hostnames are more you can use lookup .pls refer

http://docs.splunk.com/Documentation/Splunk/6.0.2/SearchReference/Lookup

Hope this helps !

lukejadamec
Super Champion

You might need to use the full value:
AU_DC_1, IN_DC_2, SG_DC_1

Also, you might want to include 1==1 as the last case statement to catch unmatched values.

0 Karma

splunker12er
Motivator

I have too many hosts

0 Karma

lukejadamec
Super Champion

How many countries?

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

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 ...