-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_dht.py
51 lines (42 loc) · 1.67 KB
/
check_dht.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#This plugin will read the temperature and humidity values from your sensor (dht11, dht22, 3202) and return it in readable format for tools like icinga oder nagios including perfdata for visualization.
#This check plugin needs the adafruit dht library available on: https://github.com/adafruit/Adafruit_Python_DHT.git
import sys
import argparse
import Adafruit_DHT
AUTHOR = "Frederic Werner"
VERSION = 0.1
parser = argparse.ArgumentParser()
parser.add_argument("model", help="the sensor model you use [11|22|3202]", type=int, choices=[11, 22, 3202])
parser.add_argument("gpio", help="the gpio pin number you are using", type=int)
parser.add_argument("-wt", help="warning value for temperature", type=int)
parser.add_argument("-ct", help="critical value for temperature", type=int)
parser.add_argument("-wh", help="warning value for humidity", type=int)
parser.add_argument("-ch", help="warning value for humidity", type=int)
args = parser.parse_args()
model = args.model
gpio = args.gpio
wt = args.wt
ct = args.ct
wh = args.wh
ch = args.ch
state = "OK"
humidity, temperature = Adafruit_DHT.read_retry(model, gpio)
def exitCode():
if state == 'OK':
sys.exit(0)
if state == 'WARNING':
sys.exit(1)
if state == 'CRITICAL':
sys.exit(2)
if state == 'UNKNOWN':
sys.exit(3)
if wt and wt < temperature:
state = "WARNING"
if wh and wh < humidity:
state = "WARNING"
if ct and ct < temperature:
state = "CRITICAL"
if ch and ch < humidity:
state = "CRITICAL"
print '%s - ' % state + 'Temperature: {0:0.1f} C Humidity: {1:0.1f} %'.format(temperature, humidity), '| temperature={0:0.1f}c'.format(temperature), 'humidity=%d' % humidity + '%'
exitCode()