chore: add default filters for host and host group queries

- Introduced `HOST_TYPE_FILTER_DEFAULT` and `HOST_GROUP_FILTER_DEFAULT` constants in the `Config` class.
- Updated resolvers to use these defaults when `tag_hostType` or `search_name` arguments are not provided.
- Added corresponding tests to verify default behavior in host and host group queries.
- Added documentation on overriding 'HOST_GROUP_FILTER_DEFAULT' by explicitly setting the 'search_name' argument in the 'allHostGroups' query.
- Explained the usage of the '*' wildcard in 'search_name' with a concrete example for subgroup matching.
This commit is contained in:
Andreas Hilbig 2026-01-27 18:44:44 +01:00
parent 2a8ff989f3
commit 5e41aa5cc4
5 changed files with 107 additions and 16 deletions

View file

@ -2,6 +2,7 @@
import {createResolvers} from "../api/resolvers.js";
import {zabbixAPI, ZABBIX_EDGE_DEVICE_BASE_GROUP} from "../datasources/zabbix-api.js";
import {QueryAllHostsArgs, QueryAllDevicesArgs, QueryAllHostGroupsArgs} from "../schema/generated/graphql.js";
import {Config} from "../common_utils.js";
// Mocking ZabbixAPI
jest.mock("../datasources/zabbix-api.js", () => ({
@ -14,6 +15,14 @@ jest.mock("../datasources/zabbix-api.js", () => ({
ZABBIX_EDGE_DEVICE_BASE_GROUP: "Roadwork"
}));
// Mocking Config
jest.mock("../common_utils.js", () => ({
Config: {
HOST_TYPE_FILTER_DEFAULT: "Roadwork",
HOST_GROUP_FILTER_DEFAULT: "Roadwork/%"
}
}));
describe("Host and HostGroup Resolvers", () => {
let resolvers: any;
@ -94,6 +103,27 @@ describe("Host and HostGroup Resolvers", () => {
}));
});
test("allHostGroups query - uses default search pattern", async () => {
const mockGroups = [{ groupid: "10", name: "Roadwork/Group 1" }];
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce(mockGroups);
const args: QueryAllHostGroupsArgs = {};
const context = {
zabbixAuthToken: "test-token"
};
const result = await resolvers.Query.allHostGroups(null, args, context);
expect(result).toEqual(mockGroups);
expect(zabbixAPI.post).toHaveBeenCalledWith("hostgroup.get", expect.objectContaining({
body: expect.objectContaining({
params: expect.objectContaining({
search: { name: ["Roadwork/%"] }
})
})
}));
});
test("locations query", async () => {
const mockLocations = [{ name: "Loc 1", latitude: 1.0, longitude: 2.0 }];
(zabbixAPI.getLocations as jest.Mock).mockResolvedValueOnce(mockLocations);