Splunk Search

Add a custom column based on host value

Naji
Explorer

Hi, let me first state that I am very new to Splunk.

How can I do the following please?

I would like to add a column called Department to my table. The department value is not part of the event data. It is  something I would like to assign based on the value of host: 

Department HostsIP Address
Saleshost115.20.10.5
 host215.20.10.15
 host315.20.10.25
HRhost415.20.10.35
 host515.20.10.45
 host615.20.10.55
IThost715.20.10.65
 host815.20.10.75
 host915.20.10.85

 

 I also would like to create a Department dropdown menu that filters hosts based on department (dashboard).

Thank you for your time. I appreciate all your help

Labels (1)
0 Karma
1 Solution

SanjayReddy
SplunkTrust
SplunkTrust

Hi @Naji 

you can add new field using eval condition

| eval Department =case(host IN("host1","host2","host3"),"Sales",host IN("host4","host5","host6"),"HR",host IN("host7","host8","host9"),"IT",1=1,"NoDept")

View solution in original post

0 Karma

SanjayReddy
SplunkTrust
SplunkTrust

Hi @Naji 

you can add new field using eval condition

| eval Department =case(host IN("host1","host2","host3"),"Sales",host IN("host4","host5","host6"),"HR",host IN("host7","host8","host9"),"IT",1=1,"NoDept")

0 Karma

Naji
Explorer

This worked perfectly, thank you

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Naji,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @Naji,

if the Department field isn't in the events, you have to create a lookup (called e.g. departments.csv) containing at least two columns (department and host for the enricment).

Then you can run a search like the following:

<your_search>
| lookup departments.csv host OUTPUT department
| rename 
   department AS Department
   host AS Hosts
   IP AS "IP Address"
| table Department Hosts "IP Address"

I supposed that the "IP Address" field is extracted as "IP", if not change adapt the search.

Ciao.

Giuseppe

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Build resilience for the agentic era: Join us at Splunk Go San Jose

AI is changing how organizations build, operate, and secure digital services. As teams adopt AI agents and ...

Manage Edge Processor pipelines end to end with APIs

This guide uses the Data Management APIs to create an Edge Processor, onboard one instance, deploy a pipeline ...

Splunk Brings Proof of Control to Digital Asset Transfers

Digital assets now sit inside the core of financial services. HSBC launched its Tokenized Deposit Service in ...