Monitor OpenHAB with Nagios

666 views
Skip to first unread message

Marcolino

unread,
Oct 9, 2014, 4:56:11 AM10/9/14
to ope...@googlegroups.com
Hi,
I need to integrate Nagios to OpenHAB to handle the notification of Warning and Alarm.
I would like to know if OpenHAB expose some Webservices or something else to query Item Status.

Thanks


zmtgm...@gmail.com

unread,
Oct 9, 2014, 5:20:56 AM10/9/14
to ope...@googlegroups.com
If I understand you right you want to monitor openhab with nagios?

Openhab has a powerfull REST API for this:
https://github.com/openhab/openhab/wiki/REST-API

regards,
Grischa

Steve Cliffe

unread,
Oct 9, 2014, 5:48:05 AM10/9/14
to ope...@googlegroups.com, zmtgm...@gmail.com
As Mark said, the REST API is the way to go if you want to check specific items. 

I'm using the following check command to check the health of OpenHAB itself:

# 'check_openhab' command definition
define command{
        command_name    check_openhab
        command_line    $USER1$/check_http -H $HOSTALIAS$ -I $HOSTADDRESS$ -p 8080 -k "Accept: text/html"
        }

Steve.

Marcolino

unread,
Oct 9, 2014, 6:13:07 AM10/9/14
to ope...@googlegroups.com, zmtgm...@gmail.com
Many Thanks to Grischa and Steve.

Steve,
how do you parse results? Can you post me some example on how you read a temperature sensor in example?
Many Thanks

Marco

Steve Cliffe

unread,
Oct 9, 2014, 7:22:41 AM10/9/14
to ope...@googlegroups.com, zmtgm...@gmail.com
I'm not actually monitoring items in OpenHAB with Nagios - just checking that OpenHAB itself is running (i.e. listening on port 8080). 

Steve.

zmtgm...@gmail.com

unread,
Oct 9, 2014, 8:08:57 AM10/9/14
to ope...@googlegroups.com, zmtgm...@gmail.com
how do you parse results? Can you post me some example on how you read a temperature sensor in example?



Look at this:

with this you can check states with fixed strings (open,close,on,off) like:


Marcolino

unread,
Oct 9, 2014, 4:22:20 PM10/9/14
to ope...@googlegroups.com, zmtgm...@gmail.com
Hi all,
and thanks to all for lots of ideas.
In the end, i moved to json request to REST.
I do a request like this: 


and I get back:

{"type":"NumberItem","name":"ACQUARI_TF_TEMP","state":"25.3","link":"http://192.168.1.72:8080/rest/items/ACQUARI_TF_TEMP"}


Now I use this nagios plugin to parse JSON and ger state:

http://exchange.nagios.org/directory/Plugins/Websites,-Forms-and-Transactions/check_json--2D-check-JSON-attributes-via-http(s)/details

With this polugin I can check if value is greater or lower than a treashold using nagios syntax: https://nagios-plugins.org/doc/guidelines.html#THRESHOLDFORMAT

This is my command:

Inserisci qui il codicedefine command{
command_name check_openhab command_line $USER1$/check_json.pl --url http://myserver.home:8080/rest/items/$ARG1$?type=json --attribute {state} --warning $ARG2$ --critical $ARG3$ -o {state} }
...

ARG1 is the Item to ckek
ARG2 is warning level
ARG3 is critical level

All works like a charm.
Many thanks to all

Reply all
Reply to author
Forward
0 new messages