Nagios Plugin to check Things and Items from an Openhab Server
You need to install php-curl
/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m State -i mihome:sensor_magnet_aq2:7c49eb17e658:158d00044ee1e9
OK - ONLINE
/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m Number -i TEMPER01_Batterieladung -mi Battery -w ~75 -c ~50
WARNING - 58.00 % | Battery=58.00
/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m Contact -i WINDOW11_OpenClose
CRITICAL - OPEN
/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m Contact+ -i WINDOW11_OpenClose
OK - OPEN
/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m Number -i TEMPER07_Temperature -mi Temperatur -w 10:15 -c 3:30
WARNING - 9.82 °C | Temperatur=9.82
/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m String+ -mi "Bedeckt" -i JHSWEATHERFORCAST_ForecastHours06_VorhergesagteWetterlage
CRITICAL - Bedeckt
/usr/bin/php ./check_openhab.php -H 192.168.2.216 -T oh.nagios.En5S2bbp1RPKgGRyTjD9s97YskZm8RkS1Q3uwf89hvAqV6sA8oUGwL985QzIcXafyZCTpxQKRN7w2jF9EH3Hgs -m state -i deconz:openclosesensor:00212E06A601:00158d00044ee1e9010006 -d
{"statusInfo":{"status":"OFFLINE","statusDetail":"BRIDGE_OFFLINE"},"editable":true,"label":"DOOR02","bridgeUID":
"deconz:deconz:00212E06A612","configuration":{"lastSeenPolling":1440,"id":"3"},"properties":{"uid":"00:15:8d:00:04:4e:e1:e9-01-0006"},
"UID":"deconz:openclosesensor:00212E06A612:00158d00044ee1e9010006","thingTypeUID":"deconz:openclosesensor","channels":
[{"linkedItems":["DOOR02_OpenClose"],"uid":"deconz:openclosesensor:00212E06A612:00158d00044ee1e9010006:open","id":"open",
"channelTypeUID":"deconz:open","itemType":"Contact","kind":"STATE","label":"Open/Close","description":"Open/Close detected",
"defaultTags":[],"properties":{},"configuration":{}},{"linkedItems":[],"uid":"deconz:openclosesensor:00212E06A612:00158d00044ee1e9010006:
last_updated","id":"last_updated","channelTypeUID":"deconz:last_updated","itemType":"DateTime","kind":"STATE","label":
"Last Updated","description":"The date and time when the sensor was last updated.","defaultTags":[],"properties":{},"configuration":{}}]}
CRITICAL - JHSDOOR02 (OFFLINE): BRIDGE_OFFLINE
/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m state+ -i DOOR01,DOOR02 -c 0
CRITICAL - Total: 45 - Online: 44 - Offline: 1 (SWITCH01)
Usage: /usr/bin/php check_openhab.php -H [Openhab Server] -P [Port] -m [mode] -i [Item oder Thing] ( -mi[numbertype/string] -w [Warning] -c [Critical] -s =https -T [Token] -d =debug -h =help)
mode - Number + warn crit = number value(Item)
Contact or Contact+ = Contact (Open - Critical, Closed - OK (Item)), Contact+ (Closed - Critical, Open - OK (Item))
Switch or Switch+ = Switch (On - Critical, Off - OK (Item)), Switch+ (Off - Critical, On - OK (Item))
State = Offline - Critical, Online - OK (Thing)
State+ = total of Things Online/ Offline with warning and critcal (-i comma separated don't test things(label))
Date = Date format: [D.M.Y H:m:s] (Item)
String or String+ = find a string in a item to get OK, or find a String to get Critical
numbertype - Temperatur = °C
- Humidity = %
- Pressure = kPa
- Battery = %
or String to find/ not find
Token - since openhab 3.0 you can create a token to access the rest api.
You can create it in the web interface of openhab
Example Critical and Warning Numbers:
-w 10 -c 20 = warning > 10 and critical > 20
-w ~20 -c ~10 = warning < 20 and critical < 10
-c @10:20 = critical ≥ 10 and ≤ 20, (inside the range of {10 .. 20})
-c 10:20 = critical < 10 or > 20, (outside the range of {10 .. 20})
-w 10:20 -c 5:25 = warning < 10 or > 20, (outside the range of {10 .. 20}) and critical < 5 or > 25,(outside the range of {5 .. 25})
Version 1.20210203
add State+ (total of Things Online/ Offline with warning and critcal)
Version 1.20210124
minor bugs fixes
Version 1.20210115
add String and String+ to find not, or find a string in a item
Version 1.20210113
add Token (possible since openhab 3.0)
debug now with api output
Version 1.20210112
add Contact+ and Switch+ to change OK/CRITICAL state
Version: 1.20202127
first Release