Ad Widget

Collapse

Discovery rule from external check

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tamas-p
    Junior Member
    • Aug 2018
    • 15

    #1

    Discovery rule from external check

    Hi,

    I'm having quiet a bit of headache to discover items from an external check.
    I have machine where I would need monitor lot of items, and snmp can not be used, but an api.
    I have created a script which takes 2 parameters, as the machine or IP, and the top level object I want discover.

    The output looks like this:

    Code:
    {
        "data": [{
                "{#DISKPERFBAY}": "1",
                "{#DISKPERFDEVICENAME}": "Bay  1",
                "{#DISKPERFOPSPERSECOND}": "552",
                "{#DISKPERFINBITSPERSECOND}": "21307392",
                "{#DISKPERFOUTBITSPERSECOND}": "451379"
            },
            {
                "{#DISKPERFBAY}": "2",
                "{#DISKPERFDEVICENAME}": "Bay  2",
                "{#DISKPERFOPSPERSECOND}": "568",
                "{#DISKPERFINBITSPERSECOND}": "18850611",
                "{#DISKPERFOUTBITSPERSECOND}": "421888"
            }
        ]
    }
    (Valid JSON)

    So my understanding was the discovery rule would really just make a counter out of this, and index top level items in this example 2 which would lead to create 2 items out of every item prototype I want.
    I also understand that every item can have only 1 value attached to it.
    So I was to create 3 item prototype here, as there is 3 meaningful value each disk have.

    So having to try many things, but it still not clear for me what type the item prototype should be, as I never managed to get my items created by this way?
    I would use something like this:

    Item prototype:
    name: Disk Ops {#DISKPERFDEVICENAME}
    And then use the {#DISKPERFOPSPERSECOND} as value..
    But what check type to use? What should be the key?

    The script works from a simple item if I set it as external check and use key discovery-python["{HOSTNAME}",diskPerfEntry] so zabbix can use the script for sure and in a simple item, which set to text it records the full json output at each check.
    I did try to turn on loglevel 5, but only thing I can see there is the periodic trigger of the discovery rule, but can not see any indication if it has any issue running it, or not even if it succeeded...

    I have tried many combination, even to use a know working snmp discovery rule, which has the same number of items what I need, and then try to create dependent item prototypes pointing to a static value, but they never got created at the first place.
    I have even tried with calculated items where only a static 5+5 formula in there, as I just wanted to see it would create the desired number of items with names like "test {#SNMPINDEX}" but again, no item being created.

    I have added the script into an agent (running on the zabbix server), to try to do the discovery via agent check, and however the command works from terminal (zabbix_agent.d -t discovery-python-userparam["{HOSTNAME}",diskPerfEntry] ) but again, no items created from the prototypes.

    Can someone tell me what am I'm missing in here, as the documentation, is detailed on SNMP discovery but almost zero information, on external checks and agent checks in the topic.

    Thanks


  • Onizuca
    Junior Member
    • Oct 2018
    • 18

    #2
    In discovery rule you need to announce that yo have some DISKS.
    For example DISKPERFDEVICENA = Bay 1
    Your JSON must to looks like:
    {
    "data": [
    {"{#DISKPERFDEVICENAME}": "Bay 1"},
    {"{#DISKPERFDEVICENAME}": "Bay 2"},
    {"{#DISKPERFDEVICENAME}": "Bay 3"},
    {"{#DISKPERFDEVICENAME}": "Bay 4"}
    ]
    }
    {#DISKPERFDEVICENAME} would be used like an index for feature item.
    Now you can create item prototypes
    If there is no problem to use zabbix agent, you can create item with type: zabbix trapper.
    For example
    name: In ops for {#DISKPERFDEVICENAME}
    type: zabbix trapper
    Key: iops[{#DISKPERFDEVICENAME}] (by discovery rule zabbix now that you have "Bay 1","Bay 2" .. )
    ...
    After that your item is ready and waiting for value
    In the script that you made for discovery and zabbix sender:
    ZBXSERVER=127.0.0.1
    ZBXSENDER=/usr/bin/zabbix_sender
    HOSTNAME=$1
    calculate values

    $ZBXSENDER -z $ZBXSERVER -p 10051 -s $HOSTNAME -k iops[Bay 1] -o "iops value"
    $ZBXSENDER -z $ZBXSERVER -p 10051 -s $HOSTNAME -k iops[Bay 2] -o "iops value"
    $ZBXSENDER -z $ZBXSERVER -p 10051 -s $HOSTNAME -k iops[Bay 3] -o "iops value"
    ...

    PS HOSTNAME must announced in discovery rule. like: yourscriptname[{HOST.HOST}]. Update interval in duscovery rule will affect how often the value of items will be transmitted.
    Good luck

    Comment

    • tamas-p
      Junior Member
      • Aug 2018
      • 15

      #3
      Originally posted by Onizuca
      Now you can create item prototypes
      If there is no problem to use zabbix agent, you can create item with type: zabbix trapper.
      For example
      name: In ops for {#DISKPERFDEVICENAME}
      type: zabbix trapper
      Key: iops[{#DISKPERFDEVICENAME}] (by discovery rule zabbix now that you have "Bay 1","Bay 2" .. )
      ...
      After that your item is ready and waiting for value
      In the script that you made for discovery and zabbix sender:
      ZBXSERVER=127.0.0.1
      ZBXSENDER=/usr/bin/zabbix_sender
      HOSTNAME=$1
      calculate values

      $ZBXSENDER -z $ZBXSERVER -p 10051 -s $HOSTNAME -k iops[Bay 1] -o "iops value"
      $ZBXSENDER -z $ZBXSERVER -p 10051 -s $HOSTNAME -k iops[Bay 2] -o "iops value"
      $ZBXSENDER -z $ZBXSERVER -p 10051 -s $HOSTNAME -k iops[Bay 3] -o "iops value"
      ...

      PS HOSTNAME must announced in discovery rule. like: yourscriptname[{HOST.HOST}]. Update interval in duscovery rule will affect how often the value of items will be transmitted.
      Good luck
      Hi,

      Sorry but I don't get it how.

      Changing the discovery is not a problem, just a matter of parameter...
      I guess that is no problem to use zabbix agent, but in this context I have no idea how...

      However I don't know why but it is working now with external script as in my prev example..
      The discovery call the full list, and in the item prototype I can use the {#DISKPERFDEVICENAME} in the name and the {#DISKPERFBAY} in the key, and it does create the items.
      To be fair I have no idea why it works now. As believe I did the same thing as before.. only I just created a blank new template this time no to mess with existing ones...

      Now I have a new problem to solve around pre-processing, but I will open a new topic for that.

      Thanks for the answer!

      Comment

      Working...