Zabbix Sender and Trapper - Example 4 - Mock Shop

Video Lecture

Zabbix Sender and Trapper - Example 4 - Mock Shop Zabbix Sender and Trapper - Example 4 - Mock Shop

Description

This script is using zabbix_sender.exe to push data to 3 Zabbix trapper items configured for your host, named costprice, sellprice and profit. All three items are floats.

Python Script

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import time
import random
import subprocess


while 1:
    costprice = random.uniform(1, 100)
    sellprice = costprice + (costprice * random.uniform(-0.20, 0.50))
    profit = sellprice - costprice

    print(str(costprice) + " " + str(sellprice) + " " + str(profit))

    cmd = '"C:\\Program Files\\Zabbix Agent\\zabbix_sender" -z "your-proxy-or-server" -s "your-host" -k "costprice" -o "%s" ' % (
        costprice
    )
    print(cmd)
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    print(output)

    time.sleep(0.2)

    cmd = '"C:\\Program Files\\Zabbix Agent\\zabbix_sender" -z "your-proxy-or-server" -s "your-host" -k "sellprice" -o "%s" ' % (
        sellprice
    )
    print(cmd)
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    print(output)

    time.sleep(0.2)

    cmd = '"C:\\Program Files\\Zabbix Agent\\zabbix_sender" -z "your-proxy-or-server" -s "your-host" -k "profit" -o "%s" ' % (
        profit
    )
    print(cmd)
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    print(output)

    print()
    time.sleep(random.uniform(1, 10))