Download details

check_openhab check_openhab.php

Informationen
Erstelldatum 28.12.2020
Änderungsdatum 29.03.2022
Version 1.20220328
Dateigröße 6.14 KB
Downloads 473
Lizenz MIT Lizenz external
Preis Donate PayPal

 

Nagios Plugin to check Things and Items from an Openhab Server

You need to install php-curl

If you find a bug or have a request, write me.


/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 String+ -mi "Bedeckt" -i WEATHERFORCAST_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 - DOOR02 (OFFLINE): BRIDGE_OFFLINE

/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m group -i Temperatur -mi temperatur -w 18:21 -c 10:25
CRITICAL - Total: 9 /W: 1 (TEMPER01_Temperature) /C: 2 (TEMPER07_Temperature 27.07°C,TEMPER09_Temperature 28.47°C) | TOTAL= 9;;;; OK=6 WARNING=1 CRITICAL=2

/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m gcontact -i Window
CRITICAL - Total: 11 - Open: 1 (WINDOW08_OpenClose)

/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m gcontact -i Window -gl
CRITICAL - Total: 11 - Open: 1 (WINDOW08)

/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m gswitch+ -i Detector
CRITICAL - Total: 3 - Off: 3 (DETECTOR01_Fire,DETECTOR02_CarbonMonoxide,DETECTOR03_Fire)

/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m Contact+ -i WINDOW01_OpenClose -l WINDOW
CRITICAL - WINDOW: CLOSED 

/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 °C

/usr/bin/php ./check_openhab.php -H 192.168.2.213 -P 8080 -m Number -i TEMPER07_Temperature -mi Celsius -w 10:15 -c 3:30
WARNING - 9.82 Celsius| default=9.82

 ./check_openhab.php -C -m state+ -U -c 0 -i VSX-527
CRITICAL - Total: 46 - Online: 44 - Offline: 2 (LIGHT01,MOTION01) | Total=46;0;0;0;46 Online=44 Offline=2

 ./check_openhab.php -C -m state+ -c 0 -i VSX-527
CRITICAL - Total: 60 - Online: 58 - Offline: 2 (LIGHT01,MOTION01) | Total=60;0;0;0;60 Online=58 Offline=2

/usr/bin/php ./check_openhab.php -C -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 -C -m number -i TEMPER06_Temperature -mi Temperatur -w 16:20 -c 10:25 -l 10 -t
CRITICAL - OFFLINE (BRIDGE_UNINITIALIZED): 10 - 10.60 °C | temperatur=0;16;10;;100


 

Usage:

/usr/bin/php check_openhab.php -H [Openhab Server] -P [Port] -m [mode] -i [Item/ Thing or Group] 
( -u [user] -p [password] -T [Token] -U =unique -mi[numbertype/string] -w [Warning] -c [Critical] -s =https -l [label] -gl =group label -C [configfile] -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)) - disabled thing will not counted

Switch or Switch+
= Switch (On - Critical, Off - OK (Item)), Switch+ (Off - Critical, On - OK (Item)) - disabled thing will not counted

State
= Offline - Critical, Online - OK (Thing)

State+
= total of Things Online/ Offline with warning and critcal (-i comma separated don't test things(label)) - disabled thing will not counted

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

Group
= test a hole group (only numbers)

GContact or GContact+
= test a hole group of Contacts (Open - Critical, Closed - OK (Item)), GContact+ (Closed - Critical, Open - OK (Item))

GSwitch  or GSwitch+
= test a hole group of Switchies (On - Critical, Off - OK (Item)), GSwitch+ (Off - Critical, On - OK (Item))

numbertype

Temperatur  = °C
Humidity    = %
Pressure    = kPa
Battery     = %
Lightsensor = lx (mode number)
every unit  = [unit] (mode number)

or String to find/ not find

-t

only number/contact(+)/state(+) test if thing of an item is ONLINE or OFFLINE

-U

only State+, unique Things

-gl  can be used to print the label of an item instead of the name (Group/GContact/Gcontact+/Gswitch/Gswitch+)

-T [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

-C

config file (default=openhab.php) instead of the controller parameters -H, -P, -s, -T (you can specify any file with path)
example:

<?php
$host='192.168.2.216'; # IP or Hostname Openhab Server
$port='8080'; # Openhab Port
$prot='http'; # Value http or https
$token='' # Token
$user='' # User
$password='' # Password
?>

  

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})

 


 

openhab openhab_battery2

Changelog

Version 1.20220328
correct debug mode


Version 1.20220208
changed state+/gcount(+) and gswitch(+) (no counting DISABLED thing)
add -t to contact(+)/state(+) 


Version 1.20220129
add -t to get thing state of a tested item


Version 1.20220103
minor bugs fixes


Version 1.20211206
help added version and contact


Version 1.20210629
changed state+ unknown and perfdata


Version 1.20210610
change unique to -U
add -u user and -p password


Version 1.20210520
add -C [configfile] and -u =unique


Version 1.20210517
add numbertype Lightsensor and every unit


Version 1.20210422
add -gl group label


Version 1.20210412
add -l label


Version 1.20210405
add GSwitch/GSwitch+
add GContact/GContact+


Version 1.20210402
add Group


1.20210325
update information, if there is no connection 


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


 

Would you like to support me?
Then donate to PayPal...