Splunk Search

How to extract value from JSON then declare a variable?

yiweishih
Explorer

I have HEC to send an event to Splunk in JSON format:

 

 

{ 
   Status: Down
   Source: GCP
   URL: url_1
}
{ 
   Status: Up
   Source: GCP
   URL: url_2
}
{ 
   Status: Down
   Source: AWS
   URL: url_1
}
{ 
   Status: Up
   Source: AWS
   URL: url_2
}

 

 

I want to extract value from JSON then declare a variable, not sure should I use eval or stats
For example:
declare a variable usl_1_aws_status, it should be Down
declare a variable usl_2_gcp_status, it should be UP

How to do I extract value from JSON then declare a variable?


Labels (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

The easiest is perhaps transpose.

 

| eval site_status=URL . "_" . Source . "_status"
| table site_status Status
| transpose header_field=site_status
| fields - column

 

The sample data gives

url_1_GCP_statusurl_2_GCP_statusurl_1_AWS_statusurl_2_AWS_status
DownUpDownUp

 

View solution in original post

Tags (1)

yuanliu
SplunkTrust
SplunkTrust

The easiest is perhaps transpose.

 

| eval site_status=URL . "_" . Source . "_status"
| table site_status Status
| transpose header_field=site_status
| fields - column

 

The sample data gives

url_1_GCP_statusurl_2_GCP_statusurl_1_AWS_statusurl_2_AWS_status
DownUpDownUp

 

Tags (1)

yiweishih
Explorer

It worked!! Thank you so much!

0 Karma
Get Updates on the Splunk Community!

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...