diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6696220..df11802 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,16 +6,31 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
@@ -26,7 +41,7 @@
-
+
@@ -52,13 +67,7 @@
-
-
-
-
-
-
-
+
@@ -90,7 +99,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": "feature-improve-zabbix-version-compatiblity",
+ "git-widget-placeholder": "main",
"go.import.settings.migrated": "true",
"javascript.preferred.runtime.type.id": "node",
"junie.onboarding.icon.badge.shown": "true",
@@ -106,7 +115,7 @@
"npm.copy-schema.executor": "Run",
"npm.prod.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",
"to.speed.mode.migration.done": "true",
"ts.external.directory.path": "\\\\wsl.localhost\\Ubuntu\\home\\ahilbig\\git\\vcr\\zabbix-graphql-api\\node_modules\\typescript\\lib",
@@ -227,6 +236,8 @@
+
+
@@ -491,12 +502,12 @@
file://$PROJECT_DIR$/src/datasources/zabbix-request.ts
- 135
+ 152
file://$PROJECT_DIR$/src/datasources/zabbix-request.ts
- 276
+ 338
diff --git a/.output.txt b/.output.txt
new file mode 100644
index 0000000..18b4226
--- /dev/null
+++ b/.output.txt
@@ -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"}]}}}
\ No newline at end of file
diff --git a/docs/queries/sample_import_simulated_bt_template.graphql b/docs/queries/sample_import_simulated_bt_template.graphql
index 59d77db..636a150 100644
--- a/docs/queries/sample_import_simulated_bt_template.graphql
+++ b/docs/queries/sample_import_simulated_bt_template.graphql
@@ -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": "7d",
+ "history": "31d",
"description": "Trapper item receiving GeoJSON payloads"
}
]
diff --git a/src/api/graphql_utils.ts b/src/api/graphql_utils.ts
index 8b2aab8..ea988eb 100644
--- a/src/api/graphql_utils.ts
+++ b/src/api/graphql_utils.ts
@@ -1,5 +1,10 @@
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[] = [];
diff --git a/src/api/resolver_helpers.ts b/src/api/resolver_helpers.ts
index 8eaca8b..c7f1a27 100644
--- a/src/api/resolver_helpers.ts
+++ b/src/api/resolver_helpers.ts
@@ -2,6 +2,11 @@ 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
@@ -49,6 +54,13 @@ 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: {
@@ -76,6 +88,13 @@ 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 }],
diff --git a/src/api/resolvers.ts b/src/api/resolvers.ts
index 398587c..1f1ee53 100644
--- a/src/api/resolvers.ts
+++ b/src/api/resolvers.ts
@@ -67,6 +67,11 @@ 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
diff --git a/src/datasources/graphql-params-to-zabbix-output.ts b/src/datasources/graphql-params-to-zabbix-output.ts
index 4fb1629..e7f2abf 100644
--- a/src/datasources/graphql-params-to-zabbix-output.ts
+++ b/src/datasources/graphql-params-to-zabbix-output.ts
@@ -1,19 +1,42 @@
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);
}
diff --git a/src/datasources/zabbix-api.ts b/src/datasources/zabbix-api.ts
index 1ecaa73..4d515fa 100644
--- a/src/datasources/zabbix-api.ts
+++ b/src/datasources/zabbix-api.ts
@@ -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 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)
@@ -82,6 +90,10 @@ 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 {
if (!ZabbixAPI.version) {
const response = await this.requestByPath("apiinfo.version")
@@ -94,14 +106,39 @@ 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(zabbixRequest: ZabbixRequest, args?: A, throwApiError: boolean = true, output?: string[]): Promise {
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(path: string, args?: A, authToken?: string | null, cookies?: string, throwApiError: boolean = true, output?: string[]) {
return this.executeRequest(new ZabbixRequest(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 => {
diff --git a/src/datasources/zabbix-history.ts b/src/datasources/zabbix-history.ts
index db57459..d89bec0 100644
--- a/src/datasources/zabbix-history.ts
+++ b/src/datasources/zabbix-history.ts
@@ -16,10 +16,23 @@ 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 = 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 {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string | null) {
super("history.get", authToken, cookie);
}
@@ -65,7 +85,16 @@ 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,) {
@@ -73,7 +102,14 @@ export class ZabbixHistoryPushParams extends ParsedArgs {
}
}
+/**
+ * Request to push history to Zabbix.
+ */
export class ZabbixHistoryPushRequest extends ZabbixRequest {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string) {
super("history.push", authToken, cookie);
}
diff --git a/src/datasources/zabbix-hostgroups.ts b/src/datasources/zabbix-hostgroups.ts
index c2f3b6b..9960577 100644
--- a/src/datasources/zabbix-hostgroups.ts
+++ b/src/datasources/zabbix-hostgroups.ts
@@ -21,15 +21,28 @@ const hostGroupReadWritePermissions = {
}]
}
+/**
+ * Request to create a host group in Zabbix.
+ */
export class ZabbixCreateHostGroupRequest extends ZabbixRequestWithPermissions {
+ /**
+ * @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") {
@@ -45,8 +58,16 @@ export type ZabbixQueryHostgroupsResult = {
uuid: string
}
+/**
+ * Request to query host groups from Zabbix.
+ */
export class ZabbixQueryHostgroupsRequest extends ZabbixRequestWithPermissions {
+ /**
+ * @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,);
}
@@ -69,7 +90,14 @@ export class ZabbixQueryHostgroupsRequest extends ZabbixRequestWithPermissions {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string | null) {
super("hostgroup.delete", authToken, cookie, hostGroupReadWritePermissions);
}
@@ -84,6 +112,14 @@ 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) {
diff --git a/src/datasources/zabbix-hosts.ts b/src/datasources/zabbix-hosts.ts
index 8b5cb02..06a7284 100644
--- a/src/datasources/zabbix-hosts.ts
+++ b/src/datasources/zabbix-hosts.ts
@@ -12,9 +12,17 @@ import {ZabbixHistoryGetParams, ZabbixQueryHistoryRequest} from "./zabbix-histor
import {ZabbixQueryItemRequest} from "./zabbix-templates.js";
+/**
+ * Generic request to query hosts from Zabbix.
+ */
export class ZabbixQueryHostsGenericRequest extends ZabbixRequest {
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");
@@ -25,10 +33,23 @@ export class ZabbixQueryHostsGenericRequest {
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),
@@ -58,9 +79,16 @@ export class ZabbixQueryHostsGenericRequest {
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);
}
@@ -74,7 +102,15 @@ export class ZabbixQueryHostsMetaRequest extends ZabbixQueryHostsGenericRequest<
}
+/**
+ * Generic request to query hosts with their items from Zabbix.
+ */
export class ZabbixQueryHostsGenericRequestWithItems extends ZabbixQueryHostsGenericRequest {
+ /**
+ * @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");
@@ -167,7 +203,15 @@ export class ZabbixQueryHostsGenericRequestWithItems extends ZabbixQueryHostsGenericRequestWithItems {
+ /**
+ * @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");
@@ -189,7 +233,13 @@ 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)) {
@@ -199,7 +249,14 @@ export class ZabbixQueryDevicesArgs extends ParsedArgs {
}
}
+/**
+ * Request to query devices from Zabbix.
+ */
export class ZabbixQueryDevices extends ZabbixQueryHostsGenericRequestWithItemsAndInventory {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string) {
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 {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string) {
super("host.create", authToken, cookie);
}
@@ -286,7 +350,14 @@ export class ZabbixCreateHostRequest extends ZabbixRequest {
}
}
+/**
+ * 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);
}
diff --git a/src/datasources/zabbix-items.ts b/src/datasources/zabbix-items.ts
index 1ab4810..8f4fe37 100644
--- a/src/datasources/zabbix-items.ts
+++ b/src/datasources/zabbix-items.ts
@@ -2,11 +2,23 @@ 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 {
+ /**
+ * @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,
diff --git a/src/datasources/zabbix-module.ts b/src/datasources/zabbix-module.ts
index b1b950c..539728f 100644
--- a/src/datasources/zabbix-module.ts
+++ b/src/datasources/zabbix-module.ts
@@ -1,7 +1,14 @@
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 {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string | null) {
super("module.get", authToken, cookie);
}
diff --git a/src/datasources/zabbix-permissions.ts b/src/datasources/zabbix-permissions.ts
index b830521..c895060 100644
--- a/src/datasources/zabbix-permissions.ts
+++ b/src/datasources/zabbix-permissions.ts
@@ -5,18 +5,38 @@ 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 extends ZabbixRequest {
+ /**
+ * @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 {
// 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
@@ -104,6 +124,14 @@ export class ZabbixPermissionsHelper {
private static permissionObjectNameCache: Map = 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 | undefined): Promise {
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
}
+ /**
+ * 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 {
let permissions = await this.getUserPermissionNumbers(zabbixAPI, zabbixAuthToken, cookie);
for (const permission of args.permissions) {
diff --git a/src/datasources/zabbix-request.ts b/src/datasources/zabbix-request.ts
index 72bbcb1..f4f815f 100644
--- a/src/datasources/zabbix-request.ts
+++ b/src/datasources/zabbix-request.ts
@@ -33,11 +33,18 @@ 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))
@@ -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 {
if (this.zabbix_params instanceof Array) {
return undefined
@@ -54,6 +66,11 @@ 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;
@@ -146,6 +163,9 @@ export class ParsedArgs {
}
}
+/**
+ * Base class for all Zabbix API requests.
+ */
export class ZabbixRequest {
protected requestBodyTemplate: ZabbixRequestBody;
protected method: string
@@ -153,11 +173,22 @@ export class ZabbixRequest = new Map();
protected impliedFields: Map = 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;
@@ -202,10 +233,24 @@ export class ZabbixRequest {
// 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 {
let prepareResult = await this.prepare(zabbixAPI, args);
if (prepareResult) {
@@ -299,6 +361,14 @@ export class ZabbixRequest {
let response = await this.executeRequestReturnError(zabbixApi, args, output);
if (isZabbixErrorResult(response)) {
@@ -317,16 +387,34 @@ export class ZabbixRequest,
A extends ZabbixCreateOrUpdateParams = ZabbixCreateOrUpdateParams> extends ZabbixRequest {
+ /**
+ * @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) {
diff --git a/src/datasources/zabbix-script.ts b/src/datasources/zabbix-script.ts
index edfcd4d..bcbb115 100644
--- a/src/datasources/zabbix-script.ts
+++ b/src/datasources/zabbix-script.ts
@@ -3,12 +3,21 @@ 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
@@ -27,6 +36,10 @@ 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);
}
diff --git a/src/datasources/zabbix-templates.ts b/src/datasources/zabbix-templates.ts
index e6b7ad5..969a80e 100644
--- a/src/datasources/zabbix-templates.ts
+++ b/src/datasources/zabbix-templates.ts
@@ -12,12 +12,25 @@ export interface ZabbixQueryTemplateResponse {
}
+/**
+ * Request to query templates from Zabbix.
+ */
export class ZabbixQueryTemplatesRequest extends ZabbixRequest {
+ /**
+ * @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",
@@ -26,6 +39,13 @@ export class ZabbixQueryTemplatesRequest extends ZabbixRequest {
let result = await super.executeRequestReturnError(zabbixAPI, args, output);
@@ -64,44 +84,93 @@ export interface ZabbixQueryTemplateGroupResponse {
uuid: string
}
+/**
+ * Request to query template groups from Zabbix.
+ */
export class ZabbixQueryTemplateGroupRequest extends ZabbixRequest {
+ /**
+ * @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 {
+ /**
+ * @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);
}
@@ -109,6 +178,14 @@ 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) {
diff --git a/src/datasources/zabbix-usergroups.ts b/src/datasources/zabbix-usergroups.ts
index a7d76c0..88490f0 100644
--- a/src/datasources/zabbix-usergroups.ts
+++ b/src/datasources/zabbix-usergroups.ts
@@ -56,9 +56,16 @@ abstract class ZabbixPrepareGetTemplatesAndHostgroupsRequest {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string) {
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 {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string | null) {
super("usergroup.get", authToken, cookie);
}
@@ -130,15 +151,29 @@ export class ZabbixQueryUserGroupsRequest extends ZabbixRequest {
}
}
+/**
+ * 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 {
+ /**
+ * @param zabbixAuthToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(zabbixAuthToken: any, cookie: any) {
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 {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string | null) {
super("hostgroup.propagate", authToken, cookie);
}
diff --git a/src/datasources/zabbix-userroles.ts b/src/datasources/zabbix-userroles.ts
index 5095f01..c83d07c 100644
--- a/src/datasources/zabbix-userroles.ts
+++ b/src/datasources/zabbix-userroles.ts
@@ -26,7 +26,14 @@ export class ZabbixPrepareGetModulesRequest {
+ /**
+ * @param authToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(authToken?: string | null, cookie?: string | null) {
super("role.get", authToken, cookie);
}
@@ -63,14 +70,28 @@ 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 {
+ /**
+ * @param zabbixAuthToken - Optional Zabbix authentication token.
+ * @param cookie - Optional session cookie.
+ */
constructor(zabbixAuthToken: any, cookie: any) {
super("role.create.import", zabbixAuthToken, cookie);
}
diff --git a/src/execution/host_deleter.ts b/src/execution/host_deleter.ts
index 7288189..5481076 100644
--- a/src/execution/host_deleter.ts
+++ b/src/execution/host_deleter.ts
@@ -12,8 +12,19 @@ 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 {
const result: DeleteResponse[] = [];
let idsToDelete = hostids ? [...hostids] : [];
@@ -60,6 +71,14 @@ 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 {
const result: DeleteResponse[] = [];
let idsToDelete = groupids ? [...groupids] : [];
diff --git a/src/execution/host_exporter.ts b/src/execution/host_exporter.ts
index 563ffec..1154a9b 100644
--- a/src/execution/host_exporter.ts
+++ b/src/execution/host_exporter.ts
@@ -21,7 +21,17 @@ 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 {
let itemMapResponse: ItemMapResponse = await HostValueExporter.queryItemsForFilterArgs(args, zabbixAuthToken, cookie);
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 {
let hostFilter = args.host_filter
let itemKeyFilter = args.itemKey_filter
diff --git a/src/execution/host_importer.ts b/src/execution/host_importer.ts
index 43f4247..8ea070a 100644
--- a/src/execution/host_importer.ts
+++ b/src/execution/host_importer.ts
@@ -12,7 +12,15 @@ 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) {
let nameToGroup = new Map()
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))
}
+ /**
+ * 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> | undefined, zabbixAuthToken?: string, cookie?: string) {
if (!hostGroups) {
@@ -92,6 +107,13 @@ 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> | undefined, zabbixAuthToken?: string, cookie?: string) {
if (!hosts) {
return null
diff --git a/src/execution/regression_test_executor.ts b/src/execution/regression_test_executor.ts
index d3c49db..efb662f 100644
--- a/src/execution/regression_test_executor.ts
+++ b/src/execution/regression_test_executor.ts
@@ -15,7 +15,16 @@ 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 {
const steps: SmoketestStep[] = [];
let success = true;
diff --git a/src/execution/smoketest_executor.ts b/src/execution/smoketest_executor.ts
index f2a3598..95b682d 100644
--- a/src/execution/smoketest_executor.ts
+++ b/src/execution/smoketest_executor.ts
@@ -7,7 +7,19 @@ 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 {
const steps: SmoketestStep[] = [];
let success = true;
diff --git a/src/execution/template_deleter.ts b/src/execution/template_deleter.ts
index ac5a6b2..02dda74 100644
--- a/src/execution/template_deleter.ts
+++ b/src/execution/template_deleter.ts
@@ -8,8 +8,19 @@ 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 {
const result: DeleteResponse[] = [];
let idsToDelete = templateids ? [...templateids] : [];
@@ -55,6 +66,14 @@ 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 {
const result: DeleteResponse[] = [];
let idsToDelete = groupids ? [...groupids] : [];
diff --git a/src/execution/template_importer.ts b/src/execution/template_importer.ts
index e826806..3fb8c52 100644
--- a/src/execution/template_importer.ts
+++ b/src/execution/template_importer.ts
@@ -17,8 +17,18 @@ 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> | undefined, zabbixAuthToken?: string, cookie?: string) {
if (!templateGroups) {
return null
@@ -79,6 +89,13 @@ 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> | undefined, zabbixAuthToken?: string, cookie?: string) {
if (!templates) {
return null
diff --git a/src/model/model_enum_values.ts b/src/model/model_enum_values.ts
index 30c743c..dbe832a 100644
--- a/src/model/model_enum_values.ts
+++ b/src/model/model_enum_values.ts
@@ -1,4 +1,7 @@
// Zabbix value enum mappings
+/**
+ * Communication types used by Zabbix items.
+ */
export enum DeviceCommunicationType {
ZABBIX_AGENT = "0",
ZABBIX_TRAP = "2",
@@ -16,17 +19,26 @@ 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,
@@ -45,6 +57,9 @@ 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",