-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frederic Werner
authored
Sep 13, 2018
1 parent
0ac1970
commit f1e61c7
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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() |