Jonathan
Jonathan Author of Robopenguins

Reolink Python API with checkmk

Who watches the watchmen? In this case I set up a check to monitor my security cameras.

The main use case for the cameras: agent link

This is a part three in the series of setting up checkmk monitoring for all the IoT devices on my network.

Monitoring a Reolink

I originally decided to go with Reolink since they seemed less “Cloudy” then other network camera manufacturers. They have a lot of the cloud niceties, but don’t make you go through their services unless you want to.

As a result it wasn’t too surprising that there was already a nice Python library for doing everything I wanted and more: https://github.com/ReolinkCameraAPI/reolinkapipy. The library had one little annoyance which was that it included some large dependencies to handle video streaming which I didn’t need. I created an issue on GitHub, and one of the maintainers was very friendly and responsive to me creating and merging a PR https://github.com/ReolinkCameraAPI/reolinkapipy/pull/46 to make these dependencies optional.

The initial metrics I implemented was one that checked that the on board storage was showing up, and another that counted how many motion events triggered in the last hour.

Creating a Custom checkmk Check

I used the same basic framework for creating a local check as described in Roomba Python API with checkmk, but I extended it to be easier to work with as I add more scripts.

I created the repo https://github.com/axlan/local_checks for this development.

The idea is that rather then run the python code directly, a deploy script will copy the code along with wrapper scripts into place to setup the local checks I want to run. For instance for my two cameras:

  1. I wrote the single python script reolink_check. This script checks environment variables to get the settings it needs.
  2. I created two instance scripts that look like:
1
2
3
4
5
6
7
#!/usr/bin/env bash

SETTING_NAME='CAMERA_NAME' \
SETTING_HOST='CAMERA_IP' \
SETTING_USER='USERNAME' \
SETTING_PASS='PASSWORD' \
/usr/lib/check_mk_agent/local/scripts/reolink_check

with the appropriate values.

  1. I then run the deploy.sh script to copy these files into /usr/lib/check_mk_agent/local/ where they’ll be detected by checkmk

I could make a more sophisticated settings/deploy script, but these was a pretty simple way to be able to reuse and configure the scripts I was developing.

I also moved the code that handled generating the local check output strings to a shared utility function.

With this system I was confident in adding devices, little did I know how annoying my last target would be: Creating a Library for Google Nest API Monitoring