Ad Widget

Collapse

LLD from .xml agent output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • officersk
    Junior Member
    • Mar 2023
    • 3

    #1

    LLD from .xml agent output

    Hi guys,
    I am trying to parse some data from http-agent what are in .xml format.
    What I have done is:

    Main Item with http-agent, what give me the whole .xlm

    Hi guys,
    I am trying to parse some data from http-agent what are in .xml format.
    What I have done is:

    Main Item with http-agent, what give me the whole .xlm

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <Status Modified="2023-02-23 09:11:35">
    <Miniserver Type="2" Name="Building_A08" IP="94.237.219.25" Mask="255.255.0.0" Gateway="94.237.219.254" DHCP="false" DNS1="121.66.181.5" DNS2="86.184.130.125" MAC="504F94A1643B" Device="MS643B" Version="13.1.11.17" Offline="true">
    <NetworkDevices Name="Intercom01" Type="NetworkDevices" Branch="21" Icon="647"/>
    <NetworkDevices Name="Intercom02" Type="NetworkDevices" Branch="27" Icon="221"/>
    <TreeBranch Branch="3" Name="Device05" Icon="228" Serial="13000001" Version="13.1.9.19" Devices="1" Errors="0">
    <TreeDevice Code="-2145779531" Name="device05_sensor" Place="shop" Inst="" Serial="B03592EE" Version="12.4.1.31" HwVersion="1" Online="true" LastReceived="2023-02-23 09:11:36" TimeDiff="0" DummyDev="false"/>
    </TreeBranch>
    <Link Name="Link" Type="Link" Branch="24" Icon="697">
    <Extension Type="1-Wire Extension" Code="8" Name="WE01" Serial="05d907f8" Version="12.1.3.22" HwVersion="2" Online="true" IntDev="false" DummyDev="false">
    <OneWireDevice Name="1W23" Code="101" Serial="28.F4.34.62.0E.00.00.48" Family="00000028" LastReceived="2023-02-23 09:11:34" TimeDiff="2" Online="true"/>
    <OneWireDevice Name="1W43" Code="101" Serial="28.EC.93.5F.0E.00.00.05" Family="00000028" LastReceived="2023-02-23 09:11:31" TimeDiff="5" Online="true"/>
    <OneWireDevice Name="1W54" Code="101" Serial="28.E7.35.61.0E.00.00.0F" Family="00000028" LastReceived="2023-02-23 09:11:34" TimeDiff="2" Online="true"/>
    </Extension>
    <Extension Type="Air Base Extension" Code="170" Name="AE01" Serial="0cd9c9b6" Version="13.1.10.6" HwVersion="2" Online="true" IntDev="false" DummyDev="false" Mac="50:4F:94:FF:FE:B3:EE:02" Occupied="false" Interfered="false">
    <AirDevice Type="bat_sensor" Code="589995" Name="1.20 TH01" Place="sensor01" Inst="" Serial="50:4F:94:FF:FE:94:E8:53" IP="FE80000000000000524F94FFFE94E853" LastReceived="2023-02-23 09:04:12" TimeDiff="444" Version="11.2.11.9" MinVersion="11021109" HwVersion="1" Hops="2" QualityExt="1" QualityDev="1" Online="true" Battery="100" DummyDev="false"/>
    <AirDevice Type="bat_sensor" Code="589995" Name="1.25 TH02" Place="sensor02" Inst="" Serial="50:4F:94:FF:FE:91:F4:45" IP="FE80000000000000524F94FFFE91F4D5" LastReceived="2023-02-23 09:08:49" TimeDiff="167" Version="11.2.11.9" MinVersion="11021109" HwVersion="1" Hops="2" QualityExt="2" QualityDev="2" Online="true" Battery="100" DummyDev="false"/>
    <AirDevice Type="bat_sensor" Code="327851" Name="1.18 TH03" Place="sensor03" Inst="" Serial="50:4F:94:FF:FE:B3:87:BD" IP="FE80000000000000524F94FFFEB387BD" LastReceived="2023-02-23 03:50:28" TimeDiff="19268" Version="13.1.10.12" MinVersion="13011012" HwVersion="2" Hops="3" QualityExt="2" QualityDev="2" Online="true" Battery="127" DummyDev="false"/>
    <AirDevice Type="bat_sensor" Code="2031787" Name="2.26 OK01" Place="sensor04" Inst="" Serial="50:4F:94:FF:FE:B5:66:20" IP="FE80000000000000524F94FFFEB56620" LastReceived="2023-02-16 11:09:50" TimeDiff="597706" Version="12.4.3.2" MinVersion="12040302" HwVersion="2" Hops="4" QualityExt="2" QualityDev="2" Online="false" Battery="34" DummyDev="false"/>
    </Extension>
    <Extension Type="Relay Extension" Code="160" Name="RE02" Serial="0bdb4559" Version="12.4.5.25" HwVersion="2" Online="true" IntDev="false" DummyDev="false"/>
    <Extension Type="Relay Extension" Code="160" Name="RE01" Serial="0bdb4565" Version="12.4.5.25" HwVersion="2" Online="true" IntDev="false" DummyDev="false"/>
    <Extension Type="1-Wire Extension" Code="8" Name="WE02" Serial="05d90cb6" Version="12.1.3.22" HwVersion="2" Online="true" IntDev="false" DummyDev="false">
    <OneWireDevice Name="1W31" Code="101" Serial="28.3F.6A.61.0E.00.00.90" Family="00000028" LastReceived="2023-02-23 09:11:36" TimeDiff="0" Online="true"/>
    <OneWireDevice Name="1W62" Code="101" Serial="28.49.D6.5F.0E.00.00.89" Family="00000028" LastReceived="2023-02-23 09:11:36" TimeDiff="0" Online="true"/>
    <OneWireDevice Name="1W04" Code="101" Serial="28.3D.97.61.0E.00.00.B4" Family="00000028" LastReceived="2023-02-23 09:11:36" TimeDiff="0" Online="true"/>
    </Extension>
    </Link>
    </Miniserver>
    <NetworkDevices Name="Audio" Type="NetworkDevices" Branch="14" Icon="225"/>
    </Status>​

    Then I created a dependent discovery rule with no "Preprocesing" and "LLD macros"



    and dependent "Item prototypes" with this settings:



    ​what give me back this result: ["1W23","1W43","1W54"]

    What I want to achieve is create LLD rule, what give me back new items with "Name" and for example "Online status" from "//Status/Miniserver/Link/Extension/OneWireDevice" XML XPath.
    Could you please help or navigate me what is the right way how to do it?

    Thank you guys​
    Last edited by officersk; 03-03-2023, 10:43.
  • officersk
    Junior Member
    • Mar 2023
    • 3

    #2
    Ok,
    I pushed it forward and use js script in Preprocessing LLD step.



    Code:
    res = []
    obj = JSON.parse(value)
    for (i in obj.AirDevice) {
    res.push({"Name": obj.AirDevice[i]["@Name"]})
    }
    return JSON.stringify(res)​
    This give me back array [{"Name":"1.20 TH01"},{"Name":"1.25 TH02"},{"Name":"1.18 TH03"},{"Name":"2.26 OK01"}] what i use in "Item prototypes" and new Item with specific "Name" are finally created.
    Next question is, how can i get a Battery status for every created Item?

    Comment

    • officersk
      Junior Member
      • Mar 2023
      • 3

      #3
      Ok, got it.
      Just used a preprocessing rule with this JSONPath:
      Code:
      $.Status.Miniserver.Link.Extension[1].AirDevice[?(@.Name == '{#NAME}')].Battery
      Be aware of "@" symbols in .json output, could cause a problem in filtering. Better to remove it by preprocessing step.

      Click image for larger version

Name:	ksnip_20230303-134822.png
Views:	486
Size:	26.6 KB
ID:	460430

      Comment

      Working...