I changed a little bit the json input to my reality and i got the error:
[ERROR] 2020-05-18 22:56:18.446 [[main]>worker7] ruby - Ruby exception occurred: undefined method `each' for nil:NilClass
Bellow is my json input:
{
"onlineCreditControlRecord" : {
"creditControlRecords" : [
{
"creditControlRecord" : {
"chargingContextSpecific" : [
{
"parameterID" : 16778241,
"parameterValue" : {
"unsigned32" : 0
}
},
{
"parameterID" : 16778243,
"parameterValue" : {
"string" : "3589700690857607"
}
},
{
"parameterID" : 16778254,
"parameterValue" : {
"unsigned32" : 307
}
},
{
"parameterID" : 16778226,
"parameterValue" : {
"unsigned32" : 1086798920
}
},
{
"parameterID" : 16778227,
"parameterValue" : {
"unsigned32" : 0
}
},
{
"parameterID" : 16778228,
"parameterValue" : {
"octetString" : "645836bc"
}
},
{
"parameterID" : 16778230,
"parameterValue" : {
"octetString" : "c917bd79"
}
},
{
"parameterID" : 16778232,
"parameterValue" : {
"string" : "72405"
}
},
{
"parameterID" : 16778233,
"parameterValue" : {
"string" : "72405"
}
},
{
"parameterID" : 16778234,
"parameterValue" : {
"string" : "5"
}
},
{
"parameterID" : 16778235,
"parameterValue" : {
"string" : "java.claro.com.br"
}
},
{
"parameterID" : 16778237,
"parameterValue" : {
"string" : "0"
}
},
{
"parameterID" : 16778238,
"parameterValue" : {
"string" : "0700"
}
},
{
"parameterID" : 16778239,
"parameterValue" : {
"string" : "72405"
}
},
{
"parameterID" : 16778240,
"parameterValue" : {
"unsigned32" : 1
}
},
{
"parameterID" : 16778229,
"parameterValue" : {
"octetString" : "be6d558c"
}
},
{
"parameterID" : 16778249,
"parameterValue" : {
"string" : "72405"
}
},
{
"parameterID" : 16778250,
"parameterValue" : {
"octetString" : "934f"
}
},
{
"parameterID" : 16778252,
"parameterValue" : {
"octetString" : "fcec"
}
}
]
}
}
]
}
}
or
{"onlineCreditControlRecord":{"creditControlRecords":[{"creditControlRecord":{"chargingContextSpecific":[{"parameterID":16778241,"parameterValue":{"unsigned32":0}},{"parameterID":16778243,"parameterValue":{"string":"3589700690857607"}},{"parameterID":16778254,"parameterValue":{"unsigned32":307}},{"parameterID":16778226,"parameterValue":{"unsigned32":1086798920}},{"parameterID":16778227,"parameterValue":{"unsigned32":0}},{"parameterID":16778228,"parameterValue":{"octetString":"645836bc"}},{"parameterID":16778230,"parameterValue":{"octetString":"c917bd79"}},{"parameterID":16778232,"parameterValue":{"string":"72405"}},{"parameterID":16778233,"parameterValue":{"string":"72405"}},{"parameterID":16778234,"parameterValue":{"string":"5"}},{"parameterID":16778235,"parameterValue":{"string":"java.claro.com.br"}},{"parameterID":16778237,"parameterValue":{"string":"0"}},{"parameterID":16778238,"parameterValue":{"string":"0700"}},{"parameterID":16778239,"parameterValue":{"string":"72405"}},{"parameterID":16778240,"parameterValue":{"unsigned32":1}},{"parameterID":16778229,"parameterValue":{"octetString":"be6d558c"}},{"parameterID":16778249,"parameterValue":{"string":"72405"}},{"parameterID":16778250,"parameterValue":{"octetString":"934f"}},{"parameterID":16778252,"parameterValue":{"octetString":"fcec"}}]}}]}}
and bellow is the ruby code:
ruby {
code => '
newValue = ""
values = event.get("[onlineCreditControlRecord][creditControlRecords][creditControlRecord][chargingContextSpecific]")
values.each { |x|
id = x["parameterID"]
value = x["parameterValue"]
value.each { |k, v|
newValue = v
}
event.set("new_parameterId_#{id}", newValue)
}
event.remove("chargingContextSpecific")
'
}
i changed the ruby code to try to reflet this structure but something got wrong.
do you have any ideia ?