This commit introduces two new device types, GroundValueChecker and WeatherSensorDevice, which leverage public APIs (BORIS NRW and Open-Meteo) for real-time data collection. It also includes several API enhancements and fixes to support these new integrations. Detailed changes: - **New Device Types**: - Added GroundValueChecker schema and integration with BORIS NRW WMS via Zabbix Script items. - Added WeatherSensorDevice schema and integration with Open-Meteo via Zabbix HTTP Agent items. - **API Enhancements**: - Added error field to ZabbixItem for item-level error reporting. - Updated CreateTemplateItem mutation input to support params (for Script items) and timeout. - Registered missing scalar resolvers: JSONObject, DateTime, and Time. - **Performance & Reliability**: - Implemented batch fetching for item preprocessing in both host and template queries to reduce Zabbix API calls and ensure data visibility. - Updated template_importer.ts to correctly handle Script item parameters. - **Documentation**: - Consolidated public API device recipes in docs/howtos/cookbook.md. - Added guidance on analyzing data update frequency and setting reasonable update intervals (e.g., 1h for weather, 1d for ground values). - **Testing**: - Added new regression test REG-ITEM-META to verify item metadata (units, description, error, preprocessing) and JSONObject scalar support. - Enhanced RegressionTestExecutor with more detailed host-item relationship verification.
69 lines
3 KiB
GraphQL
69 lines
3 KiB
GraphQL
### Mutation
|
|
Use this mutation to import a template specifically designed to work with the `GroundValueChecker` type. This template uses a Zabbix Script item to dynamically calculate a BBOX around the host's coordinates and fetch ground values from the NRW BORIS WMS service.
|
|
|
|
```graphql
|
|
mutation ImportGroundValueTemplate($templates: [CreateTemplate!]!) {
|
|
importTemplates(templates: $templates) {
|
|
host
|
|
templateid
|
|
message
|
|
error {
|
|
message
|
|
code
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
### Variables
|
|
The following variables define the `GROUND_VALUE_CHECKER` template. It uses the host's user macros (`{$LAT}` and `{$LON}`) to fetch localized ground value data.
|
|
|
|
```json
|
|
{
|
|
"templates": [
|
|
{
|
|
"host": "GROUND_VALUE_CHECKER",
|
|
"name": "Ground Value Checker Template",
|
|
"groupNames": ["Templates/External APIs"],
|
|
"tags": [
|
|
{ "tag": "deviceType", "value": "GroundValueChecker" }
|
|
],
|
|
"macros": [
|
|
{ "macro": "{$LAT}", "value": "51.22" },
|
|
{ "macro": "{$LON}", "value": "6.77" }
|
|
],
|
|
"items": [
|
|
{
|
|
"name": "BORIS NRW API Fetch",
|
|
"type": 21,
|
|
"key": "boris.get",
|
|
"value_type": 4,
|
|
"history": "0",
|
|
"delay": "1d",
|
|
"params": "var lat = '{$LAT}';\nvar lon = '{$LON}';\n\nif (lat.indexOf('{$') === 0 || lon.indexOf('{$') === 0) {\n throw 'Macros {$LAT} and {$LON} must be set on the host.';\n}\n\nlat = parseFloat(lat);\nlon = parseFloat(lon);\n\nvar delta = 0.0005; \nvar minLon = lon - delta;\nvar minLat = lat - delta;\nmaxLon = lon + delta;\nmaxLat = lat + delta;\n\nvar bbox = minLon.toFixed(6) + \",\" + minLat.toFixed(6) + \",\" + maxLon.toFixed(6) + \",\" + maxLat.toFixed(6);\n\nvar url = \"https://www.wms.nrw.de/boris/wms_de_bodenrichtwerte?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&LAYERS=brw_wohnbauflaeche,brw_gewerbliche_bauweise,brw_gemischte_bauweise&QUERY_LAYERS=brw_wohnbauflaeche,brw_gewerbliche_bauweise,brw_gemischte_bauweise&I=50&J=50&WIDTH=101&HEIGHT=101&CRS=CRS:84&BBOX=\" + bbox + \"&INFO_FORMAT=application/geo%2Bjson\";\n\nvar request = new HttpRequest();\nrequest.addHeader('Accept: application/geo+json');\nvar response = request.get(url);\n\nif (request.getStatus() !== 200) {\n throw 'Response code: ' + request.getStatus();\n}\n\nreturn response;",
|
|
"timeout": "10s",
|
|
"description": "Script item calculating BBOX and fetching ground values from BORIS NRW."
|
|
},
|
|
{
|
|
"name": "Average Ground Value",
|
|
"type": 18,
|
|
"key": "state.current.averageValue",
|
|
"value_type": 0,
|
|
"history": "7d",
|
|
"units": "€/m²",
|
|
"description": "The average ground value (Bodenrichtwert) extracted from the BORIS NRW GeoJSON response.",
|
|
"master_item": {
|
|
"key": "boris.get"
|
|
},
|
|
"preprocessing": [
|
|
{
|
|
"type": 12,
|
|
"params": ["$.features[0].properties.Bodenrichtwert"]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
```
|