feat: add weather sensor support and fix device status mapping
This commit introduces support for provisioning weather sensors with geo-coordinates
via user macros and fixes a critical mapping bug in device status.
Changes:
- fix: Corrected DeviceStatus enum mapping (0=ENABLED, 1=DISABLED).
- feat: Added 'status' field to CreateTemplateItem input in GraphQL schema.
- feat: Enabled user macro assignment during host and template creation/import.
- feat: Added regression tests for user macro assignment and HTTP agent URL support.
- docs: Updated cookbook and sample queries to use {$LAT} and {$LON} macros.
- test: Added unit tests for macro assignment in HostImporter and TemplateImporter.
- chore: Regenerated GraphQL types.
This commit is contained in:
parent
5da4a17e36
commit
41e4c4da1f
12 changed files with 251 additions and 60 deletions
|
|
@ -200,7 +200,7 @@ This recipe demonstrates how to extend the schema with a new device type that re
|
|||
|
||||
### 📋 Prerequisites
|
||||
- Zabbix GraphQL API is running.
|
||||
- The device has geo-coordinates set in its inventory (`location_lat` and `location_lon`).
|
||||
- The device has geo-coordinates set via user macros (`{$LAT}` and `{$LON}`).
|
||||
|
||||
### 🛠️ Step 1: Define the Schema Extension
|
||||
Create a new `.graphql` file in `schema/extensions/` named `weather_sensor.graphql`.
|
||||
|
|
@ -242,12 +242,12 @@ Use the `importTemplates` mutation to create the `WEATHER_SENSOR` template. This
|
|||
|
||||
**Key Item Configuration**:
|
||||
- **Master Item**: `weather.get` (HTTP Agent)
|
||||
- URL: `https://api.open-meteo.com/v1/forecast?latitude={INVENTORY.LOCATION.LAT}&longitude={INVENTORY.LOCATION.LON}¤t=temperature_2m,weather_code`
|
||||
- URL: `https://api.open-meteo.com/v1/forecast?latitude={$LAT}&longitude={$LON}¤t=temperature_2m,weather_code`
|
||||
- **Dependent Item**: `state.current.temperature` (JSONPath: `$.current.temperature_2m`)
|
||||
- **Dependent Item**: `state.current.streetConditionWarnings` (JavaScript mapping from `$.current.weather_code`)
|
||||
|
||||
### ✅ Step 4: Verification
|
||||
Create a host, assign it coordinates, and query its weather state.
|
||||
Create a host, assign it macros for coordinates, and query its weather state.
|
||||
|
||||
1. **Create Host**:
|
||||
```graphql
|
||||
|
|
@ -257,10 +257,12 @@ Create a host, assign it coordinates, and query its weather state.
|
|||
deviceType: "WeatherSensorDevice",
|
||||
groupNames: ["External Sensors"],
|
||||
templateNames: ["WEATHER_SENSOR"],
|
||||
macros: [
|
||||
{ macro: "{$LAT}", value: "52.52" },
|
||||
{ macro: "{$LON}", value: "13.41" }
|
||||
],
|
||||
location: {
|
||||
name: "Berlin",
|
||||
location_lat: "52.52",
|
||||
location_lon: "13.41"
|
||||
name: "Berlin"
|
||||
}
|
||||
}]) {
|
||||
hostid
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ mutation ImportWeatherSensorTemplate($templates: [CreateTemplate!]!) {
|
|||
```
|
||||
|
||||
### Variables
|
||||
The following variables define the `WEATHER_SENSOR` template. It uses the host's inventory coordinates (`{INVENTORY.LOCATION_LAT}` and `{INVENTORY.LOCATION_LON}`) to fetch localized weather data.
|
||||
The following variables define the `WEATHER_SENSOR` template. It uses the host's user macros (`{$LAT}` and `{$LON}`) to fetch localized weather data.
|
||||
|
||||
```json
|
||||
{
|
||||
|
|
@ -28,6 +28,10 @@ The following variables define the `WEATHER_SENSOR` template. It uses the host's
|
|||
"tags": [
|
||||
{ "tag": "deviceType", "value": "WeatherSensorDevice" }
|
||||
],
|
||||
"macros": [
|
||||
{ "macro": "{$LAT}", "value": "52.52" },
|
||||
{ "macro": "{$LON}", "value": "13.41" }
|
||||
],
|
||||
"items": [
|
||||
{
|
||||
"name": "Open-Meteo API Fetch",
|
||||
|
|
@ -36,7 +40,7 @@ The following variables define the `WEATHER_SENSOR` template. It uses the host's
|
|||
"value_type": 4,
|
||||
"history": "0",
|
||||
"delay": "1m",
|
||||
"url": "https://api.open-meteo.com/v1/forecast?latitude={INVENTORY.LOCATION.LAT}&longitude={INVENTORY.LOCATION.LON}¤t=temperature_2m,weather_code",
|
||||
"url": "https://api.open-meteo.com/v1/forecast?latitude={$LAT}&longitude={$LON}¤t=temperature_2m,weather_code",
|
||||
"description": "Master item fetching weather data from Open-Meteo based on host coordinates."
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue