Ad Widget

Collapse

Zabbix4.0 -> pythonScript send JSON => how to populate Zabbix Trapper Item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monitor-it443
    Junior Member
    • May 2020
    • 10

    #1

    Zabbix4.0 -> pythonScript send JSON => how to populate Zabbix Trapper Item

    Hi,

    1.) I have a python script that successfully sends JSON Data to my Zabbix server:
    Code:
    cat /var/log/zabbix/zabbix_server.log
    
    1388:20200511:165346.143 __zbx_zbx_setproctitle() title:'trapper #3 [processing data]'
    1388:20200511:165346.144 trapper got
    '{
    "request":"sender data",
    "data":[
    {
    "host":"jayraspi",
    "key":"smoke_detector_kitchen_alarm",
    "value":"1",
    "clock":1589208826.1425662}]
    }'
    1388:20200511:165346.144 In recv_senderhistory()
    1388:20200511:165346.144 In process_client_history_data()
    1388:20200511:165346.144 In parse_history_data()
    1388:20200511:165346.144 End of parse_history_data():SUCCEED processed:0/1
    1388:20200511:165346.144 End of process_client_history_data():SUCCEED
    1388:20200511:165346.144 In zbx_send_response_ext()
    1388:20200511:165346.144 zbx_send_response_ext() '{"response":"success","info":"processed: 0; failed: 0; total: 0; seconds spent: 0.000333"}'
    1388:20200511:165346.145 End of zbx_send_response_ext():SUCCEED
    1388:20200511:165346.145 End of recv_senderhistory()
    1388:20200511:165346.145 __zbx_zbx_setproctitle() title:'trapper #3 [processed data in 0.001515 sec, waiting for connection]'

    2.) Now I want to read out the value from the key `smoke_detector_kitchen_alarm` as an Item.
    I created the following item in my Zabbix Web Interface:
    Click image for larger version

Name:	screenshot.3157.jpg
Views:	1613
Size:	72.2 KB
ID:	401325



    3.) When I restart the Zabbix server I see that the item seems to be successfully added:
    Code:
    cat /var/log/zabbix/zabbix_server.log
    28564:20200517:112612.142 itemid:28760 hostid:10084 key:'smoke_detector_kitchen_alarm'
    28564:20200517:112612.142 type:2 value_type:4
    28564:20200517:112612.142 interfaceid:0 port:''
    28564:20200517:112612.142 state:0 error:''
    28564:20200517:112612.142 flags:0 status:0
    28564:20200517:112612.142 valuemapid:0
    28564:20200517:112612.142 lastlogsize:0 mtime:0
    28564:20200517:112612.142 delay:'0' nextcheck:0 lastclock:0
    28564:20200517:112612.142 data_expected_from:1589707572
    28564:20200517:112612.142 history:1 history_sec:7776000
    28564:20200517:112612.142 poller_type:255 location:0
    28564:20200517:112612.142 inventory_link:0
    28564:20200517:112612.143 priority:1 schedulable:1


    4.) If I send the JSON Data, I can see that it was successfully received in the log file, but still processed: 0
    Code:
    cat /var/log/zabbix/zabbix_server.log
    28586:20200517:113541.557 __zbx_zbx_setproctitle() title:'trapper #4 [processing data]'
    28586:20200517:113541.557 trapper got '{
    "request":"sender data",
    "data":[
    {
    "host":"jayraspi",
    "key":"smoke_detector_kitchen_alarm",
    "value":"1",
    "clock":1589708141.5558918}]
    }'
    28586:20200517:113541.557 In recv_senderhistory()
    28586:20200517:113541.557 In process_client_history_data()
    28586:20200517:113541.557 In parse_history_data()
    28586:20200517:113541.557 End of parse_history_data():SUCCEED processed:0/1
    28586:20200517:113541.557 End of process_client_history_data():SUCCEED
    28586:20200517:113541.557 In zbx_send_response_ext()
    28586:20200517:113541.557 zbx_send_response_ext() '{"response":"success","info":"processed: 0; failed: 0; total: 0; seconds spent: 0.000166"}'
    28586:20200517:113541.557 End of zbx_send_response_ext():SUCCEED
    28586:20200517:113541.557 End of recv_senderhistory()
    28586:20200517:113541.557 __zbx_zbx_setproctitle() title:'trapper #4 [processed data in 0.000763 sec, waiting for connection]'


    5.) Also in the Web GUI, I see that the item has not received any data
    Click image for larger version

Name:	screenshot.3161.jpg
Views:	1624
Size:	21.6 KB
ID:	401326

    6.) My Question:
    -How can I make the smoke_detector_kitchen_alarm Zabbix Trapper Item receive the value (in this case unsigned int "1") from the send JSON Data?
    - What do I miss ?


    7.) This is my Python sender script:
    Click image for larger version

Name:	screenshot.3162.jpg
Views:	1595
Size:	20.2 KB
ID:	401327
    (Result is "True")
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    Nice job providing a lot of useful information. So many questions on these forums don't...

    Does it make a difference if you don't quote the '1' in the Metric object type, in the call to send_to_zabbix? I ask, because JSON does actually have data types, and a numeric type in JSON wouldn't be quoted (there are exceptions, but I suspect Zabbix is adhering closely to the rules).

    Comment

    Working...