Splunk Search

Want to extract "component","environment" & "componentType" and there corresponding value in table format.

JyotiP
Path Finder

I have the following log output and I want to extract "component", "environment" & "component type" and their corresponding value in table format.

Level="INFO", Date="2019-07-22 08:43:44,141", Message="{"Protocol":"https","Path":"/api/infrastructure/qualitygate/v1/qualityGateStatus","Verb":"GET","QueryParams":{"component":"help-website-stack","version":"1.0.291","environment":"testenvironment","componentType":"stack"},"body":{},"StatusCode":200,"Details":{"component":"help-website-stack","version":"1.0.291","sonarStatus":true,"integrationTestStatus":true,"status":true,"message":"","coverage":"0.0","newCoverage":"0.0"}}
Tags (1)
0 Karma
1 Solution

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval test="Level=\"INFO\", Date=\"2019-07-22 08:43:44,141\", Message=\"{\"Protocol\":\"https\",\"Path\":\"/api/infrastructure/qualitygate/v1/qualityGateStatus\",\"Verb\":\"GET\",\"QueryParams\":{\"component\":\"help-website-stack\",\"version\":\"1.0.291\",\"environment\":\"testenvironment\",\"componentType\":\"stack\"},\"body\":{},\"StatusCode\":200,\"Details\":{\"component\":\"help-website-stack\",\"version\":\"1.0.291\",\"sonarStatus\":true,\"integrationTestStatus\":true,\"status\":true,\"message\":\"\",\"coverage\":\"0.0\",\"newCoverage\":\"0.0\"}}" 
| rex field=test "\{\"component\"\:\"(?P<Component>[^\",]+).+\"environment\"\:\"(?P<Environment>[^,]+)\",\"componentType\"\:\"(?P<ComponentType>[^\"\}]+)" 
| table Component,Environment,ComponentType

View solution in original post

0 Karma

JyotiP
Path Finder

@vnravikumar why .+ why not ',' ?

0 Karma

JyotiP
Path Finder

@vnravikumar I want to include also the newCoverage into the table. And I am using .+\"newCoverage\":\"(?P[^\"]+. I am able to retrieve the result but when the value for
newCoverage is null/blank it is not retrieving anything. What shall I do?

0 Karma

vnravikumar
Champion

Hi

Try the below method, as per your sample data Message are in JSON format. so I used spath to extract the info

[updated:]

| makeresults 
 | eval test="Level=\"INFO\", Date=\"2019-07-22 08:43:44,141\", Message=\"{\"Protocol\":\"https\",\"Path\":\"/api/infrastructure/qualitygate/v1/qualityGateStatus\",\"Verb\":\"GET\",\"QueryParams\":{\"component\":\"help-website-stack\",\"version\":\"1.0.291\",\"environment\":\"testenvironment\",\"componentType\":\"stack\"},\"body\":{},\"StatusCode\":200,\"Details\":{\"component\":\"help-website-stack\",\"version\":\"1.0.291\",\"sonarStatus\":true,\"integrationTestStatus\":true,\"status\":true,\"message\":\"\",\"coverage\":\"0.0\",\"newCoverage\":\"0.0\"}}" 
 | rex field=test "Message\=\"(?P<Message>.*)}}$" 
 | spath input=Message path=QueryParams.component output="Component" 
 | spath input=Message path=QueryParams.environment output="Environment" 
 | spath input=Message path=QueryParams.componentType output="Component Type" 
 | spath input=Message path=Details.newCoverage output="New Coverage" 
 | table Component Environment "Component Type" "New Coverage"
0 Karma

vnravikumar
Champion

As per your sample data, the version field was in-between component and environment to skip that I had used .+

0 Karma

JyotiP
Path Finder

Oh got it, make sense as well.

0 Karma

vnravikumar
Champion

Hi

Try this

| makeresults 
| eval test="Level=\"INFO\", Date=\"2019-07-22 08:43:44,141\", Message=\"{\"Protocol\":\"https\",\"Path\":\"/api/infrastructure/qualitygate/v1/qualityGateStatus\",\"Verb\":\"GET\",\"QueryParams\":{\"component\":\"help-website-stack\",\"version\":\"1.0.291\",\"environment\":\"testenvironment\",\"componentType\":\"stack\"},\"body\":{},\"StatusCode\":200,\"Details\":{\"component\":\"help-website-stack\",\"version\":\"1.0.291\",\"sonarStatus\":true,\"integrationTestStatus\":true,\"status\":true,\"message\":\"\",\"coverage\":\"0.0\",\"newCoverage\":\"0.0\"}}" 
| rex field=test "\{\"component\"\:\"(?P<Component>[^\",]+).+\"environment\"\:\"(?P<Environment>[^,]+)\",\"componentType\"\:\"(?P<ComponentType>[^\"\}]+)" 
| table Component,Environment,ComponentType
0 Karma
Get Updates on the Splunk Community!

Earn a $35 Gift Card for Answering our Splunk Admins & App Developer Survey

Survey for Splunk Admins and App Developers is open now! | Earn a $35 gift card!      Hello there,  Splunk ...

Continuing Innovation & New Integrations Unlock Full Stack Observability For Your ...

You’ve probably heard the latest about AppDynamics joining the Splunk Observability portfolio, deepening our ...

Monitoring Amazon Elastic Kubernetes Service (EKS)

As we’ve seen, integrating Kubernetes environments with Splunk Observability Cloud is a quick and easy way to ...