I created a plugin to monitor an Arduino presence sensor for Nagios. The plugin read serial port values in Arduino. The problem is that Nagios does not let the plugin running, it performs takes the values and shuts down. That way it does not read the data correctly.
#!/usr/bin/python
import os, sys
import serial
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=0)
while True:
if state == "0":
print "OK - Sem Alertas"
sys.exit(0)
elif (str(ser.read()) == '2'):
print "WARNING "
sys.exit(1)
elif (str(ser.read()) == '1'):
print "CRITICAL - Intrusos Detectados"
sys.exit(2)
else:
print "UKNOWN - Parametro Desconhecido"
sys.exit(3)