Ad Widget

Collapse

Preprocessing XML XPath Not working as expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mellis
    Senior Member
    • Oct 2017
    • 145

    #1

    Preprocessing XML XPath Not working as expected

    I am looking at trying to use some dependent items that parse an xml value.

    I have setup an item to query a web service and return an XML string:
    <RestAPIStatusModel xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/RestAPI.Models"><Id>a5d9cfa3-b68c-4799-8166-9df39016abb4</Id><IsHealthy>true</IsHealthy><JobIsRunning>false</JobIsRunning><NotHealthyError></NotHealthyError><Printers><RestAPIPrinterModel><Is Available>true</IsAvailable><Message></Message><Name>10.10.224.17</Name><Status>Idle</Status></RestAPIPrinterModel></Printers><ServicesStatus><RestAPIServiceStatusMode l><IsAvailable>true</IsAvailable><Message>Service is Available</Message><ServiceName>BatchSpooler</ServiceName><ServiceType>BatchSpooler</ServiceType></RestAPIServiceStatusModel><RestAPIServiceStatusMod el><IsAvailable>true</IsAvailable><Message></Message><ServiceName>net.pipe://127.0.0.1/RenderingEngineService</ServiceName><ServiceType>Renderer</ServiceType></RestAPIServiceStatusModel><RestAPIServiceStatusMod el><IsAvailable>true</IsAvailable><Message></Message><ServiceName>PrintSpooler1</ServiceName><ServiceType>PrintSpooler</ServiceType></RestAPIServiceStatusModel></ServicesStatus></RestAPIStatusModel>
    Next I wanted to parse out the values of IsHeathy, NotHeathlyError, and IsAvailable.

    For the IsHealthy I am using the preprocessing XML XPath of string(/IsHealthy) but I am getting a null string.

    Anyone have an idea where my error is?
  • drenriza
    Junior Member
    • May 2019
    • 19

    #2
    In your XPATH parameters try saying

    /RestAPIStatusModel/IsHealthy/text()

    and have "type of information" as text

    Comment

    • mellis
      Senior Member
      • Oct 2017
      • 145

      #3
      Still getting an empty string

      Comment

      • drenriza
        Junior Member
        • May 2019
        • 19

        #4
        After you made the change have you made a new "check now" under the host, items and the item in question? So you are sure you are looking at new data in "latest data"
        If it still does not work try see this https://www.youtube.com/watch?v=xIbWRx0DF1k

        Comment

        • mellis
          Senior Member
          • Oct 2017
          • 145

          #5
          I am using the test in the preprocessing, I will review the youtube,
          thank you

          Comment

          • mellis
            Senior Member
            • Oct 2017
            • 145

            #6
            OK I am back trying to get this to work, the closest I have gotten is a blank string. I watch the video and, this works the way I expect it to only I do not get any value.

            Comment

            • drenriza
              Junior Member
              • May 2019
              • 19

              #7
              Have you tried to use another xpath program to see if you can extract data from your xml file, to make sure the file itself is ok?
              Did you add /text() after your xpath statement in Zabbix? I get an empty string if i dont do this myself.

              Comment

              • gchalmers_aus
                Junior Member
                • Apr 2019
                • 2

                #8
                I know it is old but I hit the same problem. Try the test path with the xml name space removed i.e.
                <RestAPIStatusModel><Id>a5d9cfa3-b68c-4799-8166-9df39016abb4</Id><IsHealthy>true</IsHealthy>
                I found that is what was breaking my citrix odata monitoring xml discovery

                Comment

                • Juanito
                  Junior Member
                  • Mar 2021
                  • 4

                  #9
                  Hi Gchalmers_aus,
                  nice catch, namespace seems to be the issue.
                  too bad such xml can't be treated via Xpath :/
                  i'll keep searching a workaround
                  thanks!

                  ps: this worked for me, to get rid of the namespace issue: https://stackoverflow.com/questions/...ces-with-xpath
                  Last edited by Juanito; 19-05-2021, 15:36. Reason: adding link to get rid of namespace

                  Comment

                  Working...