feat: add Zabbix 7.4 documentation samples and importHostGroups MCP tool

This commit introduces a comprehensive set of GraphQL query and mutation samples based on the official Zabbix 7.4 API documentation, along with testing and automation improvements.

Changes:

- Documentation:

  - Added 21 GraphQL sample files in docs/queries/from_zabbix_docs/ covering various Zabbix API operations.

  - Updated docs/howtos/cookbook.md with a new recipe for executing these documentation samples.

- AI & MCP:

  - Added mcp/operations/importHostGroups.graphql to enable host group import via MCP tools.

- Testing:

  - Added src/test/zabbix_docs_samples.test.ts to automatically validate all documentation samples against the GraphQL schema.
This commit is contained in:
Andreas Hilbig 2026-01-31 10:52:56 +01:00
parent 9a79fc8e4c
commit b56255ffaa
24 changed files with 626 additions and 0 deletions

View file

@ -0,0 +1,27 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/host/get
### Query
```graphql
query GetAllDevices($name_pattern: String) {
allDevices(name_pattern: $name_pattern) {
hostid
host
name
deviceType
state {
operational {
temperature
voltage
signalstrength
}
}
}
}
```
### Variables
```json
{
"name_pattern": "Device%"
}
```

View file

@ -0,0 +1,18 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/hostgroup/get
### Query
```graphql
query GetAllHostGroups($search_name: String) {
allHostGroups(search_name: $search_name) {
groupid
name
}
}
```
### Variables
```json
{
"search_name": "Zabbix%"
}
```

View file

@ -0,0 +1,34 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/host/get
### Query
```graphql
query GetAllHosts($name_pattern: String, $groupids: [Int!]) {
allHosts(name_pattern: $name_pattern, groupids: $groupids) {
hostid
host
name
deviceType
hostgroups {
groupid
name
}
... on ZabbixHost {
tags
items {
itemid
name
key_
lastvalue
}
}
}
}
```
### Variables
```json
{
"name_pattern": "Linux%",
"groupids": [2]
}
```

View file

@ -0,0 +1,18 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/templategroup/get
### Query
```graphql
query GetAllTemplateGroups($name_pattern: String) {
allTemplateGroups(name_pattern: $name_pattern) {
groupid
name
}
}
```
### Variables
```json
{
"name_pattern": "Templates%"
}
```

View file

@ -0,0 +1,23 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/host/create
### Query
```graphql
mutation CreateHost($host: String!, $hostgroupids: [Int!]!, $templateids: [Int!]!) {
createHost(
host: $host,
hostgroupids: $hostgroupids,
templateids: $templateids
) {
hostids
}
}
```
### Variables
```json
{
"host": "Linux server",
"hostgroupids": [50],
"templateids": [20045]
}
```

View file

@ -0,0 +1,18 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/templategroup/delete
### Query
```graphql
mutation DeleteTemplateGroups($groupids: [Int!]) {
deleteTemplateGroups(groupids: $groupids) {
id
message
}
}
```
### Variables
```json
{
"groupids": [10, 11]
}
```

View file

@ -0,0 +1,18 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/template/delete
### Query
```graphql
mutation DeleteTemplates($templateids: [Int!]) {
deleteTemplates(templateids: $templateids) {
id
message
}
}
```
### Variables
```json
{
"templateids": [10001, 10002]
}
```

View file

@ -0,0 +1,24 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/history/get
### Query
```graphql
query ExportHostValueHistory($host_filter: [String!], $itemKey_filter: [String!], $limit: Int) {
exportHostValueHistory(
host_filter: $host_filter,
itemKey_filter: $itemKey_filter,
limit: $limit,
type: FLOAT
) {
result
}
}
```
### Variables
```json
{
"host_filter": ["Linux server"],
"itemKey_filter": ["system.cpu.load[all,avg1]"],
"limit": 10
}
```

View file

@ -0,0 +1,28 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/usergroup/get
### Query
```graphql
query ExportUserRights($name_pattern: String) {
exportUserRights(name_pattern: $name_pattern) {
userGroups {
usrgrpid
name
hostgroup_rights {
name
permission
}
}
userRoles {
roleid
name
}
}
}
```
### Variables
```json
{
"name_pattern": "Zabbix%"
}
```

View file

@ -0,0 +1,20 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/usergroup/get
### Query
```graphql
query HasPermissions($permissions: [PermissionRequest!]!) {
hasPermissions(permissions: $permissions)
}
```
### Variables
```json
{
"permissions": [
{
"objectName": "Read-Only-Access",
"permission": "READ"
}
]
}
```

View file

@ -0,0 +1,26 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/hostgroup/create
### Query
```graphql
mutation ImportHostGroups($hostGroups: [CreateHostGroup!]!) {
importHostGroups(hostGroups: $hostGroups) {
groupName
groupid
message
}
}
```
### Variables
```json
{
"hostGroups": [
{
"groupName": "New Host Group 1"
},
{
"groupName": "New Host Group 2"
}
]
}
```

View file

@ -0,0 +1,30 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/host/create
### Query
```graphql
mutation ImportHosts($hosts: [CreateHost!]!) {
importHosts(hosts: $hosts) {
hostid
deviceKey
message
}
}
```
### Variables
```json
{
"hosts": [
{
"deviceKey": "Host 1",
"deviceType": "GenericDevice",
"groupNames": ["Zabbix servers"]
},
{
"deviceKey": "Host 2",
"deviceType": "GenericDevice",
"groupNames": ["Zabbix servers"]
}
]
}
```

View file

@ -0,0 +1,23 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/templategroup/create
### Query
```graphql
mutation ImportTemplateGroups($templateGroups: [CreateTemplateGroup!]!) {
importTemplateGroups(templateGroups: $templateGroups) {
groupName
groupid
message
}
}
```
### Variables
```json
{
"templateGroups": [
{
"groupName": "New Template Group 1"
}
]
}
```

View file

@ -0,0 +1,32 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/template/create
### Query
```graphql
mutation ImportTemplates($templates: [CreateTemplate!]!) {
importTemplates(templates: $templates) {
templateid
host
message
}
}
```
### Variables
```json
{
"templates": [
{
"host": "New Template 1",
"groupNames": ["Templates/Operating systems"],
"items": [
{
"name": "Custom item",
"key": "custom.item",
"value_type": 3,
"history": "90d"
}
]
}
]
}
```

View file

@ -0,0 +1,45 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/usergroup/create
### Query
```graphql
mutation ImportUserRights($input: UserRightsInput!, $dryRun: Boolean!) {
importUserRights(input: $input, dryRun: $dryRun) {
userGroups {
id
name
message
}
userRoles {
id
name
message
}
}
}
```
### Variables
```json
{
"dryRun": true,
"input": {
"userGroups": [
{
"name": "New User Group",
"hostgroup_rights": [
{
"name": "Zabbix servers",
"permission": "READ"
}
]
}
],
"userRoles": [
{
"name": "New Role",
"type": 1
}
]
}
}
```

View file

@ -0,0 +1,19 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/host/get
### Query
```graphql
query GetLocations($name_pattern: String) {
locations(name_pattern: $name_pattern) {
name
latitude
longitude
}
}
```
### Variables
```json
{
"name_pattern": "Riga%"
}
```

View file

@ -0,0 +1,16 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/user/login
### Query
```graphql
query Login($username: String!, $password: String!) {
login(username: $username, password: $password)
}
```
### Variables
```json
{
"username": "Admin",
"password": "zabbix_password"
}
```

View file

@ -0,0 +1,13 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/user/logout
### Query
```graphql
query Logout {
logout
}
```
### Variables
```json
{}
```

View file

@ -0,0 +1,18 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/template/get
### Query
```graphql
query GetTemplates($name_pattern: String) {
templates(name_pattern: $name_pattern) {
templateid
name
}
}
```
### Variables
```json
{
"name_pattern": "Template OS%"
}
```

View file

@ -0,0 +1,18 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/user/get
### Query
```graphql
query GetUserPermissions($objectNames: [String!]) {
userPermissions(objectNames: $objectNames) {
objectName
permission
}
}
```
### Variables
```json
{
"objectNames": ["Read-Only-Access"]
}
```

View file

@ -0,0 +1,13 @@
# Source: https://www.zabbix.com/documentation/7.4/en/manual/api/reference/apiinfo/version
### Query
```graphql
query GetZabbixVersion {
zabbixVersion
}
```
### Variables
```json
{}
```