Merge branch 'exec-script' into backend

This commit is contained in:
Alexander Zobnin
2020-06-02 12:29:08 +03:00
9 changed files with 337 additions and 5 deletions

View File

@@ -37,6 +37,24 @@ export interface ZabbixRequestResponse {
data?: JSONRPCResponse<any>;
}
export type ZabbixAPIResponse<T> = T;
export type ZabbixAPIResponse<T> = Promise<T>;
export type APILoginResponse = string;
export interface ZBXScript {
scriptid: string;
name?: string;
command?: string;
host_access?: string;
usrgrpid?: string;
groupid?: string;
description?: string;
confirmation?: string;
type?: string;
execute_on?: string;
}
export interface APIExecuteScriptResponse {
response: 'success' | 'failed';
value?: string;
}

View File

@@ -4,7 +4,7 @@ import kbn from 'grafana/app/core/utils/kbn';
import * as utils from '../../../utils';
import { ZBX_ACK_ACTION_NONE, ZBX_ACK_ACTION_ADD_MESSAGE, MIN_SLA_INTERVAL } from '../../../constants';
import { ShowProblemTypes, ZBXProblem } from '../../../types';
import { GFHTTPRequest, JSONRPCError } from './types';
import { GFHTTPRequest, JSONRPCError, ZBXScript, APIExecuteScriptResponse } from './types';
import { getBackendSrv } from '@grafana/runtime';
const DEFAULT_ZABBIX_VERSION = '3.0.0';
@@ -629,6 +629,24 @@ export class ZabbixAPIConnector {
return this.request('proxy.get', params);
}
getScripts(hostids: string[], options?: any): Promise<ZBXScript[]> {
const params: any = {
output: 'extend',
hostids,
};
return this.request('script.get', params).then(utils.mustArray);
}
executeScript(hostid: string, scriptid: string): Promise<APIExecuteScriptResponse> {
const params: any = {
hostid,
scriptid,
};
return this.request('script.execute', params);
}
}
function filterTriggersByAcknowledge(triggers, acknowledged) {

View File

@@ -20,7 +20,7 @@ interface AppsResponse extends Array<any> {
const REQUESTS_TO_PROXYFY = [
'getHistory', 'getTrend', 'getGroups', 'getHosts', 'getApps', 'getItems', 'getMacros', 'getItemsByIDs',
'getEvents', 'getAlerts', 'getHostAlerts', 'getAcknowledges', 'getITService', 'getSLA', 'getVersion', 'getProxies',
'getEventAlerts', 'getExtendedEventData', 'getProblems', 'getEventsHistory', 'getTriggersByIds'
'getEventAlerts', 'getExtendedEventData', 'getProblems', 'getEventsHistory', 'getTriggersByIds', 'getScripts'
];
const REQUESTS_TO_CACHE = [
@@ -30,7 +30,7 @@ const REQUESTS_TO_CACHE = [
const REQUESTS_TO_BIND = [
'getHistory', 'getTrend', 'getMacros', 'getItemsByIDs', 'getEvents', 'getAlerts', 'getHostAlerts',
'getAcknowledges', 'getITService', 'getVersion', 'acknowledgeEvent', 'getProxies', 'getEventAlerts',
'getExtendedEventData'
'getExtendedEventData', 'getScripts', 'executeScript',
];
export class Zabbix implements ZabbixConnector {