Table of Contents

USB sensors integration for Nagios

This guide illustrates an easy way to check the environmental situation of the FoxBox, in real-time and using a standard USB sensor (or a set of them). Obviously we will need a Nagios instance onboard, thus the procedure shown is compatible just with the FoxBox versions having it (EasyG2 and Monitoring).

At the end of the implementation, you will see these new measurements from the FoxBox Nagios interface, like in the screenshot below:

Moreover, as for every other Nagios check, you will receive SMS alerts when something goes wrong.

During this guide we will propose two practical examples, using USB sensors that should detect respectively the temperature/humidity and the movements in the room where FoxBox has been installed.

Temperature & Humidity check

This plugin has been developed to let Foxbox handle inputs from the Oak USB Sensor Humidity by Toradex (datasheet available here), allowing us to measure humidity (in %) and temperature (in °C) in the room where FoxBox is placed (e.g. the one where fundamental servers are installed).

In order to properly integrate the system with Nagios, you will need to develop a specific plugin using the sensor's specifications. In our case we already wrote and compile it (download it here).
:id1: Every plugin should be compliant with Nagios standards, thus behaving as the default ones.

Now let's speak about the installation of this binary. The file you downloaded has to be placed inside of the folder /usr/local/nagios/libexec, together with the other plugins. Remember to make the file executable, giving it right permissions.
Now you have to edit the file /etc/nagios3/commands.cfg adding these new lines:

#'check_th' command definition
define command{
    command_name check_local_th
    command_line /usr/bin/sudo $USER1$/check_th $ARG1$ $ARG2$ $ARG3$ $ARG4$ $ARG5$
}

And the file /etc/nagios3/conf.d/services_nagios2.cfg adding these new lines:

#KDEV TH sensor handling part1
define service{
    use    local-service         
    host_name    localhost
    service_description    Check Temperature
    check_command    check_local_th!0!14!22!10!26
}

#KDEV TH sensor handling part2
define service{
    use    local-service         
    host_name    localhost
    service_description    Check Humidity
    check_command    check_local_th!1!20!40!15!60
}

Note that in order to customize the behaviour of the plugin you can modify the default thresholds, changing the last four parameters in the check_command line. Their meaning, from left to right, are:

This means that, using the default values, you will receive an alert if temperature goes under 14°C, or it overcomes 26°C, or again if humidity is over 40%, and so on…

Movements check

This plugin has been developed to let Foxbox handle inputs from the Oak USB Sensor IR Motion Detection by Toradex (datasheet available here), allowing us to check the movements in the room where FoxBox is placed (e.g. the one where fundamental servers are installed).

As in the previous case, to properly integrate the system with Nagios you will need to develop a specific plugin using the sensor's specifications. In our case we already wrote and compile it (download it here).

Now let's speak about the installation of this binary. The file you downloaded has to be placed inside of the folder /usr/local/nagios/libexec, together with the other plugins. Remember to make the file executable, giving it right permissions.
Now you have to edit the file /etc/nagios3/commands.cfg adding these new lines:

#'check_pres' command definition
define command{
    command_name check_local_pres
    command_line /usr/bin/sudo $USER1$/check_pres
}

And the file /etc/nagios3/conf.d/services_nagios2.cfg adding these new lines:

# KDEV Presence sensor handling
define service{
    use    local-service         
    host_name    localhost
    service_description    Check Presence
    check_command    check_local_pres
    max_check_attempts    2
    normal_check_interval    2
    retry_check_interval    1
}

Note that in order to customize the behaviour of the plugin you can just modify the parameters shown in the previous codeblock, because the internal logic of the plugin does not accept additional ones. Please refer to some Nagios guide to correctly manage them.

By default, you will receive an alert when the sensor detects a presence (using the algorithm in the plugin) twice in two minutes.