Search code examples
pythonzabbix

Zabbix Create new item and add data value using python script


newbie on zabbix and python here.

I have a python script and it will:

  1. Retrieve item "item_key" from the zabbix, if it doesn't exist, it will create using the zabbix api,

     item=zapi.item.create(hostid=host_id, 
                           name=fault_description, 
                           key_=item_key, 
                           type=7, # Zabbix agent (active) 
                           value_type=3,
                           type=3, 
                           interfaceid=interface_id, 
                           delay=10)
    
  2. Then once the item is created, I will send some default value to the item on the zabbix using pyzabbix

    resultDefault = send_to_zabbix([Metric(host_name, item_key, OK_VAL, (cur_s))],
                                   '127.0.0.1', 10051)
    

    note:

    cur_s = is the current timestamp when the item is created

    OK_VAL = 0

I have problem, after send_to_zabbix, it seems the zabbix doesn't pick up my OK_VAL and it still shows no data in the "Latest data" on my zabbix although the send_to_zabbix return as True.

However, if i run few times send_to_zabbix() to the item, the item will only update with the OK_VAL after 1 minutes (around 40-50 seconds after the item is created).

I would like to ask, is it possible to make the zabbix receive the data once my item is created without waiting for 1 minute? Or is there any configuration on the zabbix to shorten the duration?

Thanks!

regards, jenny


Solution

  • Try to use:

    value_type=3,  # numeric value
    type=0,        # decimal number
    

    Check doc, maybe I'm wrong. Also, you have used type 2x, probably second one should be data_type=0.

    Edit CacheUpdateFrequency config of zabbix_server, so config cache will be updated more often - default is 60 second.