Using ruby filter to sum values of nested objects everytime the event matches

Hello guys,

I trying to sum the value of a specific field everytime it shows:

the field is in this format: "[cdr][Service-Information][PS-Information][Service-Data-Container][Accounting-Output-Octets]" and it's value is a numeric field(it shows the number of bits consumed).

what i trying to do is the following(based on a reply i saw in this forum):

ruby {
code => '
a = event.get("[cdr][Service-Information][PS-Information][Service-Data-Container][Accounting-Output-Octets]")
if a
sum = 0
a.each_index { |x|
sum += a["amount"]
}
event.set("amount-sum", sum)
end
'
}

i getting the following error:

"Ruby exception occurred: undefined method `each_index' for Integer"

i am a newbie in ruby, so i got no idea if this code serves for this type of field too.

Any help is appreciated! thanks in advanced! :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.