Getting Data In

Count events which has defined a path in JSON

ivykp
New Member

Hello there,

I have the next JSON which would be my event:

{"severity":"PROCESS","marker":"EML[ EMLMOD ]","logger":"SURALOGGER[PROCESS#EML#EMLMOD]","thread":"application-akka.actor.default-dispatcher-8","message":"TRANSACTIONID=dec-cf08c726-c229-46ed-9c4a-2a19b760f1c8|FECCOL=2019-04-08T14:00:07|COMENTARIO=null|DECLARACION={\"idDeclaracion\":\"dec-cf08c726-c229-46ed-9c4a-2a19b760f1c8\",\"idCotizacion\":\"cot004\",\"idSolicitud\":\"080008072325\",\"fecha\":1554317807,\"producto\":{\"ramo\":\"080\",\"subRamo\":\"vc2\"},\"canal\":\"020\",\"prospecto\":{\"id\":\"1111\",\"edad\":29,\"talla\":180,\"peso\":80,\"imc\":24.69,\"ocupacion\":\"A36\",\"sexo\":\"femenino\"},\"datosAdicionales\":null,\"preguntas\":[{\"id\":\"pe-38104e2d-28d0-49d1-ab80-37f8537cd3bc\",\"respuestas\":[{\"id\":\"re-3a8ba35c-e3d7-4eea-8d80-167ec5c213ea\",\"esPositiva\":false}]},{\"id\":\"pe-c67edfb6-f990-4bc4-ba9f-f6a2dca8b914\",\"respuestas\":[{\"id\":\"re-a315d1ab-f57f-41d0-96c3-ee4048504d5e\",\"esPositiva\":true},{\"id\":\"re-8251a993-595a-4f69-883b-fccf01748518\",\"esPositiva\":true}]},{\"id\":\"pe-9945cdf8-eb3d-4499-887b-40fe201e2c64\",\"respuestas\":[{\"id\":\"re-negativa-pregunta-otras-enfermedades\",\"esPositiva\":false}]},{\"id\":\"pe-19f3325e-f775-4abe-a8e1-218d1bb24cc6\",\"respuestas\":[{\"id\":\"re-negativa-pregunta-otros-deportes\",\"esPositiva\":false}]},{\"id\":\"pe-d0bdf8cd-bb79-4440-b171-0028ca1deb3a\",\"respuestas\":[{\"id\":\"re-1bb16e02-ec0a-4b36-8f5d-4cff953a70ae\",\"esPositiva\":false}]},{\"id\":\"pe-35d09af1-4ad4-46e9-bd76-e50f2afa5dcc\",\"respuestas\":[{\"id\":\"re-9e559f45-342c-4f7c-9a4d-1bf0daebaa5d\",\"esPositiva\":false}]},{\"id\":\"pe-3705c84b-2e55-4bb0-9c3c-1061b7814e8d\",\"respuestas\":[{\"id\":\"re-b4add8ef-ccae-49c3-a664-242bfa4a6875\",\"esPositiva\":true}]},{\"id\":\"pe-3b93e80e-d7d0-4d90-bf13-16489da2d47f\",\"respuestas\":[{\"id\":\"re-95f212a4-3562-405a-be24-aa656b93fe80\",\"esPositiva\":false}]}],\"decisiones\":{\"declinar\":{\"coberturas\":[\"vrd\",\"pau\",\"vgc\"],\"codigosCie\":[]},\"aprobar\":{\"coberturas\":[\"gex\",\"vcn\"],\"codigosCie\":[]},\"extraprimar-miles\":[{\"cobertura\":\"mac\",\"magnitud\":3,\"clasificacion\":\"deporte extremo\",\"codigosCie\":[\"Z57\"]},{\"cobertura\":\"vid\",\"magnitud\":3,\"clasificacion\":\"deporte extremo\",\"codigosCie\":[\"Z57\"]}],\"extraprimar-porcentaje\":[{\"cobertura\":\"ive\",\"magnitud\":25,\"clasificacion\":\"morbilidad\",\"codigosCie\":[\"I10X\"]},{\"cobertura\":\"ive\",\"magnitud\":100,\"clasificacion\":\"deporte extremo\",\"codigosCie\":[\"Z57\"]},{\"cobertura\":\"vid\",\"magnitud\":25,\"clasificacion\":\"morbilidad\",\"codigosCie\":[\"I10X\"]},{\"cobertura\":\"iva\",\"magnitud\":100,\"clasificacion\":\"deporte extremo\",\"codigosCie\":[\"Z57\"]},{\"cobertura\":\"efg\",\"magnitud\":25,\"clasificacion\":\"morbilidad\",\"codigosCie\":[\"I10X\"]},{\"cobertura\":\"efg\",\"magnitud\":50,\"clasificacion\":\"deporte extremo\",\"codigosCie\":[\"Z57\"]}],\"riesgo-sub-normal\":[\"E780\",\"I10X\"]}}"}

I want to count the events which has the path 'decisiones.declinar' defined.

This is my query:

index=eml | rex field=message "DECLARACION=(?<declaracion>[\"\s\W\{\}\[\]:\w\n\.]+)" | where NOT isnull(declaracion) | spath input=declaracion | eval declinar = if(isnull('decisiones.declinar'), 0, 1) | table declinar

The problem is i always get 0 for each event, even though the path 'decisiones.declinar' is defined.

Any suggestions?

0 Karma

vnravikumar
Champion

Hi

Give a try

index=eml 
| rex field=message "DECLARACION=(?<declaracion>[\"\s\W\{\}\[\]:\w\n\.]+)" 
| where NOT isnull(declaracion) 
| spath input=declaracion 
| eval declinar = if(isnull('decisiones.declinar.coberturas{}'), 0, 1) 
| table declinar,decisiones.declinar.coberturas{}
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!

Painting a Clearer Picture: Unifying Your Investigations with Cisco AI Canvas

Painting a Clearer Picture: Unifying Your Investigations with Cisco AI Canvas  We’ve all been there. You’re ...

Hello POJO, meet nocode

What's the Challenge? Instrumentation agents are highly advanced bits of software that manipulate bytecode, ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...