-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zabbix_Data_Sender.py
34 lines (28 loc) · 1 KB
/
Zabbix_Data_Sender.py
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
import syslog
import Adafruit_DHT
import os
### Enter the IP/Hostname of your Zabbix Server here ###
ip =
### Enter the hostname of the Pi running the script here ###
hostname =
### Enter the pin of the AM2302 Temp Sensor Here ###
pin =
key1 = 'Temp'
key2 = 'Hum'
x = 0
syslog.syslog('***** STARTING TEMP/HUMID GATHERING *****')
Sensor = Adafruit_DHT.AM2302
try:
hum, tem = Adafruit_DHT.read_retry(Sensor, pin)
syslog.syslog('***** GOT TEMP AND HUMID *****')
tem_f = 1.8*float(tem) + 32
syslog.syslog("***** TEMP={} HUMIDITY={} *****".format(tem_f,hum))
print("Temp: {}".format(tem_f))
print("Humidity: {}".format(hum))
os.system('zabbix_sender -z {} -s {} -k {} -o {}'.format(ip,hostname,key1,float(tem_f)))
os.system('zabbix_sender -z {} -s {} -k {} -o {}'.format(ip,hostname,key2, float(hum)))
syslog.syslog('***** FINISHED TEMP/HUMID GATHERING *****')
except Exception as e:
syslog.syslog('***** FAILED TO GET TEMP/HUMID BECAUSE: [{}] *****'.format(e))
print(e)
exit