Zabbix Sender and Trapper - Intro and Example 1 - Cron
Video Lecture
Description
On My Raspberry Pi Zabbix Proxy, I copy this file to /home/pi/gettemp_cron.py
and create a cron job with settings,
*/1 * * * * python /home/pi/gettemp_cron.py
Provided, I have a Zabbix trapper item in my RaspberryPi host settings in Zabbix Server, with key = pitemp
I will see the temperature of my RaspberryPi logged every minute.
Python Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 | import subprocess
import time
cmd = '/opt/vc/bin/vcgencmd measure_temp'
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
#print(output)
tempC = output.split("=")[1].replace("'C", "").strip()
#print(tempC)
cmd = 'zabbix_sender -z 127.0.0.1 -s "raspberrypi" -k "pitemp" -o "%s" ' % (tempC)
print(cmd)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
print(output)
|
Useful Links
Cron
Crontab Guru