zabbix-graphql-api/docs/queries/sample_import_weather_sensor_template.graphql
Andreas Hilbig ad104acde2 feat: add GroundValueChecker and WeatherSensorDevice with public API integration
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.
2026-02-01 21:07:21 +01:00

89 lines
3.5 KiB
GraphQL

### Mutation
Use this mutation to import a template specifically designed to work with the `WeatherSensorDevice` type. This template retrieves real-time weather data from the public Open-Meteo API using a Zabbix HTTP agent item.
```graphql
mutation ImportWeatherSensorTemplate($templates: [CreateTemplate!]!) {
importTemplates(templates: $templates) {
host
templateid
message
error {
message
code
}
}
}
```
### Variables
The following variables define the `WEATHER_SENSOR` template. It uses the host's user macros (`{$LAT}` and `{$LON}`) to fetch localized weather data.
```json
{
"templates": [
{
"host": "WEATHER_SENSOR",
"name": "Weather Sensor API Template",
"groupNames": ["Templates/External APIs"],
"tags": [
{ "tag": "deviceType", "value": "WeatherSensorDevice" }
],
"macros": [
{ "macro": "{$LAT}", "value": "52.52" },
{ "macro": "{$LON}", "value": "13.41" }
],
"items": [
{
"name": "Open-Meteo API Fetch",
"type": 19,
"key": "weather.get",
"value_type": 4,
"history": "0",
"delay": "1h",
"url": "https://api.open-meteo.com/v1/forecast?latitude={$LAT}&longitude={$LON}&current=temperature_2m,weather_code",
"description": "Master item fetching weather data from Open-Meteo based on host coordinates."
},
{
"name": "Current Temperature",
"type": 18,
"key": "state.current.temperature",
"value_type": 0,
"history": "7d",
"units": "°C",
"description": "The current temperature at the device location.",
"master_item": {
"key": "weather.get"
},
"preprocessing": [
{
"type": 12,
"params": ["$.current.temperature_2m"]
}
]
},
{
"name": "Street Condition Warnings",
"type": 18,
"key": "state.current.streetConditionWarnings",
"value_type": 4,
"history": "7d",
"description": "Human-readable weather warnings or descriptions derived from weather codes.",
"master_item": {
"key": "weather.get"
},
"preprocessing": [
{
"type": 12,
"params": ["$.current.weather_code"]
},
{
"type": 21,
"params": ["var codes = {0:\"Clear\",1:\"Mainly Clear\",2:\"Partly Cloudy\",3:\"Overcast\",45:\"Fog\",48:\"Depositing Rime Fog\",51:\"Light Drizzle\",53:\"Moderate Drizzle\",55:\"Dense Drizzle\",56:\"Light Freezing Drizzle\",57:\"Dense Freezing Drizzle\",61:\"Slight Rain\",63:\"Moderate Rain\",65:\"Heavy Rain\",66:\"Light Freezing Rain\",67:\"Heavy Freezing Rain\",71:\"Slight Snow Fall\",73:\"Moderate Snow Fall\",75:\"Heavy Snow Fall\",77:\"Snow Grains\",80:\"Slight Rain Showers\",81:\"Moderate Rain Showers\",82:\"Violent Rain Showers\",85:\"Slight Snow Showers\",86:\"Heavy Snow Showers\",95:\"Thunderstorm\",96:\"Thunderstorm with Slight Hail\",99:\"Thunderstorm with Heavy Hail\"}; var code = parseInt(value); var warning = codes[code] || \"Unknown\"; if ([56, 57, 66, 67, 71, 73, 75, 77, 85, 86].indexOf(code) !== -1) { return \"WARNING: Slippery Roads (Snow/Ice)\"; } if ([51, 53, 55, 61, 63, 65, 80, 81, 82].indexOf(code) !== -1) { return \"CAUTION: Wet Roads\"; } return warning;"]
}
]
}
]
}
]
}
```