docs: add TSDoc to core components
- Added detailed JSDoc documentation to all core datasource classes in src/datasources/ - Documented execution logic classes in src/execution/ - Added TSDoc to API utility functions and resolvers in src/api/ - Documented shared models and enums in src/model/
This commit is contained in:
parent
3c3cb7c753
commit
0acef818c6
27 changed files with 689 additions and 19 deletions
47
.idea/workspace.xml
generated
47
.idea/workspace.xml
generated
|
|
@ -6,16 +6,31 @@
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="d7a71994-2699-4ae4-9fd2-ee13b7f33d35" name="Changes" comment="docs: refactor documentation and upgrade to Node.js 24 This commit upgrades the project to Node.js 24 (LTS) and performs a major refactoring of the documentation to support both advanced users and AI-based automation (MCP). Changes: - Environment & CI/CD: - Set Node.js version to >=24 in package.json and .nvmrc. - Updated Dockerfile to use Node 24 base image. - Updated @types/node to ^24.10.9. - Documentation: - Refactored README.md with comprehensive technical reference, configuration details, and Zabbix-to-GraphQL mapping. - Created docs/howtos/cookbook.md with practical recipes for common tasks and AI test generation. - Updated docs/howtos/mcp.md to emphasize GraphQL's advantages for AI agents and Model Context Protocol. - Added readme.improvement.plan.md to track documentation evolution. - Enhanced all how-to guides with improved cross-references and up-to-date information. - Guidelines: - Updated .junie/guidelines.md with Node 24 requirements and enhanced commit message standards (Conventional Commits 1.0.0). - Infrastructure & Code: - Updated docker-compose.yml with Apollo MCP server integration. - Refined configuration and schema handling in src/api/ and src/datasources/. - Synchronized generated TypeScript types with schema updates.">
|
<list default="true" id="d7a71994-2699-4ae4-9fd2-ee13b7f33d35" name="Changes" comment="docs: refactor documentation and upgrade to Node.js 24 This commit upgrades the project to Node.js 24 (LTS) and performs a major refactoring of the documentation to support both advanced users and AI-based automation (MCP). Changes: - Environment & CI/CD: - Set Node.js version to >=24 in package.json and .nvmrc. - Updated Dockerfile to use Node 24 base image. - Updated @types/node to ^24.10.9. - Documentation: - Refactored README.md with comprehensive technical reference, configuration details, and Zabbix-to-GraphQL mapping. - Created docs/howtos/cookbook.md with practical recipes for common tasks and AI test generation. - Updated docs/howtos/mcp.md to emphasize GraphQL's advantages for AI agents and Model Context Protocol. - Added readme.improvement.plan.md to track documentation evolution. - Enhanced all how-to guides with improved cross-references and up-to-date information. - Guidelines: - Updated .junie/guidelines.md with Node 24 requirements and enhanced commit message standards (Conventional Commits 1.0.0). - Infrastructure & Code: - Updated docker-compose.yml with Apollo MCP server integration. - Refined configuration and schema handling in src/api/ and src/datasources/. - Synchronized generated TypeScript types with schema updates.">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/docs/queries/sample_import_simulated_bt_template.graphql" beforeDir="false" afterPath="$PROJECT_DIR$/docs/queries/sample_import_simulated_bt_template.graphql" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/docs/howtos/local_development.md" beforeDir="false" afterPath="$PROJECT_DIR$/docs/howtos/local_development.md" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/api/graphql_utils.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/graphql_utils.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/docs/howtos/maintenance.md" beforeDir="false" afterPath="$PROJECT_DIR$/docs/howtos/maintenance.md" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/api/resolver_helpers.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/resolver_helpers.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/roadmap.md" beforeDir="false" afterPath="$PROJECT_DIR$/roadmap.md" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/api/resolvers.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/resolvers.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/datasources/graphql-params-to-zabbix-output.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/graphql-params-to-zabbix-output.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-api.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-api.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-history.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-history.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-hostgroups.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-hostgroups.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-hosts.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-hosts.ts" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-hosts.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-hosts.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-items.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-items.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-module.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-module.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-permissions.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-permissions.ts" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-permissions.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-permissions.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-request.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-request.ts" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-request.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-request.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-script.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-script.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-templates.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-templates.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-usergroups.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-usergroups.ts" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-usergroups.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-usergroups.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/test/history_push.test.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/history_push.test.ts" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/datasources/zabbix-userroles.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-userroles.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/test/zabbix_6_0_compatibility.test.ts" beforeDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/execution/host_deleter.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/execution/host_deleter.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/execution/host_exporter.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/execution/host_exporter.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/execution/host_importer.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/execution/host_importer.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/execution/regression_test_executor.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/execution/regression_test_executor.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/execution/smoketest_executor.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/execution/smoketest_executor.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/execution/template_deleter.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/execution/template_deleter.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/execution/template_importer.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/execution/template_importer.ts" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/model/model_enum_values.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/model/model_enum_values.ts" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|
@ -26,7 +41,7 @@
|
||||||
<execution />
|
<execution />
|
||||||
</component>
|
</component>
|
||||||
<component name="EmbeddingIndexingInfo">
|
<component name="EmbeddingIndexingInfo">
|
||||||
<option name="cachedIndexableFilesCount" value="172" />
|
<option name="cachedIndexableFilesCount" value="175" />
|
||||||
<option name="fileBasedEmbeddingIndicesEnabled" value="true" />
|
<option name="fileBasedEmbeddingIndicesEnabled" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
|
|
@ -52,13 +67,7 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="McpProjectServerCommands">
|
<component name="McpProjectServerCommands">
|
||||||
<commands />
|
<commands />
|
||||||
<urls>
|
<urls />
|
||||||
<McpServerConfigurationProperties>
|
|
||||||
<option name="allowedToolsNames" />
|
|
||||||
<option name="enabled" value="true" />
|
|
||||||
<option name="name" value="zabbix-graphql" />
|
|
||||||
</McpServerConfigurationProperties>
|
|
||||||
</urls>
|
|
||||||
</component>
|
</component>
|
||||||
<component name="ProblemsViewState">
|
<component name="ProblemsViewState">
|
||||||
<option name="selectedTabId" value="CurrentFile" />
|
<option name="selectedTabId" value="CurrentFile" />
|
||||||
|
|
@ -90,7 +99,7 @@
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
||||||
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
|
||||||
"git-widget-placeholder": "feature-improve-zabbix-version-compatiblity",
|
"git-widget-placeholder": "main",
|
||||||
"go.import.settings.migrated": "true",
|
"go.import.settings.migrated": "true",
|
||||||
"javascript.preferred.runtime.type.id": "node",
|
"javascript.preferred.runtime.type.id": "node",
|
||||||
"junie.onboarding.icon.badge.shown": "true",
|
"junie.onboarding.icon.badge.shown": "true",
|
||||||
|
|
@ -106,7 +115,7 @@
|
||||||
"npm.copy-schema.executor": "Run",
|
"npm.copy-schema.executor": "Run",
|
||||||
"npm.prod.executor": "Run",
|
"npm.prod.executor": "Run",
|
||||||
"npm.test.executor": "Run",
|
"npm.test.executor": "Run",
|
||||||
"settings.editor.selected.configurable": "junie.mcp",
|
"settings.editor.selected.configurable": "ml.llm.mcp",
|
||||||
"settings.editor.splitter.proportion": "0.23751687",
|
"settings.editor.splitter.proportion": "0.23751687",
|
||||||
"to.speed.mode.migration.done": "true",
|
"to.speed.mode.migration.done": "true",
|
||||||
"ts.external.directory.path": "\\\\wsl.localhost\\Ubuntu\\home\\ahilbig\\git\\vcr\\zabbix-graphql-api\\node_modules\\typescript\\lib",
|
"ts.external.directory.path": "\\\\wsl.localhost\\Ubuntu\\home\\ahilbig\\git\\vcr\\zabbix-graphql-api\\node_modules\\typescript\\lib",
|
||||||
|
|
@ -227,6 +236,8 @@
|
||||||
<workItem from="1770129804879" duration="13000" />
|
<workItem from="1770129804879" duration="13000" />
|
||||||
<workItem from="1770129846593" duration="5283000" />
|
<workItem from="1770129846593" duration="5283000" />
|
||||||
<workItem from="1770167580486" duration="16982000" />
|
<workItem from="1770167580486" duration="16982000" />
|
||||||
|
<workItem from="1770799063115" duration="1101000" />
|
||||||
|
<workItem from="1770800423630" duration="4799000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="chore: Update IntelliJ workspace settings and add GitHub Actions workflow for Docker deployment">
|
<task id="LOCAL-00001" summary="chore: Update IntelliJ workspace settings and add GitHub Actions workflow for Docker deployment">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
|
@ -491,12 +502,12 @@
|
||||||
<breakpoints>
|
<breakpoints>
|
||||||
<line-breakpoint enabled="true" type="javascript">
|
<line-breakpoint enabled="true" type="javascript">
|
||||||
<url>file://$PROJECT_DIR$/src/datasources/zabbix-request.ts</url>
|
<url>file://$PROJECT_DIR$/src/datasources/zabbix-request.ts</url>
|
||||||
<line>135</line>
|
<line>152</line>
|
||||||
<option name="timeStamp" value="5" />
|
<option name="timeStamp" value="5" />
|
||||||
</line-breakpoint>
|
</line-breakpoint>
|
||||||
<line-breakpoint enabled="true" type="javascript">
|
<line-breakpoint enabled="true" type="javascript">
|
||||||
<url>file://$PROJECT_DIR$/src/datasources/zabbix-request.ts</url>
|
<url>file://$PROJECT_DIR$/src/datasources/zabbix-request.ts</url>
|
||||||
<line>276</line>
|
<line>338</line>
|
||||||
<option name="timeStamp" value="6" />
|
<option name="timeStamp" value="6" />
|
||||||
</line-breakpoint>
|
</line-breakpoint>
|
||||||
</breakpoints>
|
</breakpoints>
|
||||||
|
|
|
||||||
1
.output.txt
Normal file
1
.output.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
{"data":{"runAllRegressionTests":{"success":true,"message":"Regression tests passed successfully","steps":[{"name":"REG-LOC: Locations query argument order","success":true,"message":"Locations query executed without session error"},{"name":"REG-TEMP: Template technical name lookup","success":true,"message":"Template REG_TEMP_o1fedi created and searchable by technical name"},{"name":"REG-HTTP: HTTP Agent URL support","success":true,"message":"Template REG_HTTP_cnbxkf with HTTP Agent item created successfully"},{"name":"REG-MACRO: User Macro assignment","success":true,"message":"Macros successfully assigned to template and host"},{"name":"REG-HOST: Host retrieval and visibility (incl. groups and templates)","success":true,"message":"Host REG_HOST_ngacal retrieved successfully with groups and templates"},{"name":"REG-ITEM-META: Item metadata (preprocessing, units, description, error)","success":true,"message":"Item metadata successfully retrieved including preprocessing and units"},{"name":"REG-OPT: Query Optimization and Skippable Parameters","success":true,"message":"Optimization logic correctly filters output fields and skippable parameters"},{"name":"REG-EMPTY: Empty result handling","success":true,"message":"Correctly returned empty array for non-existent host"},{"name":"REG-DEP: Dependent Items support","success":true,"message":"Template with master and dependent items imported successfully"},{"name":"REG-STATE: State sub-properties retrieval (indirect dependency)","success":true,"message":"State sub-properties correctly trigger item fetching and are available"},{"name":"REG-OPT-NEG: Negative Optimization - items not requested (allDevices)","success":true,"message":"Optimization correctly omits items when neither items nor state are requested"},{"name":"REG-DEV-FILTER: allDevices deviceType filter","success":true,"message":"allDevices correctly filtered out hosts without deviceType tag"},{"name":"REG-PUSH: pushHistory mutation","success":true,"message":"Successfully pushed history data to trapper item"},{"name":"Create Host Group","success":true,"message":"Host group REG_GROUP_l5t5hv created"}]}}}
|
||||||
|
|
@ -36,7 +36,7 @@ We use the `state.current.json_geojson` key for the trapper item. The `json_` pr
|
||||||
"type": 2,
|
"type": 2,
|
||||||
"key": "state.current.json_geojson",
|
"key": "state.current.json_geojson",
|
||||||
"value_type": 4,
|
"value_type": 4,
|
||||||
"history": "7d",
|
"history": "31d",
|
||||||
"description": "Trapper item receiving GeoJSON payloads"
|
"description": "Trapper item receiving GeoJSON payloads"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
import {FieldNode, GraphQLResolveInfo, InlineFragmentNode} from "graphql";
|
import {FieldNode, GraphQLResolveInfo, InlineFragmentNode} from "graphql";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the requested fields from a GraphQL resolve info object, including nested fields and fragments.
|
||||||
|
* @param info - The GraphQL resolve info.
|
||||||
|
* @returns An array of strings representing the full paths of the requested fields.
|
||||||
|
*/
|
||||||
export function getRequestedFields(info: GraphQLResolveInfo): string[] {
|
export function getRequestedFields(info: GraphQLResolveInfo): string[] {
|
||||||
if (!info || !info.fieldNodes) return [];
|
if (!info || !info.fieldNodes) return [];
|
||||||
const fields: string[] = [];
|
const fields: string[] = [];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@ import {isObjectType} from "graphql";
|
||||||
import {logger} from "../logging/logger.js";
|
import {logger} from "../logging/logger.js";
|
||||||
import {Device, Host} from "../schema/generated/graphql.js";
|
import {Device, Host} from "../schema/generated/graphql.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if a host object is a specialized device.
|
||||||
|
* @param value - The host object to check.
|
||||||
|
* @returns True if the host is a device, false otherwise.
|
||||||
|
*/
|
||||||
export const isDevice = (value: Host | undefined): value is Device => !!(value as Device)?.deviceType;
|
export const isDevice = (value: Host | undefined): value is Device => !!(value as Device)?.deviceType;
|
||||||
/*
|
/*
|
||||||
As a default all . - seperators within a key shall be replaced by a Capital letter of the following word
|
As a default all . - seperators within a key shall be replaced by a Capital letter of the following word
|
||||||
|
|
@ -49,6 +54,13 @@ export function createHierarchicalValueFieldResolver(
|
||||||
return resolver
|
return resolver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps Zabbix item values to GraphQL type fields based on the field name.
|
||||||
|
* @param fieldname - The name of the GraphQL field.
|
||||||
|
* @param parent - The parent object containing Zabbix items.
|
||||||
|
* @param objectTypeRequested - Whether the requested field is an object type.
|
||||||
|
* @returns The mapped value or hierarchical object.
|
||||||
|
*/
|
||||||
export function zabbixItemValueSourceFieldMapper(
|
export function zabbixItemValueSourceFieldMapper(
|
||||||
fieldname: string,
|
fieldname: string,
|
||||||
parent: {
|
parent: {
|
||||||
|
|
@ -76,6 +88,13 @@ export function zabbixItemValueSourceFieldMapper(
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps Zabbix tag values to GraphQL type fields based on the field name.
|
||||||
|
* @param fieldname - The name of the GraphQL field.
|
||||||
|
* @param tags - The array of Zabbix tags.
|
||||||
|
* @param objectTypeRequested - Whether the requested field is an object type.
|
||||||
|
* @returns The mapped value or hierarchical object.
|
||||||
|
*/
|
||||||
export function zabbixTagsValueSourceFieldMapper(
|
export function zabbixTagsValueSourceFieldMapper(
|
||||||
fieldname: string,
|
fieldname: string,
|
||||||
tags: [{ tag: string, value: any }],
|
tags: [{ tag: string, value: any }],
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,11 @@ import {Config} from "../common_utils.js";
|
||||||
import {GraphqlParamsToNeededZabbixOutput} from "../datasources/graphql-params-to-zabbix-output.js";
|
import {GraphqlParamsToNeededZabbixOutput} from "../datasources/graphql-params-to-zabbix-output.js";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the GraphQL resolvers for the Zabbix API.
|
||||||
|
* Defines how queries, mutations, and types are resolved by interacting with the Zabbix data sources and execution logic.
|
||||||
|
* @returns The GraphQL resolvers object.
|
||||||
|
*/
|
||||||
export function createResolvers(): Resolvers {
|
export function createResolvers(): Resolvers {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,42 @@
|
||||||
import {GraphQLResolveInfo} from "graphql";
|
import {GraphQLResolveInfo} from "graphql";
|
||||||
import {getRequestedFields} from "../api/graphql_utils.js";
|
import {getRequestedFields} from "../api/graphql_utils.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class to map GraphQL request information to the fields needed from Zabbix.
|
||||||
|
*/
|
||||||
export class GraphqlParamsToNeededZabbixOutput {
|
export class GraphqlParamsToNeededZabbixOutput {
|
||||||
|
/**
|
||||||
|
* Maps the requested fields for allHosts query.
|
||||||
|
* @param info - The GraphQL resolve info.
|
||||||
|
* @returns An array of field names.
|
||||||
|
*/
|
||||||
static mapAllHosts(info: GraphQLResolveInfo): string[] {
|
static mapAllHosts(info: GraphQLResolveInfo): string[] {
|
||||||
return getRequestedFields(info);
|
return getRequestedFields(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the requested fields for allDevices query.
|
||||||
|
* @param info - The GraphQL resolve info.
|
||||||
|
* @returns An array of field names.
|
||||||
|
*/
|
||||||
static mapAllDevices(info: GraphQLResolveInfo): string[] {
|
static mapAllDevices(info: GraphQLResolveInfo): string[] {
|
||||||
return getRequestedFields(info);
|
return getRequestedFields(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the requested fields for allHostGroups query.
|
||||||
|
* @param info - The GraphQL resolve info.
|
||||||
|
* @returns An array of field names.
|
||||||
|
*/
|
||||||
static mapAllHostGroups(info: GraphQLResolveInfo): string[] {
|
static mapAllHostGroups(info: GraphQLResolveInfo): string[] {
|
||||||
return getRequestedFields(info);
|
return getRequestedFields(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the requested fields for templates query.
|
||||||
|
* @param info - The GraphQL resolve info.
|
||||||
|
* @returns An array of field names.
|
||||||
|
*/
|
||||||
static mapTemplates(info: GraphQLResolveInfo): string[] {
|
static mapTemplates(info: GraphQLResolveInfo): string[] {
|
||||||
return getRequestedFields(info);
|
return getRequestedFields(info);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,18 @@ export const zabbixPrivilegeEscalationToken = Config.ZABBIX_PRIVILEGE_ESCALATION
|
||||||
export const ZABBIX_EDGE_DEVICE_BASE_GROUP = Config.ZABBIX_EDGE_DEVICE_BASE_GROUP || Config.ZABBIX_ROADWORK_BASE_GROUP || "Roadwork"
|
export const ZABBIX_EDGE_DEVICE_BASE_GROUP = Config.ZABBIX_EDGE_DEVICE_BASE_GROUP || Config.ZABBIX_ROADWORK_BASE_GROUP || "Roadwork"
|
||||||
export const FIND_ZABBIX_EDGE_DEVICE_BASE_GROUP_PREFIX = new RegExp(`^(${ZABBIX_EDGE_DEVICE_BASE_GROUP})\/`)
|
export const FIND_ZABBIX_EDGE_DEVICE_BASE_GROUP_PREFIX = new RegExp(`^(${ZABBIX_EDGE_DEVICE_BASE_GROUP})\/`)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data source for interacting with the Zabbix API.
|
||||||
|
* Extends RESTDataSource to handle JSON-RPC requests to Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixAPI
|
export class ZabbixAPI
|
||||||
extends RESTDataSource {
|
extends RESTDataSource {
|
||||||
private static readonly MAX_LOG_REQUEST_BODY_LIMIT_LENGTH = 500
|
private static readonly MAX_LOG_REQUEST_BODY_LIMIT_LENGTH = 500
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param baseURL - The base URL of the Zabbix API.
|
||||||
|
* @param config - Optional data source configuration.
|
||||||
|
*/
|
||||||
constructor(public baseURL: string, config?: DataSourceConfig) {
|
constructor(public baseURL: string, config?: DataSourceConfig) {
|
||||||
super(config);
|
super(config);
|
||||||
logger.info("Connecting to Zabbix at url=" + this.baseURL)
|
logger.info("Connecting to Zabbix at url=" + this.baseURL)
|
||||||
|
|
@ -82,6 +90,10 @@ export class ZabbixAPI
|
||||||
|
|
||||||
private static version: string | undefined
|
private static version: string | undefined
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the Zabbix API version.
|
||||||
|
* @returns A promise that resolves to the version string.
|
||||||
|
*/
|
||||||
async getVersion(): Promise<string> {
|
async getVersion(): Promise<string> {
|
||||||
if (!ZabbixAPI.version) {
|
if (!ZabbixAPI.version) {
|
||||||
const response = await this.requestByPath<string>("apiinfo.version")
|
const response = await this.requestByPath<string>("apiinfo.version")
|
||||||
|
|
@ -94,14 +106,39 @@ export class ZabbixAPI
|
||||||
return ZabbixAPI.version
|
return ZabbixAPI.version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a Zabbix API request.
|
||||||
|
* @param zabbixRequest - The request object to execute.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param throwApiError - Whether to throw an error if the request fails (default: true).
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns A promise that resolves to the result or an error result.
|
||||||
|
*/
|
||||||
async executeRequest<T extends ZabbixResult, A extends ParsedArgs>(zabbixRequest: ZabbixRequest<T, A>, args?: A, throwApiError: boolean = true, output?: string[]): Promise<T | ZabbixErrorResult> {
|
async executeRequest<T extends ZabbixResult, A extends ParsedArgs>(zabbixRequest: ZabbixRequest<T, A>, args?: A, throwApiError: boolean = true, output?: string[]): Promise<T | ZabbixErrorResult> {
|
||||||
return throwApiError ? zabbixRequest.executeRequestThrowError(this, args, output) : zabbixRequest.executeRequestReturnError(this, args, output);
|
return throwApiError ? zabbixRequest.executeRequestThrowError(this, args, output) : zabbixRequest.executeRequestReturnError(this, args, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a Zabbix API request by its method path.
|
||||||
|
* @param path - The Zabbix API method path.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookies - Optional session cookies.
|
||||||
|
* @param throwApiError - Whether to throw an error if the request fails (default: true).
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns A promise that resolves to the result or an error result.
|
||||||
|
*/
|
||||||
async requestByPath<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs>(path: string, args?: A, authToken?: string | null, cookies?: string, throwApiError: boolean = true, output?: string[]) {
|
async requestByPath<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs>(path: string, args?: A, authToken?: string | null, cookies?: string, throwApiError: boolean = true, output?: string[]) {
|
||||||
return this.executeRequest<T, A>(new ZabbixRequest<T>(path, authToken, cookies), args, throwApiError, output);
|
return this.executeRequest<T, A>(new ZabbixRequest<T>(path, authToken, cookies), args, throwApiError, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves locations from host inventory.
|
||||||
|
* @param args - The parsed arguments for filtering locations.
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookies - Optional session cookies.
|
||||||
|
* @returns A promise that resolves to an array of location objects.
|
||||||
|
*/
|
||||||
async getLocations(args?: ParsedArgs, authToken?: string, cookies?: string) {
|
async getLocations(args?: ParsedArgs, authToken?: string, cookies?: string) {
|
||||||
const hosts_promise = this.requestByPath("host.get", args, authToken, cookies);
|
const hosts_promise = this.requestByPath("host.get", args, authToken, cookies);
|
||||||
return hosts_promise.then(response => {
|
return hosts_promise.then(response => {
|
||||||
|
|
|
||||||
|
|
@ -16,10 +16,23 @@ export interface ZabbixExportValue extends ZabbixValue, ZabbixResult {
|
||||||
itemid?: string
|
itemid?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters for querying history from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixHistoryGetParams extends ParsedArgs {
|
export class ZabbixHistoryGetParams extends ParsedArgs {
|
||||||
time_from_ms: number | undefined
|
time_from_ms: number | undefined
|
||||||
time_till_ms: number | undefined
|
time_till_ms: number | undefined
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param itemids - The IDs of the items to query history for.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @param limit - The maximum number of values to return.
|
||||||
|
* @param history - The storage item type (e.g., float, integer, character, text, log).
|
||||||
|
* @param time_from - The start time for the history query.
|
||||||
|
* @param time_until - The end time for the history query.
|
||||||
|
* @param sortfield - The field to sort the results by.
|
||||||
|
* @param sortorder - The sort order (ASC or DESC).
|
||||||
|
*/
|
||||||
constructor(public itemids: number[] | number | string | string[],
|
constructor(public itemids: number[] | number | string | string[],
|
||||||
public output: string[] = ["value", "itemid", "clock", "ns"],
|
public output: string[] = ["value", "itemid", "clock", "ns"],
|
||||||
public limit: number | null = Array.isArray(itemids) ? itemids.length : 1,
|
public limit: number | null = Array.isArray(itemids) ? itemids.length : 1,
|
||||||
|
|
@ -35,7 +48,14 @@ export class ZabbixHistoryGetParams extends ParsedArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query history from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryHistoryRequest extends ZabbixRequest<ZabbixExportValue[], ZabbixHistoryGetParams> {
|
export class ZabbixQueryHistoryRequest extends ZabbixRequest<ZabbixExportValue[], ZabbixHistoryGetParams> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("history.get", authToken, cookie);
|
super("history.get", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -65,7 +85,16 @@ export interface ZabbixHistoryPushResult {
|
||||||
error?: ApiError | string[]
|
error?: ApiError | string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters for pushing history to Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixHistoryPushParams extends ParsedArgs {
|
export class ZabbixHistoryPushParams extends ParsedArgs {
|
||||||
|
/**
|
||||||
|
* @param values - The history values to push.
|
||||||
|
* @param itemid - Optional item ID to push history for.
|
||||||
|
* @param key - Optional item key to push history for.
|
||||||
|
* @param host - Optional host name to push history for.
|
||||||
|
*/
|
||||||
constructor(public values: ZabbixHistoryPushInput[], public itemid?: string,
|
constructor(public values: ZabbixHistoryPushInput[], public itemid?: string,
|
||||||
public key?: string,
|
public key?: string,
|
||||||
public host?: string,) {
|
public host?: string,) {
|
||||||
|
|
@ -73,7 +102,14 @@ export class ZabbixHistoryPushParams extends ParsedArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to push history to Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixHistoryPushRequest extends ZabbixRequest<ZabbixHistoryPushResult, ZabbixHistoryPushParams> {
|
export class ZabbixHistoryPushRequest extends ZabbixRequest<ZabbixHistoryPushResult, ZabbixHistoryPushParams> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string) {
|
constructor(authToken?: string | null, cookie?: string) {
|
||||||
super("history.push", authToken, cookie);
|
super("history.push", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,28 @@ const hostGroupReadWritePermissions = {
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to create a host group in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixCreateHostGroupRequest extends ZabbixRequestWithPermissions<CreateHostGroupResult> {
|
export class ZabbixCreateHostGroupRequest extends ZabbixRequestWithPermissions<CreateHostGroupResult> {
|
||||||
|
/**
|
||||||
|
* @param _authToken - Ignored, as privilege escalation token is used.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(_authToken?: string | null, cookie?: string) {
|
constructor(_authToken?: string | null, cookie?: string) {
|
||||||
super("hostgroup.create", zabbixPrivilegeEscalationToken, cookie, hostGroupReadWritePermissions);
|
super("hostgroup.create", zabbixPrivilegeEscalationToken, cookie, hostGroupReadWritePermissions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters for querying host groups from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryHostgroupsParams extends ParsedArgs {
|
export class ZabbixQueryHostgroupsParams extends ParsedArgs {
|
||||||
search_name: string | undefined
|
search_name: string | undefined
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args - The raw arguments.
|
||||||
|
*/
|
||||||
constructor(args?: any) {
|
constructor(args?: any) {
|
||||||
super(args);
|
super(args);
|
||||||
if ("search_name" in args && typeof (args.search_name) == "string") {
|
if ("search_name" in args && typeof (args.search_name) == "string") {
|
||||||
|
|
@ -45,8 +58,16 @@ export type ZabbixQueryHostgroupsResult = {
|
||||||
uuid: string
|
uuid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query host groups from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryHostgroupsRequest extends ZabbixRequestWithPermissions<ZabbixQueryHostgroupsResult[],
|
export class ZabbixQueryHostgroupsRequest extends ZabbixRequestWithPermissions<ZabbixQueryHostgroupsResult[],
|
||||||
ZabbixQueryHostgroupsParams> {
|
ZabbixQueryHostgroupsParams> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @param hostGroupReadPermissions - Optional host group read permissions.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null, hostGroupReadPermissions?: any) {
|
constructor(authToken?: string | null, cookie?: string | null, hostGroupReadPermissions?: any) {
|
||||||
super("hostgroup.get", authToken, cookie, hostGroupReadPermissions,);
|
super("hostgroup.get", authToken, cookie, hostGroupReadPermissions,);
|
||||||
}
|
}
|
||||||
|
|
@ -69,7 +90,14 @@ export class ZabbixQueryHostgroupsRequest extends ZabbixRequestWithPermissions<Z
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to delete host groups in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixDeleteHostGroupsRequest extends ZabbixRequestWithPermissions<{ groupids: string[] }> {
|
export class ZabbixDeleteHostGroupsRequest extends ZabbixRequestWithPermissions<{ groupids: string[] }> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("hostgroup.delete", authToken, cookie, hostGroupReadWritePermissions);
|
super("hostgroup.delete", authToken, cookie, hostGroupReadWritePermissions);
|
||||||
}
|
}
|
||||||
|
|
@ -84,6 +112,14 @@ export class GroupHelper {
|
||||||
return groupName.replace(FIND_ZABBIX_EDGE_DEVICE_BASE_GROUP_PREFIX, "")
|
return groupName.replace(FIND_ZABBIX_EDGE_DEVICE_BASE_GROUP_PREFIX, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds host group IDs by their names.
|
||||||
|
* @param groupNames - The names of the host groups to find.
|
||||||
|
* @param zabbixApi - The Zabbix API instance.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of host group IDs.
|
||||||
|
*/
|
||||||
public static async findHostGroupIdsByName(groupNames: string[], zabbixApi: ZabbixAPI, zabbixAuthToken?: string, cookie?: string) {
|
public static async findHostGroupIdsByName(groupNames: string[], zabbixApi: ZabbixAPI, zabbixAuthToken?: string, cookie?: string) {
|
||||||
let result: number[] = []
|
let result: number[] = []
|
||||||
for (let groupName of groupNames) {
|
for (let groupName of groupNames) {
|
||||||
|
|
|
||||||
|
|
@ -12,9 +12,17 @@ import {ZabbixHistoryGetParams, ZabbixQueryHistoryRequest} from "./zabbix-histor
|
||||||
import {ZabbixQueryItemRequest} from "./zabbix-templates.js";
|
import {ZabbixQueryItemRequest} from "./zabbix-templates.js";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic request to query hosts from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryHostsGenericRequest<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> extends ZabbixRequest<T, A> {
|
export class ZabbixQueryHostsGenericRequest<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> extends ZabbixRequest<T, A> {
|
||||||
public static PATH = "host.get";
|
public static PATH = "host.get";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path - The Zabbix API method path.
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(path: string, authToken?: string | null, cookie?: string | null) {
|
constructor(path: string, authToken?: string | null, cookie?: string | null) {
|
||||||
super(path, authToken, cookie);
|
super(path, authToken, cookie);
|
||||||
this.skippableZabbixParams.set("selectParentTemplates", "parentTemplates");
|
this.skippableZabbixParams.set("selectParentTemplates", "parentTemplates");
|
||||||
|
|
@ -25,10 +33,23 @@ export class ZabbixQueryHostsGenericRequest<T extends ZabbixResult, A extends Pa
|
||||||
this.impliedFields.set("hostType", ["tags"]);
|
this.impliedFields.set("hostType", ["tags"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the request and returns the result or an error.
|
||||||
|
* @param zabbixAPI - The Zabbix API instance.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns A promise that resolves to the result or an error.
|
||||||
|
*/
|
||||||
async executeRequestReturnError(zabbixAPI: ZabbixAPI, args?: A, output?: string[]): Promise<ZabbixErrorResult | T> {
|
async executeRequestReturnError(zabbixAPI: ZabbixAPI, args?: A, output?: string[]): Promise<ZabbixErrorResult | T> {
|
||||||
return await super.executeRequestReturnError(zabbixAPI, args, output);
|
return await super.executeRequestReturnError(zabbixAPI, args, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the parameters for the Zabbix API request.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns The Zabbix parameters.
|
||||||
|
*/
|
||||||
createZabbixParams(args?: A, output?: string[]): ZabbixParams {
|
createZabbixParams(args?: A, output?: string[]): ZabbixParams {
|
||||||
const params: any = {
|
const params: any = {
|
||||||
...super.createZabbixParams(args),
|
...super.createZabbixParams(args),
|
||||||
|
|
@ -58,9 +79,16 @@ export class ZabbixQueryHostsGenericRequest<T extends ZabbixResult, A extends Pa
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query host metadata from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryHostsMetaRequest extends ZabbixQueryHostsGenericRequest<Host[]> {
|
export class ZabbixQueryHostsMetaRequest extends ZabbixQueryHostsGenericRequest<Host[]> {
|
||||||
public static PATH = "host.get.meta";
|
public static PATH = "host.get.meta";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super(ZabbixQueryHostsMetaRequest.PATH, authToken, cookie);
|
super(ZabbixQueryHostsMetaRequest.PATH, authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -74,7 +102,15 @@ export class ZabbixQueryHostsMetaRequest extends ZabbixQueryHostsGenericRequest<
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic request to query hosts with their items from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryHostsGenericRequestWithItems<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> extends ZabbixQueryHostsGenericRequest<T, A> {
|
export class ZabbixQueryHostsGenericRequestWithItems<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> extends ZabbixQueryHostsGenericRequest<T, A> {
|
||||||
|
/**
|
||||||
|
* @param path - The Zabbix API method path.
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(path: string, authToken?: string | null, cookie?: string) {
|
constructor(path: string, authToken?: string | null, cookie?: string) {
|
||||||
super(path, authToken, cookie);
|
super(path, authToken, cookie);
|
||||||
this.skippableZabbixParams.set("selectItems", "items");
|
this.skippableZabbixParams.set("selectItems", "items");
|
||||||
|
|
@ -167,7 +203,15 @@ export class ZabbixQueryHostsGenericRequestWithItems<T extends ZabbixResult, A e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generic request to query hosts with their items and inventory from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryHostsGenericRequestWithItemsAndInventory<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> extends ZabbixQueryHostsGenericRequestWithItems<T, A> {
|
export class ZabbixQueryHostsGenericRequestWithItemsAndInventory<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> extends ZabbixQueryHostsGenericRequestWithItems<T, A> {
|
||||||
|
/**
|
||||||
|
* @param path - The Zabbix API method path.
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(path: string, authToken?: string | null, cookie?: string) {
|
constructor(path: string, authToken?: string | null, cookie?: string) {
|
||||||
super(path, authToken, cookie);
|
super(path, authToken, cookie);
|
||||||
this.skippableZabbixParams.set("selectInventory", "inventory");
|
this.skippableZabbixParams.set("selectInventory", "inventory");
|
||||||
|
|
@ -189,7 +233,13 @@ export class ZabbixQueryHostsRequestWithItemsAndInventory extends ZabbixQueryHos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arguments for querying devices.
|
||||||
|
*/
|
||||||
export class ZabbixQueryDevicesArgs extends ParsedArgs {
|
export class ZabbixQueryDevicesArgs extends ParsedArgs {
|
||||||
|
/**
|
||||||
|
* @param args - The raw arguments.
|
||||||
|
*/
|
||||||
constructor(public args?: any) {
|
constructor(public args?: any) {
|
||||||
if (!args?.tag_deviceType ||
|
if (!args?.tag_deviceType ||
|
||||||
(Array.isArray(args.tag_deviceType) && !args.tag_deviceType.length)) {
|
(Array.isArray(args.tag_deviceType) && !args.tag_deviceType.length)) {
|
||||||
|
|
@ -199,7 +249,14 @@ export class ZabbixQueryDevicesArgs extends ParsedArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query devices from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryDevices extends ZabbixQueryHostsGenericRequestWithItemsAndInventory<Device[], ZabbixQueryDevicesArgs> {
|
export class ZabbixQueryDevices extends ZabbixQueryHostsGenericRequestWithItemsAndInventory<Device[], ZabbixQueryDevicesArgs> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string) {
|
constructor(authToken?: string | null, cookie?: string) {
|
||||||
super("host.get.with_items", authToken, cookie);
|
super("host.get.with_items", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -272,7 +329,14 @@ class ZabbixCreateHostParams implements ZabbixParams {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to create a host in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixCreateHostRequest extends ZabbixRequest<CreateHostResponse> {
|
export class ZabbixCreateHostRequest extends ZabbixRequest<CreateHostResponse> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string) {
|
constructor(authToken?: string | null, cookie?: string) {
|
||||||
super("host.create", authToken, cookie);
|
super("host.create", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -286,7 +350,14 @@ export class ZabbixCreateHostRequest extends ZabbixRequest<CreateHostResponse> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to delete hosts in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixDeleteHostsRequest extends ZabbixRequest<{ hostids: string[] }> {
|
export class ZabbixDeleteHostsRequest extends ZabbixRequest<{ hostids: string[] }> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("host.delete", authToken, cookie);
|
super("host.delete", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,23 @@ import {ParsedArgs, ZabbixRequest} from "./zabbix-request.js";
|
||||||
import {ZabbixItem} from "../schema/generated/graphql.js";
|
import {ZabbixItem} from "../schema/generated/graphql.js";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query items from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryItemsRequest extends ZabbixRequest<ZabbixItem[]> {
|
export class ZabbixQueryItemsRequest extends ZabbixRequest<ZabbixItem[]> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string) {
|
constructor(authToken?: string | null, cookie?: string) {
|
||||||
super("item.get", authToken, cookie);
|
super("item.get", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the parameters for the Zabbix API request.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @returns The Zabbix parameters.
|
||||||
|
*/
|
||||||
createZabbixParams(args?: ParsedArgs) {
|
createZabbixParams(args?: ParsedArgs) {
|
||||||
return {
|
return {
|
||||||
"templated": false,
|
"templated": false,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,14 @@
|
||||||
import {ParsedArgs, ZabbixParams, ZabbixRequest} from "./zabbix-request.js";
|
import {ParsedArgs, ZabbixParams, ZabbixRequest} from "./zabbix-request.js";
|
||||||
import {UserRoleModule} from "../schema/generated/graphql.js";
|
import {UserRoleModule} from "../schema/generated/graphql.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query modules from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryModulesRequest extends ZabbixRequest<UserRoleModule[]> {
|
export class ZabbixQueryModulesRequest extends ZabbixRequest<UserRoleModule[]> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("module.get", authToken, cookie);
|
super("module.get", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,38 @@ import {ApiErrorCode, PermissionNumber} from "../model/model_enum_values.js";
|
||||||
import {Config} from "../common_utils.js";
|
import {Config} from "../common_utils.js";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for Zabbix requests that require specific user permissions.
|
||||||
|
*/
|
||||||
export class ZabbixRequestWithPermissions<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> extends ZabbixRequest<T, A> {
|
export class ZabbixRequestWithPermissions<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> extends ZabbixRequest<T, A> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path - The Zabbix API method path.
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @param permissionsNeeded - The permissions required to execute this request.
|
||||||
|
*/
|
||||||
constructor(public path: string, public authToken?: string | null, public cookie?: string | null,
|
constructor(public path: string, public authToken?: string | null, public cookie?: string | null,
|
||||||
protected permissionsNeeded?: QueryHasPermissionsArgs) {
|
protected permissionsNeeded?: QueryHasPermissionsArgs) {
|
||||||
super(path, authToken, cookie);
|
super(path, authToken, cookie);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Prepares the request by checking user permissions.
|
||||||
|
* @param zabbixAPI - The Zabbix API instance.
|
||||||
|
* @param _args - The parsed arguments for the request.
|
||||||
|
* @returns A promise that resolves to the result or an error if permissions are missing.
|
||||||
|
*/
|
||||||
async prepare(zabbixAPI: ZabbixAPI, _args?: A): Promise<T | ZabbixErrorResult | undefined> {
|
async prepare(zabbixAPI: ZabbixAPI, _args?: A): Promise<T | ZabbixErrorResult | undefined> {
|
||||||
// If prepare returns something else than undefined, the execution will be skipped and the
|
// If prepare returns something else than undefined, the execution will be skipped and the
|
||||||
// result returned
|
// result returned
|
||||||
this.prepResult = await this.assureUserPermissions(zabbixAPI);
|
this.prepResult = await this.assureUserPermissions(zabbixAPI);
|
||||||
return this.prepResult;
|
return this.prepResult;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Ensures that the user has the required permissions.
|
||||||
|
* @param zabbixAPI - The Zabbix API instance.
|
||||||
|
* @returns A promise that resolves to undefined if permissions are granted, or an error otherwise.
|
||||||
|
*/
|
||||||
async assureUserPermissions(zabbixAPI: ZabbixAPI) {
|
async assureUserPermissions(zabbixAPI: ZabbixAPI) {
|
||||||
if (this.authToken && this.authToken === Config.ZABBIX_PRIVILEGE_ESCALATION_TOKEN) {
|
if (this.authToken && this.authToken === Config.ZABBIX_PRIVILEGE_ESCALATION_TOKEN) {
|
||||||
// Bypass permission check for the privilege escalation token as it is assumed to have required rights
|
// Bypass permission check for the privilege escalation token as it is assumed to have required rights
|
||||||
|
|
@ -104,6 +124,14 @@ export class ZabbixPermissionsHelper {
|
||||||
private static permissionObjectNameCache: Map<string, string | null> = new Map()
|
private static permissionObjectNameCache: Map<string, string | null> = new Map()
|
||||||
public static ZABBIX_PERMISSION_TEMPLATE_GROUP_NAME_PREFIX = Config.ZABBIX_PERMISSION_TEMPLATE_GROUP_NAME_PREFIX
|
public static ZABBIX_PERMISSION_TEMPLATE_GROUP_NAME_PREFIX = Config.ZABBIX_PERMISSION_TEMPLATE_GROUP_NAME_PREFIX
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves permissions for the current user.
|
||||||
|
* @param zabbixAPI - The Zabbix API instance.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @param objectNames - Optional filter for object names.
|
||||||
|
* @returns A promise that resolves to an array of user permissions.
|
||||||
|
*/
|
||||||
public static async getUserPermissions(zabbixAPI: ZabbixAPI, zabbixAuthToken?: string, cookie?: string,
|
public static async getUserPermissions(zabbixAPI: ZabbixAPI, zabbixAuthToken?: string, cookie?: string,
|
||||||
objectNames?: InputMaybe<string[]> | undefined): Promise<UserPermission[]> {
|
objectNames?: InputMaybe<string[]> | undefined): Promise<UserPermission[]> {
|
||||||
return Array.from((await this.getUserPermissionNumbers(zabbixAPI, zabbixAuthToken, cookie, objectNames)).entries()).map(value => {
|
return Array.from((await this.getUserPermissionNumbers(zabbixAPI, zabbixAuthToken, cookie, objectNames)).entries()).map(value => {
|
||||||
|
|
@ -211,6 +239,14 @@ export class ZabbixPermissionsHelper {
|
||||||
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user has the required permissions.
|
||||||
|
* @param zabbixAPI - The Zabbix API instance.
|
||||||
|
* @param args - The permissions to check.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to true if the user has all required permissions, false otherwise.
|
||||||
|
*/
|
||||||
public static async hasUserPermissions(zabbixAPI: ZabbixAPI, args: QueryHasPermissionsArgs, zabbixAuthToken?: string | null, cookie?: string | null): Promise<boolean> {
|
public static async hasUserPermissions(zabbixAPI: ZabbixAPI, args: QueryHasPermissionsArgs, zabbixAuthToken?: string | null, cookie?: string | null): Promise<boolean> {
|
||||||
let permissions = await this.getUserPermissionNumbers(zabbixAPI, zabbixAuthToken, cookie);
|
let permissions = await this.getUserPermissionNumbers(zabbixAPI, zabbixAuthToken, cookie);
|
||||||
for (const permission of args.permissions) {
|
for (const permission of args.permissions) {
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,18 @@ export interface ZabbixWithTagsParams extends ZabbixParams {
|
||||||
tags?: { tag: string; operator: number; value?: any; }[]
|
tags?: { tag: string; operator: number; value?: any; }[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parser for arguments passed to Zabbix requests.
|
||||||
|
* Handles Zabbix-specific argument mapping like name_pattern, tag filters, and field filters.
|
||||||
|
*/
|
||||||
export class ParsedArgs {
|
export class ParsedArgs {
|
||||||
public name_pattern?: string
|
public name_pattern?: string
|
||||||
public distinct_by_name?: boolean;
|
public distinct_by_name?: boolean;
|
||||||
public zabbix_params: ZabbixParams[] | ZabbixParams
|
public zabbix_params: ZabbixParams[] | ZabbixParams
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param params - The raw parameters to parse.
|
||||||
|
*/
|
||||||
constructor(params?: any) {
|
constructor(params?: any) {
|
||||||
if (Array.isArray(params)) {
|
if (Array.isArray(params)) {
|
||||||
this.zabbix_params = params.map(arg => this.parseArgObject(arg))
|
this.zabbix_params = params.map(arg => this.parseArgObject(arg))
|
||||||
|
|
@ -46,6 +53,11 @@ export class ParsedArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a parameter value by name.
|
||||||
|
* @param paramName - The name of the parameter to retrieve.
|
||||||
|
* @returns The parameter value or undefined.
|
||||||
|
*/
|
||||||
getParam(paramName: string): any {
|
getParam(paramName: string): any {
|
||||||
if (this.zabbix_params instanceof Array) {
|
if (this.zabbix_params instanceof Array) {
|
||||||
return undefined
|
return undefined
|
||||||
|
|
@ -54,6 +66,11 @@ export class ParsedArgs {
|
||||||
return paramName in this.zabbix_params ? this.zabbix_params[paramName] : undefined
|
return paramName in this.zabbix_params ? this.zabbix_params[paramName] : undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses an argument object into Zabbix parameters.
|
||||||
|
* @param args - The raw argument object.
|
||||||
|
* @returns The parsed Zabbix parameters.
|
||||||
|
*/
|
||||||
parseArgObject(args?: any) {
|
parseArgObject(args?: any) {
|
||||||
if (args && (typeof args !== 'object' || args.constructor !== Object)) {
|
if (args && (typeof args !== 'object' || args.constructor !== Object)) {
|
||||||
return args;
|
return args;
|
||||||
|
|
@ -146,6 +163,9 @@ export class ParsedArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for all Zabbix API requests.
|
||||||
|
*/
|
||||||
export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> {
|
export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> {
|
||||||
protected requestBodyTemplate: ZabbixRequestBody;
|
protected requestBodyTemplate: ZabbixRequestBody;
|
||||||
protected method: string
|
protected method: string
|
||||||
|
|
@ -153,11 +173,22 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
|
||||||
protected skippableZabbixParams: Map<string, string> = new Map();
|
protected skippableZabbixParams: Map<string, string> = new Map();
|
||||||
protected impliedFields: Map<string, string[]> = new Map();
|
protected impliedFields: Map<string, string[]> = new Map();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path - The Zabbix API method path.
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(public path: string, public authToken?: string | null, public cookie?: string | null) {
|
constructor(public path: string, public authToken?: string | null, public cookie?: string | null) {
|
||||||
this.method = path.split(".", 2).join(".");
|
this.method = path.split(".", 2).join(".");
|
||||||
this.requestBodyTemplate = new ZabbixRequestBody(this.method);
|
this.requestBodyTemplate = new ZabbixRequestBody(this.method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Optimizes Zabbix parameters by removing unused fields and adding implied fields based on the requested output.
|
||||||
|
* @param params - The Zabbix parameters to optimize.
|
||||||
|
* @param output - The list of requested output fields.
|
||||||
|
* @returns The optimized Zabbix parameters.
|
||||||
|
*/
|
||||||
optimizeZabbixParams(params: ZabbixParams, output?: string[]): ZabbixParams {
|
optimizeZabbixParams(params: ZabbixParams, output?: string[]): ZabbixParams {
|
||||||
if (!output || output.length === 0) {
|
if (!output || output.length === 0) {
|
||||||
return params;
|
return params;
|
||||||
|
|
@ -202,10 +233,24 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the parameters for the Zabbix API request.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns The Zabbix parameters.
|
||||||
|
*/
|
||||||
createZabbixParams(args?: A, output?: string[]): ZabbixParams {
|
createZabbixParams(args?: A, output?: string[]): ZabbixParams {
|
||||||
return this.optimizeZabbixParams(args?.zabbix_params || {}, output)
|
return this.optimizeZabbixParams(args?.zabbix_params || {}, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs the request body for the Zabbix API call.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param zabbixParams - Optional pre-constructed Zabbix parameters.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @param version - The Zabbix API version.
|
||||||
|
* @returns The constructed Zabbix request body.
|
||||||
|
*/
|
||||||
getRequestBody(args?: A, zabbixParams?: ZabbixParams, output?: string[], version?: string): ZabbixRequestBody {
|
getRequestBody(args?: A, zabbixParams?: ZabbixParams, output?: string[], version?: string): ZabbixRequestBody {
|
||||||
let params: ZabbixParams
|
let params: ZabbixParams
|
||||||
if (Array.isArray(args?.zabbix_params)) {
|
if (Array.isArray(args?.zabbix_params)) {
|
||||||
|
|
@ -233,6 +278,10 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
|
||||||
return body
|
return body
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the HTTP headers for the Zabbix API call.
|
||||||
|
* @returns The HTTP headers.
|
||||||
|
*/
|
||||||
headers() {
|
headers() {
|
||||||
let headers: {
|
let headers: {
|
||||||
"Content-Type": string
|
"Content-Type": string
|
||||||
|
|
@ -255,12 +304,25 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepares the request before execution. Can be overridden to perform checks or transformations.
|
||||||
|
* @param zabbixAPI - The Zabbix API instance.
|
||||||
|
* @param _args - The parsed arguments for the request.
|
||||||
|
* @returns A promise that resolves to the result, an error, or undefined if preparation is successful.
|
||||||
|
*/
|
||||||
async prepare(zabbixAPI: ZabbixAPI, _args?: A): Promise<T | ZabbixErrorResult | undefined> {
|
async prepare(zabbixAPI: ZabbixAPI, _args?: A): Promise<T | ZabbixErrorResult | undefined> {
|
||||||
// If prepare returns something else than undefined, the execution will be skipped and the
|
// If prepare returns something else than undefined, the execution will be skipped and the
|
||||||
// result returned
|
// result returned
|
||||||
return this.prepResult;
|
return this.prepResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the request and returns the result or an error.
|
||||||
|
* @param zabbixAPI - The Zabbix API instance.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns A promise that resolves to the result or an error.
|
||||||
|
*/
|
||||||
async executeRequestReturnError(zabbixAPI: ZabbixAPI, args?: A, output?: string[]): Promise<T | ZabbixErrorResult> {
|
async executeRequestReturnError(zabbixAPI: ZabbixAPI, args?: A, output?: string[]): Promise<T | ZabbixErrorResult> {
|
||||||
let prepareResult = await this.prepare(zabbixAPI, args);
|
let prepareResult = await this.prepare(zabbixAPI, args);
|
||||||
if (prepareResult) {
|
if (prepareResult) {
|
||||||
|
|
@ -299,6 +361,14 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the request and throws an error if it fails.
|
||||||
|
* @param zabbixApi - The Zabbix API instance.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns A promise that resolves to the result.
|
||||||
|
* @throws GraphQLError if the request fails.
|
||||||
|
*/
|
||||||
async executeRequestThrowError(zabbixApi: ZabbixAPI, args?: A, output?: string[]): Promise<T> {
|
async executeRequestThrowError(zabbixApi: ZabbixAPI, args?: A, output?: string[]): Promise<T> {
|
||||||
let response = await this.executeRequestReturnError(zabbixApi, args, output);
|
let response = await this.executeRequestReturnError(zabbixApi, args, output);
|
||||||
if (isZabbixErrorResult(response)) {
|
if (isZabbixErrorResult(response)) {
|
||||||
|
|
@ -317,16 +387,34 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters for creating or updating entities in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixCreateOrUpdateParams extends ParsedArgs {
|
export class ZabbixCreateOrUpdateParams extends ParsedArgs {
|
||||||
|
/**
|
||||||
|
* @param args - The raw arguments.
|
||||||
|
* @param dryRun - Whether to perform a dry run (default: true).
|
||||||
|
*/
|
||||||
constructor(args: any, public dryRun = true) {
|
constructor(args: any, public dryRun = true) {
|
||||||
super(args);
|
super(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to create or update entities in Zabbix.
|
||||||
|
* Automatically checks if an entity with the same name already exists.
|
||||||
|
*/
|
||||||
export class ZabbixCreateOrUpdateRequest<
|
export class ZabbixCreateOrUpdateRequest<
|
||||||
T extends ZabbixResult,
|
T extends ZabbixResult,
|
||||||
P extends ZabbixRequest<ZabbixResult>,
|
P extends ZabbixRequest<ZabbixResult>,
|
||||||
A extends ZabbixCreateOrUpdateParams = ZabbixCreateOrUpdateParams> extends ZabbixRequest<T, A> {
|
A extends ZabbixCreateOrUpdateParams = ZabbixCreateOrUpdateParams> extends ZabbixRequest<T, A> {
|
||||||
|
/**
|
||||||
|
* @param entity - The entity name (e.g., "host", "usergroup").
|
||||||
|
* @param updateExistingIdFieldname - The name of the ID field used for updating.
|
||||||
|
* @param prepareType - The class type used to query for existing entities.
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(public entity: string,
|
constructor(public entity: string,
|
||||||
public updateExistingIdFieldname: string,
|
public updateExistingIdFieldname: string,
|
||||||
private prepareType: new (authToken?: string | null, cookie?: string | null) => P, authToken?: string | null, cookie?: string | null) {
|
private prepareType: new (authToken?: string | null, cookie?: string | null) => P, authToken?: string | null, cookie?: string | null) {
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,21 @@ import {ApiErrorCode} from "../model/model_enum_values.js";
|
||||||
import {isZabbixErrorResult, ParsedArgs, ZabbixErrorResult, ZabbixParams, ZabbixRequest} from "./zabbix-request.js";
|
import {isZabbixErrorResult, ParsedArgs, ZabbixErrorResult, ZabbixParams, ZabbixRequest} from "./zabbix-request.js";
|
||||||
import {ZabbixQueryHostsMetaRequest} from "./zabbix-hosts.js";
|
import {ZabbixQueryHostsMetaRequest} from "./zabbix-hosts.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters for forcing a Zabbix configuration cache reload.
|
||||||
|
*/
|
||||||
export class ZabbixForceCacheReloadParams extends ParsedArgs {
|
export class ZabbixForceCacheReloadParams extends ParsedArgs {
|
||||||
|
/**
|
||||||
|
* @param hostid - The ID of the host to execute the script on.
|
||||||
|
*/
|
||||||
constructor(public hostid: number) {
|
constructor(public hostid: number) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to force a Zabbix configuration cache reload.
|
||||||
|
*/
|
||||||
export class ZabbixForceCacheReloadRequest extends ZabbixRequest<{
|
export class ZabbixForceCacheReloadRequest extends ZabbixRequest<{
|
||||||
response: string
|
response: string
|
||||||
value: string
|
value: string
|
||||||
|
|
@ -27,6 +36,10 @@ export class ZabbixForceCacheReloadRequest extends ZabbixRequest<{
|
||||||
"scope": "2"
|
"scope": "2"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("script.execute", authToken, cookie);
|
super("script.execute", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,25 @@ export interface ZabbixQueryTemplateResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query templates from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryTemplatesRequest extends ZabbixRequest<ZabbixQueryTemplateResponse[]> {
|
export class ZabbixQueryTemplatesRequest extends ZabbixRequest<ZabbixQueryTemplateResponse[]> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null,) {
|
constructor(authToken?: string | null, cookie?: string | null,) {
|
||||||
super("template.get", authToken, cookie);
|
super("template.get", authToken, cookie);
|
||||||
this.skippableZabbixParams.set("selectItems", "items");
|
this.skippableZabbixParams.set("selectItems", "items");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the parameters for the Zabbix API request.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns The Zabbix parameters.
|
||||||
|
*/
|
||||||
createZabbixParams(args?: ParsedArgs, output?: string[]): ZabbixParams {
|
createZabbixParams(args?: ParsedArgs, output?: string[]): ZabbixParams {
|
||||||
return this.optimizeZabbixParams({
|
return this.optimizeZabbixParams({
|
||||||
"selectItems": "extend",
|
"selectItems": "extend",
|
||||||
|
|
@ -26,6 +39,13 @@ export class ZabbixQueryTemplatesRequest extends ZabbixRequest<ZabbixQueryTempla
|
||||||
}, output);
|
}, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes the request and returns the result or an error.
|
||||||
|
* @param zabbixAPI - The Zabbix API instance.
|
||||||
|
* @param args - The parsed arguments for the request.
|
||||||
|
* @param output - The list of fields to return.
|
||||||
|
* @returns A promise that resolves to the result or an error.
|
||||||
|
*/
|
||||||
async executeRequestReturnError(zabbixAPI: ZabbixAPI, args?: ParsedArgs, output?: string[]): Promise<ZabbixErrorResult | ZabbixQueryTemplateResponse[]> {
|
async executeRequestReturnError(zabbixAPI: ZabbixAPI, args?: ParsedArgs, output?: string[]): Promise<ZabbixErrorResult | ZabbixQueryTemplateResponse[]> {
|
||||||
let result = await super.executeRequestReturnError(zabbixAPI, args, output);
|
let result = await super.executeRequestReturnError(zabbixAPI, args, output);
|
||||||
|
|
||||||
|
|
@ -64,44 +84,93 @@ export interface ZabbixQueryTemplateGroupResponse {
|
||||||
uuid: string
|
uuid: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query template groups from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryTemplateGroupRequest extends ZabbixRequest<ZabbixQueryTemplateGroupResponse[]> {
|
export class ZabbixQueryTemplateGroupRequest extends ZabbixRequest<ZabbixQueryTemplateGroupResponse[]> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("templategroup.get", authToken, cookie);
|
super("templategroup.get", authToken, cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to create a template group in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixCreateTemplateGroupRequest extends ZabbixRequest<{ groupids: string[] }> {
|
export class ZabbixCreateTemplateGroupRequest extends ZabbixRequest<{ groupids: string[] }> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("templategroup.create", authToken, cookie);
|
super("templategroup.create", authToken, cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to create a template in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixCreateTemplateRequest extends ZabbixRequest<{ templateids: string[] }> {
|
export class ZabbixCreateTemplateRequest extends ZabbixRequest<{ templateids: string[] }> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("template.create", authToken, cookie);
|
super("template.create", authToken, cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query items from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryItemRequest extends ZabbixRequest<any[]> {
|
export class ZabbixQueryItemRequest extends ZabbixRequest<any[]> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("item.get", authToken, cookie);
|
super("item.get", authToken, cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to create an item in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixCreateItemRequest extends ZabbixRequest<{ itemids: string[] }> {
|
export class ZabbixCreateItemRequest extends ZabbixRequest<{ itemids: string[] }> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("item.create", authToken, cookie);
|
super("item.create", authToken, cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to delete templates in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixDeleteTemplatesRequest extends ZabbixRequest<{ templateids: string[] }> {
|
export class ZabbixDeleteTemplatesRequest extends ZabbixRequest<{ templateids: string[] }> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("template.delete", authToken, cookie);
|
super("template.delete", authToken, cookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to delete template groups in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixDeleteTemplateGroupsRequest extends ZabbixRequest<{ groupids: string[] }> {
|
export class ZabbixDeleteTemplateGroupsRequest extends ZabbixRequest<{ groupids: string[] }> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("templategroup.delete", authToken, cookie);
|
super("templategroup.delete", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -109,6 +178,14 @@ export class ZabbixDeleteTemplateGroupsRequest extends ZabbixRequest<{ groupids:
|
||||||
|
|
||||||
|
|
||||||
export class TemplateHelper {
|
export class TemplateHelper {
|
||||||
|
/**
|
||||||
|
* Finds template IDs by their names.
|
||||||
|
* @param templateNames - The names of the templates to find.
|
||||||
|
* @param zabbixApi - The Zabbix API instance.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of template IDs or null if any template is not found.
|
||||||
|
*/
|
||||||
public static async findTemplateIdsByName(templateNames: string[], zabbixApi: ZabbixAPI, zabbixAuthToken?: string, cookie?: string) {
|
public static async findTemplateIdsByName(templateNames: string[], zabbixApi: ZabbixAPI, zabbixAuthToken?: string, cookie?: string) {
|
||||||
let result: number[] = []
|
let result: number[] = []
|
||||||
for (let templateName of templateNames) {
|
for (let templateName of templateNames) {
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,16 @@ abstract class ZabbixPrepareGetTemplatesAndHostgroupsRequest<T extends ZabbixRes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Arguments for exporting user groups.
|
||||||
|
*/
|
||||||
export class ZabbixExportUserGroupArgs extends ParsedArgs {
|
export class ZabbixExportUserGroupArgs extends ParsedArgs {
|
||||||
public exclude_hostgroups_pattern?: RegExp | undefined = undefined;
|
public exclude_hostgroups_pattern?: RegExp | undefined = undefined;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param name_pattern - Optional wildcard name pattern for filtering user groups.
|
||||||
|
* @param exclude_hostgroups_pattern_str - Optional regex string to exclude host groups by name.
|
||||||
|
*/
|
||||||
constructor(name_pattern?: string | null, exclude_hostgroups_pattern_str?: string | null) {
|
constructor(name_pattern?: string | null, exclude_hostgroups_pattern_str?: string | null) {
|
||||||
super(name_pattern? {name_pattern: name_pattern} : undefined);
|
super(name_pattern? {name_pattern: name_pattern} : undefined);
|
||||||
if (exclude_hostgroups_pattern_str) {
|
if (exclude_hostgroups_pattern_str) {
|
||||||
|
|
@ -67,8 +74,15 @@ export class ZabbixExportUserGroupArgs extends ParsedArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to export user groups from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixExportUserGroupsRequest extends ZabbixPrepareGetTemplatesAndHostgroupsRequest<
|
export class ZabbixExportUserGroupsRequest extends ZabbixPrepareGetTemplatesAndHostgroupsRequest<
|
||||||
UserGroup[], ZabbixExportUserGroupArgs> {
|
UserGroup[], ZabbixExportUserGroupArgs> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string) {
|
constructor(authToken?: string | null, cookie?: string) {
|
||||||
super("usergroup.get.withuuids", authToken, cookie);
|
super("usergroup.get.withuuids", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +131,14 @@ export class ZabbixExportUserGroupsRequest extends ZabbixPrepareGetTemplatesAndH
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query user groups from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryUserGroupsRequest extends ZabbixRequest<UserGroup[]> {
|
export class ZabbixQueryUserGroupsRequest extends ZabbixRequest<UserGroup[]> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("usergroup.get", authToken, cookie);
|
super("usergroup.get", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -130,15 +151,29 @@ export class ZabbixQueryUserGroupsRequest extends ZabbixRequest<UserGroup[]> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters for importing user groups.
|
||||||
|
*/
|
||||||
export class ZabbixImportUserGroupsParams extends ParsedArgs {
|
export class ZabbixImportUserGroupsParams extends ParsedArgs {
|
||||||
|
/**
|
||||||
|
* @param usergroups - The user groups to import.
|
||||||
|
* @param dryRun - Whether to perform a dry run (default: true).
|
||||||
|
*/
|
||||||
constructor(public usergroups: UserGroupInput[], public dryRun = true) {
|
constructor(public usergroups: UserGroupInput[], public dryRun = true) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to import user groups into Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixImportUserGroupsRequest
|
export class ZabbixImportUserGroupsRequest
|
||||||
extends ZabbixPrepareGetTemplatesAndHostgroupsRequest<ImportUserRightResult[],
|
extends ZabbixPrepareGetTemplatesAndHostgroupsRequest<ImportUserRightResult[],
|
||||||
ZabbixImportUserGroupsParams> {
|
ZabbixImportUserGroupsParams> {
|
||||||
|
/**
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(zabbixAuthToken: any, cookie: any) {
|
constructor(zabbixAuthToken: any, cookie: any) {
|
||||||
super("usergroup.create.import", zabbixAuthToken, cookie);
|
super("usergroup.create.import", zabbixAuthToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -328,8 +363,15 @@ class ZabbixPropagateHostGroupsParams extends ParsedArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to propagate host group permissions to children in Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixPropagateHostGroupsRequest extends ZabbixRequest<ZabbixCreateUserGroupResponse,
|
export class ZabbixPropagateHostGroupsRequest extends ZabbixRequest<ZabbixCreateUserGroupResponse,
|
||||||
ZabbixPropagateHostGroupsParams> {
|
ZabbixPropagateHostGroupsParams> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("hostgroup.propagate", authToken, cookie);
|
super("hostgroup.propagate", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,14 @@ export class ZabbixPrepareGetModulesRequest<T extends ZabbixResult, A extends Pa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to query user roles from Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixQueryUserRolesRequest extends ZabbixPrepareGetModulesRequest<UserRole[]> {
|
export class ZabbixQueryUserRolesRequest extends ZabbixPrepareGetModulesRequest<UserRole[]> {
|
||||||
|
/**
|
||||||
|
* @param authToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(authToken?: string | null, cookie?: string | null) {
|
constructor(authToken?: string | null, cookie?: string | null) {
|
||||||
super("role.get", authToken, cookie);
|
super("role.get", authToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
@ -63,14 +70,28 @@ export class ZabbixQueryUserRolesRequest extends ZabbixPrepareGetModulesRequest<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parameters for importing user roles.
|
||||||
|
*/
|
||||||
export class ZabbixImportUserRolesParams extends ParsedArgs {
|
export class ZabbixImportUserRolesParams extends ParsedArgs {
|
||||||
|
/**
|
||||||
|
* @param userRoles - The user roles to import.
|
||||||
|
* @param dryRun - Whether to perform a dry run (default: false).
|
||||||
|
*/
|
||||||
constructor(public userRoles: UserRoleInput[], public dryRun: boolean = false) {
|
constructor(public userRoles: UserRoleInput[], public dryRun: boolean = false) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request to import user roles into Zabbix.
|
||||||
|
*/
|
||||||
export class ZabbixImportUserRolesRequest extends ZabbixPrepareGetModulesRequest<ImportUserRightResult[],
|
export class ZabbixImportUserRolesRequest extends ZabbixPrepareGetModulesRequest<ImportUserRightResult[],
|
||||||
ZabbixImportUserRolesParams> {
|
ZabbixImportUserRolesParams> {
|
||||||
|
/**
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
*/
|
||||||
constructor(zabbixAuthToken: any, cookie: any) {
|
constructor(zabbixAuthToken: any, cookie: any) {
|
||||||
super("role.create.import", zabbixAuthToken, cookie);
|
super("role.create.import", zabbixAuthToken, cookie);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,19 @@ import {
|
||||||
import {isZabbixErrorResult, ParsedArgs} from "../datasources/zabbix-request.js";
|
import {isZabbixErrorResult, ParsedArgs} from "../datasources/zabbix-request.js";
|
||||||
import {zabbixAPI} from "../datasources/zabbix-api.js";
|
import {zabbixAPI} from "../datasources/zabbix-api.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles deleting hosts and host groups from Zabbix.
|
||||||
|
*/
|
||||||
export class HostDeleter {
|
export class HostDeleter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes hosts based on their IDs or a name pattern.
|
||||||
|
* @param hostids - The IDs of the hosts to delete.
|
||||||
|
* @param name_pattern - Optional wildcard name pattern for filtering hosts.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of delete responses.
|
||||||
|
*/
|
||||||
public static async deleteHosts(hostids: number[] | null | undefined, name_pattern?: string | null, zabbixAuthToken?: string, cookie?: string): Promise<DeleteResponse[]> {
|
public static async deleteHosts(hostids: number[] | null | undefined, name_pattern?: string | null, zabbixAuthToken?: string, cookie?: string): Promise<DeleteResponse[]> {
|
||||||
const result: DeleteResponse[] = [];
|
const result: DeleteResponse[] = [];
|
||||||
let idsToDelete = hostids ? [...hostids] : [];
|
let idsToDelete = hostids ? [...hostids] : [];
|
||||||
|
|
@ -60,6 +71,14 @@ export class HostDeleter {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes host groups based on their IDs or a name pattern.
|
||||||
|
* @param groupids - The IDs of the host groups to delete.
|
||||||
|
* @param name_pattern - Optional wildcard name pattern for filtering host groups.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of delete responses.
|
||||||
|
*/
|
||||||
public static async deleteHostGroups(groupids: number[] | null | undefined, name_pattern?: string | null, zabbixAuthToken?: string, cookie?: string): Promise<DeleteResponse[]> {
|
public static async deleteHostGroups(groupids: number[] | null | undefined, name_pattern?: string | null, zabbixAuthToken?: string, cookie?: string): Promise<DeleteResponse[]> {
|
||||||
const result: DeleteResponse[] = [];
|
const result: DeleteResponse[] = [];
|
||||||
let idsToDelete = groupids ? [...groupids] : [];
|
let idsToDelete = groupids ? [...groupids] : [];
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,17 @@ type ItemMapResponse = {
|
||||||
error?: ApiError
|
error?: ApiError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles exporting host history data from Zabbix.
|
||||||
|
*/
|
||||||
export class HostValueExporter {
|
export class HostValueExporter {
|
||||||
|
/**
|
||||||
|
* Exports history data based on the provided filter arguments.
|
||||||
|
* @param args - The filter and output options for the export.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to a generic response containing the history data.
|
||||||
|
*/
|
||||||
static async exportHistory(args: QueryExportHostValueHistoryArgs, zabbixAuthToken?: string, cookie?: string): Promise<GenericResponse> {
|
static async exportHistory(args: QueryExportHostValueHistoryArgs, zabbixAuthToken?: string, cookie?: string): Promise<GenericResponse> {
|
||||||
let itemMapResponse: ItemMapResponse = await HostValueExporter.queryItemsForFilterArgs(args, zabbixAuthToken, cookie);
|
let itemMapResponse: ItemMapResponse = await HostValueExporter.queryItemsForFilterArgs(args, zabbixAuthToken, cookie);
|
||||||
if (itemMapResponse.error || !itemMapResponse.items) {
|
if (itemMapResponse.error || !itemMapResponse.items) {
|
||||||
|
|
@ -75,6 +85,13 @@ export class HostValueExporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries for items matching the provided filter arguments to be used in history export.
|
||||||
|
* @param args - The filter arguments.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an item map response.
|
||||||
|
*/
|
||||||
static async queryItemsForFilterArgs(args: QueryExportHostValueHistoryArgs, zabbixAuthToken?: string, cookie?: string): Promise<ItemMapResponse> {
|
static async queryItemsForFilterArgs(args: QueryExportHostValueHistoryArgs, zabbixAuthToken?: string, cookie?: string): Promise<ItemMapResponse> {
|
||||||
let hostFilter = args.host_filter
|
let hostFilter = args.host_filter
|
||||||
let itemKeyFilter = args.itemKey_filter
|
let itemKeyFilter = args.itemKey_filter
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,15 @@ import {isZabbixErrorResult, ParsedArgs, ZabbixErrorResult} from "../datasources
|
||||||
import {CreateHostGroupResult, GroupHelper, ZabbixCreateHostGroupRequest} from "../datasources/zabbix-hostgroups.js";
|
import {CreateHostGroupResult, GroupHelper, ZabbixCreateHostGroupRequest} from "../datasources/zabbix-hostgroups.js";
|
||||||
import {ZABBIX_EDGE_DEVICE_BASE_GROUP, zabbixAPI} from "../datasources/zabbix-api.js";
|
import {ZABBIX_EDGE_DEVICE_BASE_GROUP, zabbixAPI} from "../datasources/zabbix-api.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles importing hosts and host groups into Zabbix.
|
||||||
|
*/
|
||||||
export class HostImporter {
|
export class HostImporter {
|
||||||
|
/**
|
||||||
|
* Extracts and sorts all parent group names from a list of host groups to ensure correct hierarchy creation.
|
||||||
|
* @param hostGroups - The list of host groups to process.
|
||||||
|
* @returns A sorted array of host groups including parents.
|
||||||
|
*/
|
||||||
public static getHostGroupHierarchyNames(hostGroups: Array<CreateHostGroup>) {
|
public static getHostGroupHierarchyNames(hostGroups: Array<CreateHostGroup>) {
|
||||||
let nameToGroup = new Map<string, CreateHostGroup>()
|
let nameToGroup = new Map<string, CreateHostGroup>()
|
||||||
for (let group of hostGroups || []) {
|
for (let group of hostGroups || []) {
|
||||||
|
|
@ -31,6 +39,13 @@ export class HostImporter {
|
||||||
return Array.from(nameToGroup.values()).sort((a, b) => a.groupName.localeCompare(b.groupName))
|
return Array.from(nameToGroup.values()).sort((a, b) => a.groupName.localeCompare(b.groupName))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports host groups into Zabbix, respecting hierarchy.
|
||||||
|
* @param hostGroups - The list of host groups to import.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of import responses.
|
||||||
|
*/
|
||||||
public static async importHostGroups(hostGroups: InputMaybe<Array<CreateHostGroup>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
public static async importHostGroups(hostGroups: InputMaybe<Array<CreateHostGroup>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
||||||
|
|
||||||
if (!hostGroups) {
|
if (!hostGroups) {
|
||||||
|
|
@ -92,6 +107,13 @@ export class HostImporter {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports hosts into Zabbix, linking them to groups and templates.
|
||||||
|
* @param hosts - The list of hosts to import.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of import responses.
|
||||||
|
*/
|
||||||
static async importHosts(hosts: InputMaybe<Array<CreateHost>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
static async importHosts(hosts: InputMaybe<Array<CreateHost>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
||||||
if (!hosts) {
|
if (!hosts) {
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,16 @@ import {ZabbixQueryTemplatesRequest} from "../datasources/zabbix-templates.js";
|
||||||
import {isZabbixErrorResult, ParsedArgs, ZabbixRequest} from "../datasources/zabbix-request.js";
|
import {isZabbixErrorResult, ParsedArgs, ZabbixRequest} from "../datasources/zabbix-request.js";
|
||||||
import {ZabbixHistoryPushParams, ZabbixHistoryPushRequest} from "../datasources/zabbix-history.js";
|
import {ZabbixHistoryPushParams, ZabbixHistoryPushRequest} from "../datasources/zabbix-history.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the execution of regression tests to ensure bug fixes remain effective.
|
||||||
|
*/
|
||||||
export class RegressionTestExecutor {
|
export class RegressionTestExecutor {
|
||||||
|
/**
|
||||||
|
* Runs all regression tests, including locations query order, template lookup, HTTP Agent support, macro assignment, and more.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to a smoketest response containing the success status and detailed steps.
|
||||||
|
*/
|
||||||
public static async runAllRegressionTests(zabbixAuthToken?: string, cookie?: string): Promise<SmoketestResponse> {
|
public static async runAllRegressionTests(zabbixAuthToken?: string, cookie?: string): Promise<SmoketestResponse> {
|
||||||
const steps: SmoketestStep[] = [];
|
const steps: SmoketestStep[] = [];
|
||||||
let success = true;
|
let success = true;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,19 @@ import {zabbixAPI} from "../datasources/zabbix-api.js";
|
||||||
import {ZabbixQueryHostsGenericRequest} from "../datasources/zabbix-hosts.js";
|
import {ZabbixQueryHostsGenericRequest} from "../datasources/zabbix-hosts.js";
|
||||||
import {ParsedArgs} from "../datasources/zabbix-request.js";
|
import {ParsedArgs} from "../datasources/zabbix-request.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the execution of a complete smoketest in Zabbix.
|
||||||
|
*/
|
||||||
export class SmoketestExecutor {
|
export class SmoketestExecutor {
|
||||||
|
/**
|
||||||
|
* Runs a smoketest by creating a template, host group, and host, verifying their creation and linkage, and then cleaning up.
|
||||||
|
* @param hostName - The technical name of the host to create during the test.
|
||||||
|
* @param templateName - The technical name of the template to create during the test.
|
||||||
|
* @param groupName - The technical name of the host group to create during the test.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to a smoketest response containing the success status and detailed steps.
|
||||||
|
*/
|
||||||
public static async runSmoketest(hostName: string, templateName: string, groupName: string, zabbixAuthToken?: string, cookie?: string): Promise<SmoketestResponse> {
|
public static async runSmoketest(hostName: string, templateName: string, groupName: string, zabbixAuthToken?: string, cookie?: string): Promise<SmoketestResponse> {
|
||||||
const steps: SmoketestStep[] = [];
|
const steps: SmoketestStep[] = [];
|
||||||
let success = true;
|
let success = true;
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,19 @@ import {
|
||||||
import {isZabbixErrorResult, ParsedArgs} from "../datasources/zabbix-request.js";
|
import {isZabbixErrorResult, ParsedArgs} from "../datasources/zabbix-request.js";
|
||||||
import {zabbixAPI} from "../datasources/zabbix-api.js";
|
import {zabbixAPI} from "../datasources/zabbix-api.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles deleting templates and template groups from Zabbix.
|
||||||
|
*/
|
||||||
export class TemplateDeleter {
|
export class TemplateDeleter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes templates based on their IDs or a name pattern.
|
||||||
|
* @param templateids - The IDs of the templates to delete.
|
||||||
|
* @param name_pattern - Optional wildcard name pattern for filtering templates.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of delete responses.
|
||||||
|
*/
|
||||||
public static async deleteTemplates(templateids: number[] | null | undefined, name_pattern?: string | null, zabbixAuthToken?: string, cookie?: string): Promise<DeleteResponse[]> {
|
public static async deleteTemplates(templateids: number[] | null | undefined, name_pattern?: string | null, zabbixAuthToken?: string, cookie?: string): Promise<DeleteResponse[]> {
|
||||||
const result: DeleteResponse[] = [];
|
const result: DeleteResponse[] = [];
|
||||||
let idsToDelete = templateids ? [...templateids] : [];
|
let idsToDelete = templateids ? [...templateids] : [];
|
||||||
|
|
@ -55,6 +66,14 @@ export class TemplateDeleter {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes template groups based on their IDs or a name pattern.
|
||||||
|
* @param groupids - The IDs of the template groups to delete.
|
||||||
|
* @param name_pattern - Optional wildcard name pattern for filtering template groups.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of delete responses.
|
||||||
|
*/
|
||||||
public static async deleteTemplateGroups(groupids: number[] | null | undefined, name_pattern?: string | null, zabbixAuthToken?: string, cookie?: string): Promise<DeleteResponse[]> {
|
public static async deleteTemplateGroups(groupids: number[] | null | undefined, name_pattern?: string | null, zabbixAuthToken?: string, cookie?: string): Promise<DeleteResponse[]> {
|
||||||
const result: DeleteResponse[] = [];
|
const result: DeleteResponse[] = [];
|
||||||
let idsToDelete = groupids ? [...groupids] : [];
|
let idsToDelete = groupids ? [...groupids] : [];
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,18 @@ import {
|
||||||
import {isZabbixErrorResult, ParsedArgs, ZabbixErrorResult} from "../datasources/zabbix-request.js";
|
import {isZabbixErrorResult, ParsedArgs, ZabbixErrorResult} from "../datasources/zabbix-request.js";
|
||||||
import {zabbixAPI} from "../datasources/zabbix-api.js";
|
import {zabbixAPI} from "../datasources/zabbix-api.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles importing templates and template groups into Zabbix.
|
||||||
|
*/
|
||||||
export class TemplateImporter {
|
export class TemplateImporter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports template groups into Zabbix.
|
||||||
|
* @param templateGroups - The list of template groups to import.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of import responses.
|
||||||
|
*/
|
||||||
public static async importTemplateGroups(templateGroups: InputMaybe<Array<CreateTemplateGroup>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
public static async importTemplateGroups(templateGroups: InputMaybe<Array<CreateTemplateGroup>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
||||||
if (!templateGroups) {
|
if (!templateGroups) {
|
||||||
return null
|
return null
|
||||||
|
|
@ -79,6 +89,13 @@ export class TemplateImporter {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imports templates into Zabbix, including their items and linked templates.
|
||||||
|
* @param templates - The list of templates to import.
|
||||||
|
* @param zabbixAuthToken - Optional Zabbix authentication token.
|
||||||
|
* @param cookie - Optional session cookie.
|
||||||
|
* @returns A promise that resolves to an array of import responses.
|
||||||
|
*/
|
||||||
public static async importTemplates(templates: InputMaybe<Array<CreateTemplate>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
public static async importTemplates(templates: InputMaybe<Array<CreateTemplate>> | undefined, zabbixAuthToken?: string, cookie?: string) {
|
||||||
if (!templates) {
|
if (!templates) {
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
// Zabbix value enum mappings
|
// Zabbix value enum mappings
|
||||||
|
/**
|
||||||
|
* Communication types used by Zabbix items.
|
||||||
|
*/
|
||||||
export enum DeviceCommunicationType {
|
export enum DeviceCommunicationType {
|
||||||
ZABBIX_AGENT = "0",
|
ZABBIX_AGENT = "0",
|
||||||
ZABBIX_TRAP = "2",
|
ZABBIX_TRAP = "2",
|
||||||
|
|
@ -16,17 +19,26 @@ export enum DeviceCommunicationType {
|
||||||
SIMULATOR_JAVASCRIPT = "21",
|
SIMULATOR_JAVASCRIPT = "21",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status of a Zabbix device or item.
|
||||||
|
*/
|
||||||
export enum DeviceStatus {
|
export enum DeviceStatus {
|
||||||
ENABLED = "0",
|
ENABLED = "0",
|
||||||
DISABLED = "1"
|
DISABLED = "1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Types of storage for Zabbix items.
|
||||||
|
*/
|
||||||
export enum StorageItemType {
|
export enum StorageItemType {
|
||||||
Float = 0,
|
Float = 0,
|
||||||
Int = 3,
|
Int = 3,
|
||||||
Text = 4,
|
Text = 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error codes returned by the API.
|
||||||
|
*/
|
||||||
export enum ApiErrorCode {
|
export enum ApiErrorCode {
|
||||||
OK = 0,
|
OK = 0,
|
||||||
ZABBIX_ERROR = 1000,
|
ZABBIX_ERROR = 1000,
|
||||||
|
|
@ -45,6 +57,9 @@ export enum ApiErrorCode {
|
||||||
PERMISSION_ERROR = 2002,
|
PERMISSION_ERROR = 2002,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error messages returned by the API.
|
||||||
|
*/
|
||||||
export enum ApiErrorMessage {
|
export enum ApiErrorMessage {
|
||||||
OK = "",
|
OK = "",
|
||||||
ZABBIX_NO_TRAPPER_ITEMS_FOR_PUSHING_VALUES_FOUND = "Unable to push value to history, didn't find corresponding trapper item",
|
ZABBIX_NO_TRAPPER_ITEMS_FOR_PUSHING_VALUES_FOUND = "Unable to push value to history, didn't find corresponding trapper item",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue