sc-zabbix-api
Version:
TypeScript client for Zabbix JSON-RPC API with token authentication
106 lines (105 loc) • 3.63 kB
TypeScript
import { Host, HostGetParams, Item, ItemCreateParams, ItemGetParams, ItemUpdateParams, UserCheckAuthenticationParams, UserCheckAuthenticationResponse, UserLoginParams, UserLoginResponse, ZabbixApiConfig, ZabbixApiResponse } from "./types";
/**
* Zabbix API Client using token authentication or user/password login
* Provides methods to interact with Zabbix API endpoints.
*/
export declare class SCZabbixApi {
private readonly client;
private token;
private sessionId;
private requestId;
private config;
private initialized;
constructor(config: ZabbixApiConfig);
/**
* Auto-login using username/password when instance is created
* @private
*/
private autoLogin;
/**
* Create a standardized connection error
* @private
*/
private createConnectionError;
/**
* Sleep for specified milliseconds
* @private
*/
private sleep;
/**
* Retry logic with exponential backoff
* @private
*/
private withRetry;
/**
* Ensure the instance is initialized (auto-login completed if needed)
* @private
*/
private ensureInitialized;
/**
* Get the authentication token (either from token or session)
* @private
*/
private getAuthToken;
/**
* Login to Zabbix using username and password.
* This method authenticates a user and returns information about the user including a session ID.
* @param params - Login parameters
*/
UserLogin(params: UserLoginParams): Promise<ZabbixApiResponse<UserLoginResponse>>;
/**
* Checks if the user session is valid and returns user information.
* This method can be used to verify if a session ID or API token is still valid and to retrieve user details.
* @param params - Check authentication parameters
*/
UserCheckAuthentication(params?: UserCheckAuthenticationParams): Promise<ZabbixApiResponse<UserCheckAuthenticationResponse>>;
/**
* Logout from Zabbix and invalidate the current session.
*/
UserLogout(): Promise<ZabbixApiResponse<boolean>>;
/**
* This method allows to retrieve the version of the Zabbix API.
*/
ApiinfoVersion(): Promise<ZabbixApiResponse<string>>;
/**
* Test connectivity to Zabbix server
* This is a lightweight method to check if the server is reachable
*/
testConnection(): Promise<{
success: boolean;
version?: string;
error?: string;
latency?: number;
}>;
/**
* The method allows to retrieve hosts according to the given parameters.
* @param params - Parameters for host retrieval
*/
HostGet(params?: HostGetParams): Promise<ZabbixApiResponse<Host[]>>;
/**
* The method allows to retrieve items according to the given parameters.
* @param params - Parameters for item retrieval
*/
ItemGet(params?: ItemGetParams): Promise<ZabbixApiResponse<Item[]>>;
/**
* This method allows to create new items.
* @param params - Parameters for item creation
*/
ItemCreate(params: ItemCreateParams): Promise<ZabbixApiResponse<{
itemids: string[];
}>>;
/**
* This method allows to update existing items.
* @param params - Parameters for item update
*/
ItemUpdate(params: ItemUpdateParams): Promise<ZabbixApiResponse<{
itemids: string[];
}>>;
/**
* This method allows to delete items.
* @param params - Parameters for item deletion (array of item IDs)
*/
ItemDelete(params: string[]): Promise<ZabbixApiResponse<{
itemids: string[];
}>>;
}