Compare commits

..

No commits in common. "b894687bea50b3f89b10df977613942b10258559" and "3c3cb7c7534a56a80e2f3861964fd3ed209eedaa" have entirely different histories.

27 changed files with 20 additions and 690 deletions

47
.idea/workspace.xml generated
View file

@ -6,31 +6,16 @@
<component name="ChangeListManager">
<list default="true" id="d7a71994-2699-4ae4-9fd2-ee13b7f33d35" name="Changes" comment="docs: refactor documentation and upgrade to Node.js 24&#10;&#10;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).&#10;&#10;Changes:&#10;- Environment &amp; CI/CD:&#10; - Set Node.js version to &gt;=24 in package.json and .nvmrc.&#10; - Updated Dockerfile to use Node 24 base image.&#10; - Updated @types/node to ^24.10.9.&#10;- Documentation:&#10; - Refactored README.md with comprehensive technical reference, configuration details, and Zabbix-to-GraphQL mapping.&#10; - Created docs/howtos/cookbook.md with practical recipes for common tasks and AI test generation.&#10; - Updated docs/howtos/mcp.md to emphasize GraphQL's advantages for AI agents and Model Context Protocol.&#10; - Added readme.improvement.plan.md to track documentation evolution.&#10; - Enhanced all how-to guides with improved cross-references and up-to-date information.&#10;- Guidelines:&#10; - Updated .junie/guidelines.md with Node 24 requirements and enhanced commit message standards (Conventional Commits 1.0.0).&#10;- Infrastructure &amp; Code:&#10; - Updated docker-compose.yml with Apollo MCP server integration.&#10; - Refined configuration and schema handling in src/api/ and src/datasources/.&#10; - 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$/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$/src/api/graphql_utils.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/api/graphql_utils.ts" 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$/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$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" 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$/docs/howtos/maintenance.md" beforeDir="false" afterPath="$PROJECT_DIR$/docs/howtos/maintenance.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/roadmap.md" beforeDir="false" afterPath="$PROJECT_DIR$/roadmap.md" 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-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-userroles.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/datasources/zabbix-userroles.ts" afterDir="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" />
<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/test/zabbix_6_0_compatibility.test.ts" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -41,7 +26,7 @@
<execution />
</component>
<component name="EmbeddingIndexingInfo">
<option name="cachedIndexableFilesCount" value="175" />
<option name="cachedIndexableFilesCount" value="172" />
<option name="fileBasedEmbeddingIndicesEnabled" value="true" />
</component>
<component name="Git.Settings">
@ -67,7 +52,13 @@
</component>
<component name="McpProjectServerCommands">
<commands />
<urls />
<urls>
<McpServerConfigurationProperties>
<option name="allowedToolsNames" />
<option name="enabled" value="true" />
<option name="name" value="zabbix-graphql" />
</McpServerConfigurationProperties>
</urls>
</component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="CurrentFile" />
@ -99,7 +90,7 @@
"RunOnceActivity.git.unshallow": "true",
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
"com.intellij.ml.llm.matterhorn.ej.ui.settings.DefaultModelSelectionForGA.v1": "true",
"git-widget-placeholder": "main",
"git-widget-placeholder": "feature-improve-zabbix-version-compatiblity",
"go.import.settings.migrated": "true",
"javascript.preferred.runtime.type.id": "node",
"junie.onboarding.icon.badge.shown": "true",
@ -115,7 +106,7 @@
"npm.copy-schema.executor": "Run",
"npm.prod.executor": "Run",
"npm.test.executor": "Run",
"settings.editor.selected.configurable": "ml.llm.mcp",
"settings.editor.selected.configurable": "junie.mcp",
"settings.editor.splitter.proportion": "0.23751687",
"to.speed.mode.migration.done": "true",
"ts.external.directory.path": "\\\\wsl.localhost\\Ubuntu\\home\\ahilbig\\git\\vcr\\zabbix-graphql-api\\node_modules\\typescript\\lib",
@ -236,8 +227,6 @@
<workItem from="1770129804879" duration="13000" />
<workItem from="1770129846593" duration="5283000" />
<workItem from="1770167580486" duration="16982000" />
<workItem from="1770799063115" duration="1101000" />
<workItem from="1770800423630" duration="4799000" />
</task>
<task id="LOCAL-00001" summary="chore: Update IntelliJ workspace settings and add GitHub Actions workflow for Docker deployment">
<option name="closed" value="true" />
@ -502,12 +491,12 @@
<breakpoints>
<line-breakpoint enabled="true" type="javascript">
<url>file://$PROJECT_DIR$/src/datasources/zabbix-request.ts</url>
<line>152</line>
<line>135</line>
<option name="timeStamp" value="5" />
</line-breakpoint>
<line-breakpoint enabled="true" type="javascript">
<url>file://$PROJECT_DIR$/src/datasources/zabbix-request.ts</url>
<line>338</line>
<line>276</line>
<option name="timeStamp" value="6" />
</line-breakpoint>
</breakpoints>

View file

@ -1 +0,0 @@
{"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"}]}}}

View file

@ -36,7 +36,7 @@ We use the `state.current.json_geojson` key for the trapper item. The `json_` pr
"type": 2,
"key": "state.current.json_geojson",
"value_type": 4,
"history": "31d",
"history": "7d",
"description": "Trapper item receiving GeoJSON payloads"
}
]

View file

@ -1,10 +1,5 @@
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[] {
if (!info || !info.fieldNodes) return [];
const fields: string[] = [];

View file

@ -2,11 +2,6 @@ import {isObjectType} from "graphql";
import {logger} from "../logging/logger.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;
/*
As a default all . - seperators within a key shall be replaced by a Capital letter of the following word
@ -54,13 +49,6 @@ export function createHierarchicalValueFieldResolver(
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(
fieldname: string,
parent: {
@ -88,13 +76,6 @@ export function zabbixItemValueSourceFieldMapper(
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(
fieldname: string,
tags: [{ tag: string, value: any }],

View file

@ -67,11 +67,6 @@ import {Config} from "../common_utils.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 {
// @ts-ignore
// @ts-ignore

View file

@ -1,42 +1,19 @@
import {GraphQLResolveInfo} from "graphql";
import {getRequestedFields} from "../api/graphql_utils.js";
/**
* Helper class to map GraphQL request information to the fields needed from Zabbix.
*/
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[] {
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[] {
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[] {
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[] {
return getRequestedFields(info);
}

View file

@ -14,18 +14,10 @@ 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 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
extends RESTDataSource {
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) {
super(config);
logger.info("Connecting to Zabbix at url=" + this.baseURL)
@ -90,10 +82,6 @@ export class ZabbixAPI
private static version: string | undefined
/**
* Retrieves the Zabbix API version.
* @returns A promise that resolves to the version string.
*/
async getVersion(): Promise<string> {
if (!ZabbixAPI.version) {
const response = await this.requestByPath<string>("apiinfo.version")
@ -106,39 +94,14 @@ export class ZabbixAPI
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> {
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[]) {
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) {
const hosts_promise = this.requestByPath("host.get", args, authToken, cookies);
return hosts_promise.then(response => {

View file

@ -16,26 +16,13 @@ export interface ZabbixExportValue extends ZabbixValue, ZabbixResult {
itemid?: string
}
/**
* Parameters for querying history from Zabbix.
*/
export class ZabbixHistoryGetParams extends ParsedArgs {
time_from_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[],
public output: string[] = ["value", "itemid", "clock", "ns"],
public limit: number | null | undefined = undefined,
public limit: number | null = Array.isArray(itemids) ? itemids.length : 1,
public history: StorageItemType | string = StorageItemType.Text,
time_from?: Date,
time_until?: Date,
@ -48,14 +35,7 @@ export class ZabbixHistoryGetParams extends ParsedArgs {
}
}
/**
* Request to query history from Zabbix.
*/
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) {
super("history.get", authToken, cookie);
}
@ -85,16 +65,7 @@ export interface ZabbixHistoryPushResult {
error?: ApiError | string[]
}
/**
* Parameters for pushing history to Zabbix.
*/
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,
public key?: string,
public host?: string,) {
@ -102,14 +73,7 @@ export class ZabbixHistoryPushParams extends ParsedArgs {
}
}
/**
* Request to push history to Zabbix.
*/
export class ZabbixHistoryPushRequest extends ZabbixRequest<ZabbixHistoryPushResult, ZabbixHistoryPushParams> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string) {
super("history.push", authToken, cookie);
}

View file

@ -21,28 +21,15 @@ const hostGroupReadWritePermissions = {
}]
}
/**
* Request to create a host group in Zabbix.
*/
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) {
super("hostgroup.create", zabbixPrivilegeEscalationToken, cookie, hostGroupReadWritePermissions);
}
}
/**
* Parameters for querying host groups from Zabbix.
*/
export class ZabbixQueryHostgroupsParams extends ParsedArgs {
search_name: string | undefined
/**
* @param args - The raw arguments.
*/
constructor(args?: any) {
super(args);
if ("search_name" in args && typeof (args.search_name) == "string") {
@ -58,16 +45,8 @@ export type ZabbixQueryHostgroupsResult = {
uuid: string
}
/**
* Request to query host groups from Zabbix.
*/
export class ZabbixQueryHostgroupsRequest extends ZabbixRequestWithPermissions<ZabbixQueryHostgroupsResult[],
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) {
super("hostgroup.get", authToken, cookie, hostGroupReadPermissions,);
}
@ -90,14 +69,7 @@ export class ZabbixQueryHostgroupsRequest extends ZabbixRequestWithPermissions<Z
}
/**
* Request to delete host groups in Zabbix.
*/
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) {
super("hostgroup.delete", authToken, cookie, hostGroupReadWritePermissions);
}
@ -112,14 +84,6 @@ export class GroupHelper {
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) {
let result: number[] = []
for (let groupName of groupNames) {

View file

@ -12,17 +12,9 @@ import {ZabbixHistoryGetParams, ZabbixQueryHistoryRequest} from "./zabbix-histor
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> {
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) {
super(path, authToken, cookie);
this.skippableZabbixParams.set("selectParentTemplates", "parentTemplates");
@ -33,23 +25,10 @@ export class ZabbixQueryHostsGenericRequest<T extends ZabbixResult, A extends Pa
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> {
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 {
const params: any = {
...super.createZabbixParams(args),
@ -79,16 +58,9 @@ export class ZabbixQueryHostsGenericRequest<T extends ZabbixResult, A extends Pa
}
/**
* Request to query host metadata from Zabbix.
*/
export class ZabbixQueryHostsMetaRequest extends ZabbixQueryHostsGenericRequest<Host[]> {
public static PATH = "host.get.meta";
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null) {
super(ZabbixQueryHostsMetaRequest.PATH, authToken, cookie);
}
@ -102,15 +74,7 @@ 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> {
/**
* @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) {
super(path, authToken, cookie);
this.skippableZabbixParams.set("selectItems", "items");
@ -203,15 +167,7 @@ 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> {
/**
* @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) {
super(path, authToken, cookie);
this.skippableZabbixParams.set("selectInventory", "inventory");
@ -233,13 +189,7 @@ export class ZabbixQueryHostsRequestWithItemsAndInventory extends ZabbixQueryHos
}
}
/**
* Arguments for querying devices.
*/
export class ZabbixQueryDevicesArgs extends ParsedArgs {
/**
* @param args - The raw arguments.
*/
constructor(public args?: any) {
if (!args?.tag_deviceType ||
(Array.isArray(args.tag_deviceType) && !args.tag_deviceType.length)) {
@ -249,14 +199,7 @@ export class ZabbixQueryDevicesArgs extends ParsedArgs {
}
}
/**
* Request to query devices from Zabbix.
*/
export class ZabbixQueryDevices extends ZabbixQueryHostsGenericRequestWithItemsAndInventory<Device[], ZabbixQueryDevicesArgs> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string) {
super("host.get.with_items", authToken, cookie);
}
@ -329,14 +272,7 @@ class ZabbixCreateHostParams implements ZabbixParams {
}
/**
* Request to create a host in Zabbix.
*/
export class ZabbixCreateHostRequest extends ZabbixRequest<CreateHostResponse> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string) {
super("host.create", authToken, cookie);
}
@ -350,14 +286,7 @@ export class ZabbixCreateHostRequest extends ZabbixRequest<CreateHostResponse> {
}
}
/**
* Request to delete hosts in Zabbix.
*/
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) {
super("host.delete", authToken, cookie);
}

View file

@ -2,23 +2,11 @@ import {ParsedArgs, ZabbixRequest} from "./zabbix-request.js";
import {ZabbixItem} from "../schema/generated/graphql.js";
/**
* Request to query items from Zabbix.
*/
export class ZabbixQueryItemsRequest extends ZabbixRequest<ZabbixItem[]> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string) {
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) {
return {
"templated": false,

View file

@ -1,14 +1,7 @@
import {ParsedArgs, ZabbixParams, ZabbixRequest} from "./zabbix-request.js";
import {UserRoleModule} from "../schema/generated/graphql.js";
/**
* Request to query modules from Zabbix.
*/
export class ZabbixQueryModulesRequest extends ZabbixRequest<UserRoleModule[]> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null) {
super("module.get", authToken, cookie);
}

View file

@ -5,38 +5,18 @@ import {ApiErrorCode, PermissionNumber} from "../model/model_enum_values.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> {
/**
* @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,
protected permissionsNeeded?: QueryHasPermissionsArgs) {
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> {
// If prepare returns something else than undefined, the execution will be skipped and the
// result returned
this.prepResult = await this.assureUserPermissions(zabbixAPI);
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) {
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
@ -124,14 +104,6 @@ export class ZabbixPermissionsHelper {
private static permissionObjectNameCache: Map<string, string | null> = new Map()
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,
objectNames?: InputMaybe<string[]> | undefined): Promise<UserPermission[]> {
return Array.from((await this.getUserPermissionNumbers(zabbixAPI, zabbixAuthToken, cookie, objectNames)).entries()).map(value => {
@ -239,14 +211,6 @@ export class ZabbixPermissionsHelper {
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> {
let permissions = await this.getUserPermissionNumbers(zabbixAPI, zabbixAuthToken, cookie);
for (const permission of args.permissions) {

View file

@ -33,18 +33,11 @@ export interface ZabbixWithTagsParams extends ZabbixParams {
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 {
public name_pattern?: string
public distinct_by_name?: boolean;
public zabbix_params: ZabbixParams[] | ZabbixParams
/**
* @param params - The raw parameters to parse.
*/
constructor(params?: any) {
if (Array.isArray(params)) {
this.zabbix_params = params.map(arg => this.parseArgObject(arg))
@ -53,11 +46,6 @@ 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 {
if (this.zabbix_params instanceof Array) {
return undefined
@ -66,11 +54,6 @@ export class ParsedArgs {
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) {
if (args && (typeof args !== 'object' || args.constructor !== Object)) {
return args;
@ -163,9 +146,6 @@ export class ParsedArgs {
}
}
/**
* Base class for all Zabbix API requests.
*/
export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = ParsedArgs> {
protected requestBodyTemplate: ZabbixRequestBody;
protected method: string
@ -173,22 +153,11 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
protected skippableZabbixParams: 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) {
this.method = path.split(".", 2).join(".");
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 {
if (!output || output.length === 0) {
return params;
@ -233,24 +202,10 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
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 {
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 {
let params: ZabbixParams
if (Array.isArray(args?.zabbix_params)) {
@ -278,10 +233,6 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
return body
};
/**
* Returns the HTTP headers for the Zabbix API call.
* @returns The HTTP headers.
*/
headers() {
let headers: {
"Content-Type": string
@ -304,25 +255,12 @@ 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> {
// If prepare returns something else than undefined, the execution will be skipped and the
// result returned
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> {
let prepareResult = await this.prepare(zabbixAPI, args);
if (prepareResult) {
@ -361,14 +299,6 @@ 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> {
let response = await this.executeRequestReturnError(zabbixApi, args, output);
if (isZabbixErrorResult(response)) {
@ -387,34 +317,16 @@ export class ZabbixRequest<T extends ZabbixResult, A extends ParsedArgs = Parsed
}
/**
* Parameters for creating or updating entities in Zabbix.
*/
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) {
super(args);
}
}
/**
* Request to create or update entities in Zabbix.
* Automatically checks if an entity with the same name already exists.
*/
export class ZabbixCreateOrUpdateRequest<
T extends ZabbixResult,
P extends ZabbixRequest<ZabbixResult>,
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,
public updateExistingIdFieldname: string,
private prepareType: new (authToken?: string | null, cookie?: string | null) => P, authToken?: string | null, cookie?: string | null) {

View file

@ -3,21 +3,12 @@ import {ApiErrorCode} from "../model/model_enum_values.js";
import {isZabbixErrorResult, ParsedArgs, ZabbixErrorResult, ZabbixParams, ZabbixRequest} from "./zabbix-request.js";
import {ZabbixQueryHostsMetaRequest} from "./zabbix-hosts.js";
/**
* Parameters for forcing a Zabbix configuration cache reload.
*/
export class ZabbixForceCacheReloadParams extends ParsedArgs {
/**
* @param hostid - The ID of the host to execute the script on.
*/
constructor(public hostid: number) {
super();
}
}
/**
* Request to force a Zabbix configuration cache reload.
*/
export class ZabbixForceCacheReloadRequest extends ZabbixRequest<{
response: string
value: string
@ -36,10 +27,6 @@ export class ZabbixForceCacheReloadRequest extends ZabbixRequest<{
"scope": "2"
};
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null) {
super("script.execute", authToken, cookie);
}

View file

@ -12,25 +12,12 @@ export interface ZabbixQueryTemplateResponse {
}
/**
* Request to query templates from Zabbix.
*/
export class ZabbixQueryTemplatesRequest extends ZabbixRequest<ZabbixQueryTemplateResponse[]> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null,) {
super("template.get", authToken, cookie);
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 {
return this.optimizeZabbixParams({
"selectItems": "extend",
@ -39,13 +26,6 @@ export class ZabbixQueryTemplatesRequest extends ZabbixRequest<ZabbixQueryTempla
}, 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[]> {
let result = await super.executeRequestReturnError(zabbixAPI, args, output);
@ -84,93 +64,44 @@ export interface ZabbixQueryTemplateGroupResponse {
uuid: string
}
/**
* Request to query template groups from Zabbix.
*/
export class ZabbixQueryTemplateGroupRequest extends ZabbixRequest<ZabbixQueryTemplateGroupResponse[]> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null) {
super("templategroup.get", authToken, cookie);
}
}
/**
* Request to create a template group in Zabbix.
*/
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) {
super("templategroup.create", authToken, cookie);
}
}
/**
* Request to create a template in Zabbix.
*/
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) {
super("template.create", authToken, cookie);
}
}
/**
* Request to query items from Zabbix.
*/
export class ZabbixQueryItemRequest extends ZabbixRequest<any[]> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null) {
super("item.get", authToken, cookie);
}
}
/**
* Request to create an item in Zabbix.
*/
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) {
super("item.create", authToken, cookie);
}
}
/**
* Request to delete templates in Zabbix.
*/
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) {
super("template.delete", authToken, cookie);
}
}
/**
* Request to delete template groups in Zabbix.
*/
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) {
super("templategroup.delete", authToken, cookie);
}
@ -178,14 +109,6 @@ export class ZabbixDeleteTemplateGroupsRequest extends ZabbixRequest<{ groupids:
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) {
let result: number[] = []
for (let templateName of templateNames) {

View file

@ -56,16 +56,9 @@ abstract class ZabbixPrepareGetTemplatesAndHostgroupsRequest<T extends ZabbixRes
}
}
/**
* Arguments for exporting user groups.
*/
export class ZabbixExportUserGroupArgs extends ParsedArgs {
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) {
super(name_pattern? {name_pattern: name_pattern} : undefined);
if (exclude_hostgroups_pattern_str) {
@ -74,15 +67,8 @@ export class ZabbixExportUserGroupArgs extends ParsedArgs {
}
}
/**
* Request to export user groups from Zabbix.
*/
export class ZabbixExportUserGroupsRequest extends ZabbixPrepareGetTemplatesAndHostgroupsRequest<
UserGroup[], ZabbixExportUserGroupArgs> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string) {
super("usergroup.get.withuuids", authToken, cookie);
}
@ -131,14 +117,7 @@ export class ZabbixExportUserGroupsRequest extends ZabbixPrepareGetTemplatesAndH
}
}
/**
* Request to query user groups from Zabbix.
*/
export class ZabbixQueryUserGroupsRequest extends ZabbixRequest<UserGroup[]> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null) {
super("usergroup.get", authToken, cookie);
}
@ -151,29 +130,15 @@ export class ZabbixQueryUserGroupsRequest extends ZabbixRequest<UserGroup[]> {
}
}
/**
* Parameters for importing user groups.
*/
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) {
super();
}
}
/**
* Request to import user groups into Zabbix.
*/
export class ZabbixImportUserGroupsRequest
extends ZabbixPrepareGetTemplatesAndHostgroupsRequest<ImportUserRightResult[],
ZabbixImportUserGroupsParams> {
/**
* @param zabbixAuthToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(zabbixAuthToken: any, cookie: any) {
super("usergroup.create.import", zabbixAuthToken, cookie);
}
@ -363,15 +328,8 @@ class ZabbixPropagateHostGroupsParams extends ParsedArgs {
}
}
/**
* Request to propagate host group permissions to children in Zabbix.
*/
export class ZabbixPropagateHostGroupsRequest extends ZabbixRequest<ZabbixCreateUserGroupResponse,
ZabbixPropagateHostGroupsParams> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null) {
super("hostgroup.propagate", authToken, cookie);
}

View file

@ -26,14 +26,7 @@ export class ZabbixPrepareGetModulesRequest<T extends ZabbixResult, A extends Pa
}
}
/**
* Request to query user roles from Zabbix.
*/
export class ZabbixQueryUserRolesRequest extends ZabbixPrepareGetModulesRequest<UserRole[]> {
/**
* @param authToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(authToken?: string | null, cookie?: string | null) {
super("role.get", authToken, cookie);
}
@ -70,28 +63,14 @@ export class ZabbixQueryUserRolesRequest extends ZabbixPrepareGetModulesRequest<
}
}
/**
* Parameters for importing user roles.
*/
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) {
super();
}
}
/**
* Request to import user roles into Zabbix.
*/
export class ZabbixImportUserRolesRequest extends ZabbixPrepareGetModulesRequest<ImportUserRightResult[],
ZabbixImportUserRolesParams> {
/**
* @param zabbixAuthToken - Optional Zabbix authentication token.
* @param cookie - Optional session cookie.
*/
constructor(zabbixAuthToken: any, cookie: any) {
super("role.create.import", zabbixAuthToken, cookie);
}

View file

@ -12,19 +12,8 @@ import {
import {isZabbixErrorResult, ParsedArgs} from "../datasources/zabbix-request.js";
import {zabbixAPI} from "../datasources/zabbix-api.js";
/**
* Handles deleting hosts and host groups from Zabbix.
*/
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[]> {
const result: DeleteResponse[] = [];
let idsToDelete = hostids ? [...hostids] : [];
@ -71,14 +60,6 @@ export class HostDeleter {
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[]> {
const result: DeleteResponse[] = [];
let idsToDelete = groupids ? [...groupids] : [];

View file

@ -21,17 +21,7 @@ type ItemMapResponse = {
error?: ApiError
}
/**
* Handles exporting host history data from Zabbix.
*/
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> {
let itemMapResponse: ItemMapResponse = await HostValueExporter.queryItemsForFilterArgs(args, zabbixAuthToken, cookie);
if (itemMapResponse.error || !itemMapResponse.items) {
@ -85,13 +75,6 @@ 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> {
let hostFilter = args.host_filter
let itemKeyFilter = args.itemKey_filter

View file

@ -12,15 +12,7 @@ import {isZabbixErrorResult, ParsedArgs, ZabbixErrorResult} from "../datasources
import {CreateHostGroupResult, GroupHelper, ZabbixCreateHostGroupRequest} from "../datasources/zabbix-hostgroups.js";
import {ZABBIX_EDGE_DEVICE_BASE_GROUP, zabbixAPI} from "../datasources/zabbix-api.js";
/**
* Handles importing hosts and host groups into Zabbix.
*/
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>) {
let nameToGroup = new Map<string, CreateHostGroup>()
for (let group of hostGroups || []) {
@ -39,13 +31,6 @@ export class HostImporter {
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) {
if (!hostGroups) {
@ -107,13 +92,6 @@ export class HostImporter {
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) {
if (!hosts) {
return null

View file

@ -15,16 +15,7 @@ import {ZabbixQueryTemplatesRequest} from "../datasources/zabbix-templates.js";
import {isZabbixErrorResult, ParsedArgs, ZabbixRequest} from "../datasources/zabbix-request.js";
import {ZabbixHistoryPushParams, ZabbixHistoryPushRequest} from "../datasources/zabbix-history.js";
/**
* Handles the execution of regression tests to ensure bug fixes remain effective.
*/
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> {
const steps: SmoketestStep[] = [];
let success = true;

View file

@ -7,19 +7,7 @@ import {zabbixAPI} from "../datasources/zabbix-api.js";
import {ZabbixQueryHostsGenericRequest} from "../datasources/zabbix-hosts.js";
import {ParsedArgs} from "../datasources/zabbix-request.js";
/**
* Handles the execution of a complete smoketest in Zabbix.
*/
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> {
const steps: SmoketestStep[] = [];
let success = true;

View file

@ -8,19 +8,8 @@ import {
import {isZabbixErrorResult, ParsedArgs} from "../datasources/zabbix-request.js";
import {zabbixAPI} from "../datasources/zabbix-api.js";
/**
* Handles deleting templates and template groups from Zabbix.
*/
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[]> {
const result: DeleteResponse[] = [];
let idsToDelete = templateids ? [...templateids] : [];
@ -66,14 +55,6 @@ export class TemplateDeleter {
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[]> {
const result: DeleteResponse[] = [];
let idsToDelete = groupids ? [...groupids] : [];

View file

@ -17,18 +17,8 @@ import {
import {isZabbixErrorResult, ParsedArgs, ZabbixErrorResult} from "../datasources/zabbix-request.js";
import {zabbixAPI} from "../datasources/zabbix-api.js";
/**
* Handles importing templates and template groups into Zabbix.
*/
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) {
if (!templateGroups) {
return null
@ -89,13 +79,6 @@ export class TemplateImporter {
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) {
if (!templates) {
return null

View file

@ -1,7 +1,4 @@
// Zabbix value enum mappings
/**
* Communication types used by Zabbix items.
*/
export enum DeviceCommunicationType {
ZABBIX_AGENT = "0",
ZABBIX_TRAP = "2",
@ -19,26 +16,17 @@ export enum DeviceCommunicationType {
SIMULATOR_JAVASCRIPT = "21",
}
/**
* Status of a Zabbix device or item.
*/
export enum DeviceStatus {
ENABLED = "0",
DISABLED = "1"
}
/**
* Types of storage for Zabbix items.
*/
export enum StorageItemType {
Float = 0,
Int = 3,
Text = 4,
}
/**
* Error codes returned by the API.
*/
export enum ApiErrorCode {
OK = 0,
ZABBIX_ERROR = 1000,
@ -57,9 +45,6 @@ export enum ApiErrorCode {
PERMISSION_ERROR = 2002,
}
/**
* Error messages returned by the API.
*/
export enum ApiErrorMessage {
OK = "",
ZABBIX_NO_TRAPPER_ITEMS_FOR_PUSHING_VALUES_FOUND = "Unable to push value to history, didn't find corresponding trapper item",