Ad Widget

Collapse

Custom LLD from python script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • batchen_regev
    Member
    • Aug 2018
    • 80

    #1

    Custom LLD from python script

    Hey,

    I have this python script that i added in agent UserParameter:
    UserParameter=customer.vms, /usr/bin/python3 /etc/zabbix/zabbix_scripts/customer_vms.py

    That returns this output :
    {"data": [{"{#CUSTOMER}": "A1", "{#VMS}": 4}, {"{#CUSTOMER}": "B3", "{#VMS}": 4}}]}

    I have created LLD like this (atteched)

    The only thing the latest data shows is the customer names without the vms value.

    I have tried changing the item many times
    customer.vms[{#VMS}]
    customer.vms[{#CUSTOMER},{#VMS}]

    but i dont get ANY value.
    If i put {#CUSTOMER} or {#VMS} in item name it does shows the correct value.
    i want it to show :

    A1 4
    B3 4

    In latest data.
    Also i tried to change json to look like this :
    {"data": [{"#CUSTOMER": "A1", "#VMS": 4}, {"#CUSTOMER": "B3", "#VMS": 4}}]}
    And it gave me a differant error like "Cannot create item: item with the same key "customer.vms[{#VMS},{#CUSTOMER}]" already exists."

    help

    Attached Files
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    LLD is used to create data elements, not to get values for them.

    Comment

    • batchen_regev
      Member
      • Aug 2018
      • 80

      #3
      Originally posted by Hamardaban
      LLD is used to create data elements, not to get values for them.
      how can i make this work ? i do know that it does bring data for things like snmp items if battery1 is on \ off , and more.
      how can i modify it \ or do something that will fit what i want ?

      Thanks.

      Comment

      • Hamardaban
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • May 2019
        • 2713

        #4
        Originally posted by batchen_regev
        bring data for things like snmp items
        Do you use a standard template for this? which one?

        Comment

        • batchen_regev
          Member
          • Aug 2018
          • 80

          #5
          Originally posted by Hamardaban
          - do you use a standard template? which one?
          I created my own template, that uses userparameter script to get the data json.
          in the data json i have key and value and i want to see it in the latest data one by one and not to have to create an item for every pair of key value:

          {"data": [{"{#CUSTOMER}": "A1", "{#VMS}": 4}, {"{#CUSTOMER}": "B3", "{#VMS}": 4}}]}

          Thank you

          Comment

          • Hamardaban
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • May 2019
            • 2713

            #6
            I asked about the example you gave about SNMP and batteries. Not about your main task.

            Comment

            • batchen_regev
              Member
              • Aug 2018
              • 80

              #7
              Originally posted by Hamardaban
              I asked about the example you gave about SNMP and batteries. Not about your main task.
              Template Net Brocade_Foundry Stackable SNMP
              role: item proto:
              Unit {#FAN_UNIT} Fan {#FAN_INDEX}: Fan status sensor.fan.status[snChasFan2OperStatus.{#SNMPINDEX}]
              by the fan name it can give data- its status

              Comment

              • Hamardaban
                Senior Member
                Zabbix Certified SpecialistZabbix Certified Professional
                • May 2019
                • 2713

                #8
                I will write again: LLD only creates items in accordance with prototypes. And the values for these items are obtained in the standard way, just like for any other items. These are two different, independent processes. As far as I can see you are trying to create items and get data for the them in one step.

                In the example above, the item sensor.fan.status is generated FIRST via LLD, and SECOND, this item requests data over SNMP (snmp_oid-1.3.6.1.4.1.1991.1.1.1.3.2.1.4. {#SNMPINDEX}).

                Comment

                • dimir
                  Zabbix developer
                  • Apr 2011
                  • 1080

                  #9
                  Since 5.0 you can both, create items and populate their values from the same JSON. You need some item X that returns JSON with items and their values, then you need an LLD rule that is dependent item on that (master) item X with item prototypes that are also dependent items on that (master) item X. Both LLD rule and item prototypes need item preprocessing with "JSON Path" to extract the needed data.
                  Last edited by dimir; 10-08-2020, 23:55.

                  Comment

                  • batchen_regev
                    Member
                    • Aug 2018
                    • 80

                    #10
                    Originally posted by dimir
                    Since 5.0 you can both, create items and populate their values from the same JSON. You need some item X that returns JSON with items and their values, then you need an LLD rule that is dependent item on that (master) item X with item prototypes that are also dependent items on that (master) item X. Both LLD rule and item prototypes need item preprocessing with "JSON Path" to extract the needed data.
                    Yes that what i ended up doing.
                    created 2 userparams in agent.conf

                    Code:
                    UserParameter=c.conn[*], /usr/bin/python3 /etc/zabbix/zabbix_scripts/c_conn.py $1
                    UserParameter=c_conn.list, /usr/bin/python3 /etc/zabbix/zabbix_scripts/c_conn_list.py
                    Then the discovery role is made from item c_conn.list which this script returns somthing like that:

                    Code:
                     {"data": [{"{#CCC}": "andy", "{#CONN}": 3}}]}
                    And i have in this discovery role an item which is based on the other item c.conn[*]
                    that is a script that gets a value, so i created it like that :

                    Code:
                    key : c.conn[#CCC]
                    And it retuens the value 3 the latest data.
                    (c.conn script should be tested manually that if you run it like :
                    Code:
                    /usr/bin/python3 /etc/zabbix/zabbix_scripts/c_conn.py andy
                    , it returns 3)

                    I hope it will help somone that will come across this.

                    Comment

                    Working...