Today I describe a new project to monitor plants:
How it looks like when it is integrated into Nagios.
GitHub Repository: nagios_check_plant_sensor
Table of contents
1. Hardware
1.1. Plant sensor
1.2. Raspberry Pi 3 Model B
2. Installation
2.1. Raspberry Pi 3 Model B
2.2. Install Python 3.8.*
2.3. Install check_plant_sensor
2.4. Find your sensor’s MAC
2.5. Test check_plant_sensor
2.6. Install NRPE
3. Configure Nagios
3.1. Nagios configuration
4. It’s done
2. Installation
2.1. Raspberry Pi 3 Model B
Operating System: Raspbian 10
Requirements:
- git
- python 3.8.*, installation see below
2.2. Install Python 3.8.*
For more informations follow this link: https://maker-tutorials.com/python3-pip-raspberry-pi-installieren/
apt update
apt upgrade
apt install libffi-dev libbz2-dev liblzma-dev libsqlite3-dev libncurses5-dev libgdbm-dev zlib1g-dev libreadline-dev libssl-dev tk-dev build-essential libncursesw5-dev libc6-dev openssl git
wget https://www.python.org/ftp/python/3.8.4/Python-3.8.4.tar.xz
tar xf Python-3.8.4.tar.xz
cd Python-3.8.4
./configure
make -j -l 4
make altinstall
echo "alias python3=python3.8" >> ~/.bashrc
echo "alias python=python3.8" >> ~/.bashrc
echo "alias pip3=pip3.8" >> ~/.bashrc
source ~/.bashrc
python3 -V
pip3 -V
2.3. Install check_plant_sensor
cd /opt
sudo git clone https://github.com/wefixit-AT/nagios_check_plant_sensor.git nagios_check_plant_sensor.git
python -m pip install --upgrade pip
pip install btlewrap
pip install wheel
pip install bluepy
pip install miflora
2.4. Find your sensor's MAC
hcitool lescan
...
C4:7C:8D:6B:B4:12 Flower care
...
2.5. Test check_plant_sensor
python /opt/nagios_check_plant_sensor.git/check_plant_sensor.py --mac C4:7C:8D:6B:B4:12 --sensor temperature -w 10 -c 5
OK - temperature = 24.3 |temperature=24.3;10.0;5.0;0
2.6. Install NRPE
apt-get install nagios-nrpe-server
systemctl enable nagios-nrpe-server
systemctl start nagios-nrpe-server
vim /etc/nagios/nrpe.cfg
command[check_plant1_moisture]=/opt/nagios_check_plant_sensor.git/check_plant_sensor.py --mac C4:7C:8D:6B:B4:12 --sensor moisture -w 29 -c 25
command[check_plant1_battery]=/opt/nagios_check_plant_sensor.git/check_plant_sensor.py --mac C4:7C:8D:6B:B4:12 --sensor battery -w 20 -c 10
command[check_plant1_temperature]=/opt/nagios_check_plant_sensor.git/check_plant_sensor.py --mac C4:7C:8D:6B:B4:12 --sensor temperature -w 20 -c 15
systemctl reload nagios-nrpe-server
3. Configure Nagios
Add the Raspberry Pi as host, this part is not described here. I assume you know how to add hosts to Nagios. If you need more details please leave a comment.
3.1. Nagios configuration
Mind the “local-service-plantsensor”, it’s important to reduce the calls to safe the plantsensor battery.
define service {
name local-service-plantsensor
use local-service
max_check_attempts 1
check_interval 360
notification_interval 360
register 0
}
define service{
use local-service-plantsensor,graphed-service
host_name plantsensor
service_description Plant 1: Moisture
check_command check_nrpe!check_plant1_moisture
}
define service{
use local-service-plantsensor,graphed-service
host_name plantsensor
service_description Plant 1: Battery
check_command check_nrpe!check_plant1_battery
}
define service{
use local-service-plantsensor,graphed-service
host_name plantsensor
service_description Plant 1: Temperature
check_command check_nrpe!check_plant1_temperature
}
4. It's done
Finally you see your plant in the webinterface of nagios and get a mail when they need water 🙂