feat: add template and template group management via GraphQL

- Implemented GraphQL endpoints for importing, querying, and deleting Zabbix templates and template groups. - Added support for full template data import, including items, preprocessing steps, tags, and linked templates. - Implemented dependent item support by deferred creation logic in the template importer. - Added ability to query templates and template groups with name pattern filtering (supporting Zabbix wildcards). - Implemented batch deletion for templates and template groups by ID or name pattern. - Improved error reporting by including detailed Zabbix API error data in GraphQL responses. - Added comprehensive unit and integration tests covering all new functionality. - Provided GraphQL sample queries and mutations in the 'docs' directory for all new endpoints.
This commit is contained in:
Andreas Hilbig 2026-01-24 15:42:13 +01:00
parent e641f8e610
commit a3ed4886a3
22 changed files with 2450 additions and 20 deletions

View file

@ -29,12 +29,152 @@ type Mutation {
importHosts(hosts: [CreateHost!]!):[ImportHostResponse!]
importUserRights(input: UserRightsInput!, dryRun: Boolean! = true): ImportUserRightsResult
"""
(Mass) Import template groups
and assign them by groupid or name.
Return value: If no error occurs a groupid be returned for each created group,
otherwise the return object will contain an error message
Authentication: By zbx_session - cookie or zabbix-auth-token - header
"""
importTemplateGroups(templateGroups: [CreateTemplateGroup!]!):[CreateTemplateGroupResponse!]
"""
(Mass) Import templates.
Return value: If no error occurs a templateid will be returned for each created template,
otherwise the return object will contain an error message.
Authentication: By zbx_session - cookie or zabbix-auth-token - header
"""
importTemplates(templates: [CreateTemplate!]!):[ImportTemplateResponse!]
"""
Delete templates.
Authentication: By zbx_session - cookie or zabbix-auth-token - header
"""
deleteTemplates(templateids: [Int!], name_pattern: String): [DeleteResponse!]
"""
Delete template groups.
Authentication: By zbx_session - cookie or zabbix-auth-token - header
"""
deleteTemplateGroups(groupids: [Int!], name_pattern: String): [DeleteResponse!]
}
####################################################################
# Input types used for importXXX - and storeXXX - Mutations
####################################################################
type DeleteResponse {
id: Int!
message: String
error: ApiError
}
input CreateTemplateGroup {
"""
Name of the template group
"""
groupName: String!
"""
Internally used unique id
(will be assigned by Zabbix if empty)
"""
uuid: String
}
input CreateTemplate {
"""
Name of the template
"""
host: String!
"""
Visible name of the template
"""
name: String
"""
groupNames is used to assign the created object
to a template group.
"""
groupNames: [String!]!
"""
Optionally the internal groupids can be passed - in this case the
groupName is ignored
"""
groupids: [Int]
"""
Internally used unique id
(will be assigned by Zabbix if empty)
"""
uuid: String
"""
Template items
"""
items: [CreateTemplateItem!]
"""
Linked templates
"""
templates: [CreateLinkedTemplate!]
"""
Template tags
"""
tags: [CreateTag!]
}
input CreateTemplateItem {
uuid: String
name: String!
type: Int
key: String!
value_type: Int
history: String
units: String
delay: String
description: String
preprocessing: [CreateItemPreprocessing!]
tags: [CreateTag!]
master_item: CreateMasterItem
}
input CreateMasterItem {
key: String!
}
input CreateItemPreprocessing {
type: Int!
params: [String!]!
error_handler: Int
error_handler_params: String
}
input CreateLinkedTemplate {
name: String!
}
input CreateTag {
tag: String!
value: String
}
type ImportTemplateResponse {
host: String!
templateid: String
message: String
error: ApiError
}
type CreateTemplateGroupResponse {
groupName: String!
groupid: Int
message: String
error: ApiError
}
input CreateHostGroup {
"""
Name of the host group

View file

@ -113,5 +113,15 @@ type Query {
exclude_groups_pattern: Regex allowing to exclude all matching hostgroups from group permissions
"""
exportUserRights(name_pattern: String = "" exclude_hostgroups_pattern: String = ""): UserRights
"""
Get templates.
"""
templates(hostids: [Int], name_pattern: String): [Template]
"""
Get template groups.
"""
allTemplateGroups(name_pattern: String): [HostGroup]
}