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:
Andreas Hilbig 2026-02-01 16:23:35 +01:00
parent 5da4a17e36
commit 41e4c4da1f
12 changed files with 251 additions and 60 deletions

View file

@ -79,4 +79,38 @@ describe("HostImporter", () => {
expect(result).toHaveLength(1);
expect(result![0].hostid).toBe("401");
});
test("importHosts - with macros", async () => {
const hosts = [{
deviceKey: "DeviceMacro",
deviceType: "Type1",
groupNames: ["Group1"],
macros: [
{ macro: "{$LAT}", value: "52.52" },
{ macro: "{$LON}", value: "13.41" }
]
}];
// Mocking group lookup
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce([{ groupid: "201", name: ZABBIX_EDGE_DEVICE_BASE_GROUP }]);
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce([{ groupid: "202", name: ZABBIX_EDGE_DEVICE_BASE_GROUP + "/Group1" }]);
// Mocking template lookup
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce([{ templateid: "301" }]);
// Mocking host.create
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce({ hostids: ["402"] });
const result = await HostImporter.importHosts(hosts, "token");
expect(result).toHaveLength(1);
expect(result![0].hostid).toBe("402");
// Verify that host.create was called with macros
const hostCreateCall = (zabbixAPI.post as jest.Mock).mock.calls.find(call => call[1].body.method === "host.create");
expect(hostCreateCall[1].body.params.macros).toEqual([
{ macro: "{$LAT}", value: "52.52" },
{ macro: "{$LON}", value: "13.41" }
]);
});
});

View file

@ -163,4 +163,32 @@ describe("TemplateImporter", () => {
expect(result![0].message).toContain("Invalid params.");
expect(result![0].message).toContain("the parameter \"key_\" is missing.");
});
test("importTemplates - with macros", async () => {
const templates = [{
host: "TemplateWithMacros",
groupNames: ["Group1"],
macros: [
{ macro: "{$LAT}", value: "52.52" },
{ macro: "{$LON}", value: "13.41" }
]
}];
// Mocking group.get
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce([{ groupid: "201", name: "Group1" }]);
// Mocking template.create
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce({ templateids: ["302"] });
const result = await TemplateImporter.importTemplates(templates, "token");
expect(result).toHaveLength(1);
expect(result![0].templateid).toBe("302");
// Verify that template.create was called with macros
const templateCreateCall = (zabbixAPI.post as jest.Mock).mock.calls.find(call => call[1].body.method === "template.create");
expect(templateCreateCall[1].body.params.macros).toEqual([
{ macro: "{$LAT}", value: "52.52" },
{ macro: "{$LON}", value: "13.41" }
]);
});
});