Handle the xml parsed data, met an issue as ruby exception occurred: can't convert String into Integer


(terry mu) #1

Hi experts,

Here is a xml parsed data show as below:

"parsed" => {
        "PMSetup" => [
            [0] {
                 "startTime" => "2018-03-09T08:40:00.000+01:00",
                  "interval" => "5",
                "PMMOResult" => [
                    [0] {
                              "MO" => [
                            [0] {
                                       "DN" => [
                                    [0] "NTAS-tas01/Host-cbam-4c63de7aeae2460289cd4197dc7-amc-node-0/ContId-8ca345e0f5e4/ContType-amc"
                                ],
                                "dimension" => "network_element"
                            }
                        ],
                        "PMTarget" => [
                            [0] {
                                        "M2059C3" => [
                                    [0] "3"
                                ],
                                        "M2059C2" => [
                                    [0] "163580"
                                ],
                                        "M2059C1" => [
                                    [0] "4030728"
                                ],
                                "measurementType" => "CTMEM",
                                        "M2059C4" => [
                                    [0] "3"
                                ]
                            }
                        ]
                    },
                    [1] {
                              "MO" => [
                            [0] {
                                       "DN" => [
                                    [0] "NTAS-tas01/Host-cbam-4c63de7aeae2460289cd4197dc7-dtd-node-0/ContId-3929221df021/ContType-dtd"
                                ],
                                "dimension" => "network_element"
                            }
                        ],
                        "PMTarget" => [
                            [0] {
                                        "M2059C3" => [
                                    [0] "10"
                                ],
                                        "M2059C2" => [
                                    [0] "642744"
                                ],
                                        "M2059C1" => [
                                    [0] "5648712"
                                ],
                                "measurementType" => "CTMEM",
                                        "M2059C4" => [
                                    [0] "10"
                                ]
                            }
                        ]
                    },
                    [2] {
                              "MO" => [
                            [0] {
                                       "DN" => [
                                    [0] "NTAS-tas01/Host-cbam-4c63de7aeae2460289cd4197dc7-oam-node-1/ContId-07f4cdd2c44e/ContType-glsgw"
                                ],
                                "dimension" => "network_element"
                            }
                        ],
                        "PMTarget" => [
                            [0] {
                                        "M2059C3" => [
                                    [0] "1"
                                ],
                                        "M2059C2" => [
                                    [0] "77263"
                                ],
                                        "M2059C1" => [
                                    [0] "4117041"
                                ],
                                "measurementType" => "CTMEM",
                                        "M2059C4" => [
                                    [0] "1"
                                ]
                            }
                        ]
                    },
                    [3] {
                              "MO" => [
                            [0] {
                                       "DN" => [
                                    [0] "NTAS-tas01/Host-cbam-4c63de7aeae2460289cd4197dc7-oam-node-2/ContId-1e6334140d06/ContType-glsgw"
                                ],
                                "dimension" => "network_element"
                            }
                        ],
                        "PMTarget" => [
                            [0] {
                                        "M2059C3" => [
                                    [0] "1"
                                ],
                                        "M2059C2" => [
                                    [0] "80325"
                                ],
                                        "M2059C1" => [
                                    [0] "4113979"
                                ],
                                "measurementType" => "CTMEM",
                                        "M2059C4" => [
                                    [0] "1"
                                ]
                            }
                        ]
                    },
                 ],
        "version" => "2.3"
    }

I want to use ruby code to handle every PMMOResult block, the related ruby code such like this:

 if "_xmlparsefailure" not in [tags]{
                ruby { code => "

                                pmMeasInfo = event.get(['parsed']['PMSetup'][0]['PMMOResult'])
                                pmMeasInfo.each do |pr|

                                     ... ...

                               end
                               ... ...

                             "}

Then this sentence "pmMeasInfo = event.get(['parsed']['PMSetup'][0]['PMMOResult'])" make the ruby exception result.

[2018-05-14T19:08:18,912][ERROR][logstash.filters.ruby    ] Ruby exception occurred: can't convert String into Integer

Experts, would you please help me check this issue? How can I get every data from "PMMOResult", then put them into an array/hash_array?

Thank you.


(terry mu) #2

@magnusbaeck expert, can you help check it? Thank you.


(Guy Boertje) #3

For a LS nested field reference, you need to put the all the brackets in one continuous string.
pmMeasInfo = event.get("[parsed][PMSetup][0][PMMOResult]")
Single quotes are OK too - I used double quotes here as they are easier to see.


(terry mu) #4

Guyboertje, great thanks a lot for your answer, I have modified it to
pmMeasInfo = event.get("[parsed][PMSetup][0][PMMOResult]")
Then it can work without rubyexception.

It block me a long time, thanks agian.


(system) #5

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