How to develop plugin for opensensemap data

Hello all,

I would like to monitor some data from https://opensensemap.org

actually they have a API to get the data like this:
https://api.opensensemap.org/boxes/5b1d9ddd1fef04001b15460e?format=json

resulting to an output of this:
{"_id":“5b1d9ddd1fef04001b15460e”,“createdAt”:“2022-03-30T11:25:43.544Z”,“updatedAt”:“2022-04-10T11:30:16.580Z”,“name”:“42477u12”,“currentLocation”:{“timestamp”:“2018-06-10T21:53:33.503Z”,“coordinates”:[7.360126,51.202827],“type”:“Point”},“exposure”:“outdoor”,“sensors”:[{“title”:“PM01”,“unit”:“µg/m³”,“sensorType”:“PMS 5003”,“icon”:“osem-cloud”,"_id":“5b1d9ddd1fef04001b154614”,“lastMeasurement”:{“value”:“14.20”,“createdAt”:“2022-04-10T11:30:16.573Z”}},{“title”:“PM2.5”,“unit”:“µg/m³”,“sensorType”:“PMS 5003”,“icon”:“osem-cloud”,"_id":“5b1d9ddd1fef04001b154613”,“lastMeasurement”:{“value”:“17.20”,“createdAt”:“2022-04-10T11:30:16.573Z”}},{“title”:“PM10”,“unit”:“µg/m³”,“sensorType”:“PMS 5003”,“icon”:“osem-cloud”,"_id":“5b1d9ddd1fef04001b154612”,“lastMeasurement”:{“value”:“18.60”,“createdAt”:“2022-04-10T11:30:16.573Z”}},{“title”:“Temperatur”,“unit”:“°C”,“sensorType”:“BME280”,“icon”:“osem-thermometer”,"_id":“5b1d9ddd1fef04001b154611”,“lastMeasurement”:{“value”:“9.31”,“createdAt”:“2022-04-10T11:30:16.573Z”}},{“title”:“rel. Luftfeuchte”,“unit”:"%",“sensorType”:“BME280”,“icon”:“osem-humidity”,"_id":“5b1d9ddd1fef04001b154610”,“lastMeasurement”:{“value”:“100.00”,“createdAt”:“2022-04-10T11:30:16.573Z”}},{“title”:“Luftdruck”,“unit”:“Pa”,“sensorType”:“BME280”,“icon”:“osem-barometer”,"_id":“5b1d9ddd1fef04001b15460f”,“lastMeasurement”:{“value”:“97842.97”,“createdAt”:“2022-04-10T11:30:16.573Z”}}],“model”:“luftdaten_pms5003_bme280”,“lastMeasurementAt”:“2022-04-10T11:30:16.573Z”,“grouptag”:[""],“loc”:[{“geometry”:{“timestamp”:“2018-06-10T21:53:33.503Z”,“coordinates”:[7.360126,51.202827],“type”:“Point”},“type”:“Feature”}]}

anyone could help me to put this into CheckMK 2.x to monitor the values of temperature, humidity etc.
Olay option so far would be that the SenseboxID should be a parameter to choose in WATO, because it let’s the user select a special SenseBox (e.g. for his city).

because I not familiar in linux / software developing any help is appreciated
:wink:

Mike

Hi,
there are two sections in the Checkmk user manual for you:
https://docs.checkmk.com/latest/en/devel_check_plugins.html
https://docs.checkmk.com/latest/en/dev_guidelines.html

Karl

thank you,

so far I created a executable file mk_osmap in /usr/lib/check_mk_agent/plugins.

#!/bin/sh
echo '<<<mk_osmap>>>'
curl "https://api.opensensemap.org/boxes/5b1d9ddd1fef04001b15460e?format=json"

and another file mk_osmap.py in local/lib/check_mk/base/plugins/agent_based

from .agent_based_api.v1 import *

***def discover_mk_osmap(section):***
***    yield Service()***

***def check_mk_osmap(section):***
***    for line in section:***
***        if line[0].startswith("usb-SCSI_DISK"):***
***            yield Result(state=State.CRIT, summary="Found USB stick")***
***            return***
***    yield Result(state=State.OK, summary="No USB stick found")***



register.check_plugin(
    name="mk_osmap",
    service_name="OpenSenseMap",
    discovery_function=discover_mk_osmap,
    check_function=check_mk_osmap,
)

All the tex within the *** *** ist from the website example and so it will surely not work.
I think this is the part where I really need help…

Mike

Hi Mike,

At least you need a discovery function. That´s mandatory in 2.0 AFAIK.
See here:

You may debug this on command line with "cmk --debug -IIv "
Feel free to add print statements for debugging purpose but remove it as soon as it works.

The check function depends fully on your needs. Mandatory is at least one yield as you can see in the doc.

It also depends on where you want to run the plugin. If you want to run it direct on your monitoring server its better to write a special agent. Unfortunately there is no documentation for this, so you may look how its done in the official code and copy paste.

I hope that helps.

Michael