Monitoring Devices via Nagios

zwave
Tags: #<Tag:0x00007fd08b5929b0>

#1

Thought I’d share this since I hadn’t seen any related posts.

One issue I’ve been having lately, is once in a while Z-Wave devices just go “dead” and I don’t have any visibility into this. This can range from annoying (oh, I never got notified the laundry was done) to somewhat of a security problem (oh great, my door didn’t lock last night).

I’m already using Nagios to monitor my network, so I decided to investigate what it’d take to monitor the Z-wave devices inside Home Assistant.

To solve this, I installed the following plugin, check_json:

From there, I setup the following command in commands.cfg

define command{
    command_name    check_hass_device
    command_line    $USER1$/check_json -u http://$HOSTADDRESS$:8123/api/states/$ARG1$?api_password=your_password -a '{state}' -e '$ARG2$'
}

Then I modified the file I have that checks my HASS install to the following:

define host {
    use                     linux-server
    host_name               ha
    alias                   Home Assistant Server
    address                 ha
    hostgroups              linux-servers
}

define service {
    use                     local-service
    host_name               ha
    service_description     HTTP
    check_command           check_http!-p 8123
}

define service {
    use                     local-service
    host_name               ha
    service_description     Front Door Lock
    check_command           check_hass_device!zwave.front_door!ready
}

define service {
    use                     local-service
    host_name               ha
    service_description     Washing Machine
    check_command           check_hass_device!zwave.washing_machine!ready
}

Basically, once that command is setup, it’s just a matter of setting the check_command to check_hass_device!entity_id!expected_status and things are good to go after that.

Now I can see when my Z-wave devices are dead


#2

I just started using this. Love it. Upgraded to 83.1 today and nothing works. Just a heads up. I get a 401 connection failed unauthorized error.

UPDATE: Ok, i made the changes listed in the PR here:
https://github.com/c-kr/check_json/pull/37/commits/

I then added an access token to my command:

> define command {
>             command_name    check_hass_device
>             command_line    $USER1$/check_json -u USER5$/api/states/$ARG1$?"Authorization: Bearer MY ACCESSTOKEN -a '{state}' -e '$ARG2$'

Things seem to be working.


#3

@pdobrien3 I was looking at your PR and the command example, and see that there must be things missing. Do you have a working check_json and a correct command definition?


#4

@aherbjornsen, I can’t remember why I stopped using that plugin. Something had stopped working but I can’t remember what. I would love to get things back working. I only copied the info in the PR, it wasn’t my pull request.


#5

Thanks for the quick response. I eventually got it to work myself.
There was a few things missing here and there.

In check_json.pl it needs to look like this:

if ( $np->opts->xauth ) {
    $ua->default_header(
        'Accept'        => 'application/json',
        'Authorization' => $np->opts->xauth
    );
}

Then in command.cfg the command_line should look like this:

command_line $USER1$/check_json.pl -u https://hostname/api/states/$ARG1$ -x "Bearer <your (very long) token>" -a '{state}' -e '$ARG2$' --perfvars 'state'


#6

Thanks, I will try that and report back.


#7

ok, things are coming back to me. I followed your changes and get this:

(No output on stdout) stderr: Can’t locate HTTP/Request/Common.pm in @INC (you may need to install the HTTP::Request::Common module) (@INC contains: /etc/perl /usr/local/lib/arm-linux-gnueabihf/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/arm-linux-gnueabihf/perl5/5.24 /usr/share/perl5 /usr/lib/arm-linux-gnueabihf/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/arm-linux-gnueabihf/perl-base) at /usr/local/nagios/libexec/check_json line 5.

Then when I do sudo apt-get install libjson-perl libnagios-plugin-perl libwww-perl
I get:

Package libnagios-plugin-perl is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package ‘libnagios-plugin-perl’ has no installation candidate


#8

I’ had to do “apt-get install libnagios-plugin-perl” in order to get things to work.
But that did not throw any error messages, I’m on Ubuntu 16.04. I see that it’s not available on my Ubuntu 18.04 machine, so probably something has changed between those.

You can try “apt install libmonitoring-plugin-perl” instead?


#9

(No output on stdout) stderr: Can’t locate Nagios/Plugin.pm in @INC (you may need to install the Nagios::Plugin module) (@INC contains: /etc/perl /usr/local/lib/arm-linux-gnueabihf/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/arm-linux-gnueabihf/perl5/5.24 /usr/share/perl5 /usr/lib/arm-linux-gnueabihf/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/arm-linux-gnueabihf/perl-base) at /usr/local/nagios/libexec/check_json line 8.


#10

You are missing the Perl module needed. Did you try this:
apt install libmonitoring-plugin-perl

Apart from that I think you’ll have to use Google to figure out what happened between Ubuntu 16.04 and 18.04 (or Debian 8 and 9).


#11

I did install libmonitoring-plugin-perl but now I think I have to change the check_json to use a different plugin and I dont know how

I tried changing

use

Nagios::Plugin;

to

use Nagios::Monitoring::Plugin;