Ho un messaggio JSON con un array in un array. Voglio dividere che in più eventi:Come dividere un array JSON all'interno di un oggetto
{
"type": "monitor",
"server": "10.111.222.333",
"host": "abc.de",
"bean": [{
"name": "beanName1",
"reseted": "2015-06-05T15:10:00.192Z",
"method": [{
"name": "getAllXY",
"count": 5,
"min": 3,
"max": 5
},
{
"name": "getName",
"count": 4,
"min": 2,
"max": 4
}]
},
{
"name": "beanName2",
"reseted": "2015-06-05T15:10:00.231Z",
"method": [{
"name": "getProperty",
"count": 4,
"min": 3,
"max": 3
}]
},
{
"name": "beanName3",
"reseted": "2015-06-05T15:10:00.231Z"
}]
}
Usando un filtro per dividere "fagiolo":
input {
stdin {
codec => "json"
}
}
filter {
split {
field => "bean"
}
}
output {
stdout{codec => "json"}
}
funziona bene:
{"type":"monitor",
"server":"10.111.222.333",
"host":"abc.de",
"bean":{
"name":"beanName1",
"reseted":"2015-06-05T15:10:00.192Z",
"method":[{
"name":"getAllXY",
"count":5,
"min":3,
"max":5
},{
"name":"getName",
"count":4,
"min":2,
"max":4
}]},
"@version":"1",
"@timestamp":"2015-07-14T09:21:18.326Z"
}
{"type":"monitor",
"server":"10.111.222.333",
"host":"abc.de",
"bean":{
"name":"beanName2",
"reseted":"2015-06-05T15:10:00.231Z",
"method":[{
"name":"getProperty",
"count":4,
"min":3,
"max":3
}]},
"@version":"1",
"@timestamp":"2015-07-14T09:21:18.326Z"
}
...
per separare anche i "metodi" , Ho aggiunto un altro filtro split:
split {
field => "bean"
}
split {
field => "bean.method"
}
Ma in questo modo ottengo solo un messaggio di errore:
Exception in filterworker {"exception"=>#LogStash::ConfigurationError: Only String and Array types are splittable. field:bean.method is of type = NilClass
Non riesco ad accedere al "metodo" di matrice all'interno del "fagiolo" oggetto. Ho provato diverse notazioni senza fortuna. È possibile accedere alla matrice, forse non è ancora supportato?
Funziona, ma ho fagioli senza metodi. Così ho aggiunto _if [bean] [metodo] {..._ e ora va bene, grazie mille. – joerno
Perfetto, ho aggiunto la condizione '[bean] [metodo]' alla mia risposta. – hurb
@hurb Cosa succede se il "bean" ha un solo elemento? In questo caso, questo codice non funziona –