diff --git a/.changeset/silent-shrimps-carry.md b/.changeset/silent-shrimps-carry.md new file mode 100644 index 0000000..8624a6b --- /dev/null +++ b/.changeset/silent-shrimps-carry.md @@ -0,0 +1,5 @@ +--- +'grafana-zabbix': minor +--- + +Add possibility to run "Manual event actions" diff --git a/src/datasource/zabbix/connectors/zabbix_api/types.ts b/src/datasource/zabbix/connectors/zabbix_api/types.ts index f94ebbc..6e14303 100644 --- a/src/datasource/zabbix/connectors/zabbix_api/types.ts +++ b/src/datasource/zabbix/connectors/zabbix_api/types.ts @@ -44,6 +44,7 @@ export interface ZBXScript { confirmation?: string; type?: string; execute_on?: string; + scope?: string; } export interface APIExecuteScriptResponse { diff --git a/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts index 0fd5c0f..a71d3ca 100644 --- a/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts +++ b/src/datasource/zabbix/connectors/zabbix_api/zabbixAPIConnector.ts @@ -930,11 +930,14 @@ export class ZabbixAPIConnector { return this.request('script.get', params).then(utils.mustArray); } - executeScript(hostid: string, scriptid: string): Promise { - const params: any = { - hostid, - scriptid, - }; + executeScript(scriptid: string, hostid?: string, eventid?: string): Promise { + const params: { scriptid: string; hostid?: string; eventid?: string } = { scriptid }; + if (hostid) { + params.hostid = hostid; + } + if (eventid) { + params.eventid = eventid; + } return this.request('script.execute', params); } diff --git a/src/panel-triggers/ProblemsPanel.tsx b/src/panel-triggers/ProblemsPanel.tsx index 60a435c..6704c79 100644 --- a/src/panel-triggers/ProblemsPanel.tsx +++ b/src/panel-triggers/ProblemsPanel.tsx @@ -190,10 +190,22 @@ export const ProblemsPanel = (props: ProblemsPanelProps): JSX.Element => { return ds.zabbix.getScripts([hostid]); }; - const onExecuteScript = async (problem: ProblemDTO, scriptid: string): Promise => { + const onExecuteScript = async ( + problem: ProblemDTO, + scriptid: string, + scope: string + ): Promise => { const hostid = problem.hosts?.length ? problem.hosts[0].hostid : null; const ds: any = await getDataSourceSrv().get(problem.datasource); - return ds.zabbix.executeScript(hostid, scriptid); + + switch (scope) { + case '4': // Event action + return ds.zabbix.executeScript(scriptid, undefined, problem.eventid); + case '2': // Host action + return ds.zabbix.executeScript(scriptid, hostid, undefined); + default: + return ds.zabbix.executeScript(scriptid); + } }; const onProblemAck = async (problem: ProblemDTO, data: AckProblemData) => { diff --git a/src/panel-triggers/components/ExecScriptModal.tsx b/src/panel-triggers/components/ExecScriptModal.tsx index fdaf955..cf09956 100644 --- a/src/panel-triggers/components/ExecScriptModal.tsx +++ b/src/panel-triggers/components/ExecScriptModal.tsx @@ -24,6 +24,7 @@ interface State { export interface ExecScriptData { scriptid: string; + scope: string; } export class ExecScriptModalUnthemed extends PureComponent { @@ -83,6 +84,7 @@ export class ExecScriptModalUnthemed extends PureComponent { const data: ExecScriptData = { scriptid: selectedScript.value, + scope: this.state.script.scope, }; this.props diff --git a/src/panel-triggers/components/Problems/ProblemDetails.tsx b/src/panel-triggers/components/Problems/ProblemDetails.tsx index adcb000..20daf9f 100644 --- a/src/panel-triggers/components/Problems/ProblemDetails.tsx +++ b/src/panel-triggers/components/Problems/ProblemDetails.tsx @@ -29,7 +29,7 @@ interface Props extends RTRow { getProblemEvents: (problem: ProblemDTO) => Promise; getProblemAlerts: (problem: ProblemDTO) => Promise; getScripts: (problem: ProblemDTO) => Promise; - onExecuteScript(problem: ProblemDTO, scriptid: string): Promise; + onExecuteScript(problem: ProblemDTO, scriptid: string, scope: string): Promise; onProblemAck?: (problem: ProblemDTO, data: AckProblemData) => Promise | any; onTagClick?: (tag: ZBXTag, datasource: DataSourceRef | string, ctrlKey?: boolean, shiftKey?: boolean) => void; } @@ -90,9 +90,9 @@ export const ProblemDetails = ({ return getScripts(problem); }; - const onExecuteScriptInternal = (data: ExecScriptData) => { + const onExecuteScriptInternal = ({ scriptid, scope }: ExecScriptData) => { const problem = original as ProblemDTO; - return onExecuteScript(problem, data.scriptid); + return onExecuteScript(problem, scriptid, scope); }; const problem = original as ProblemDTO; diff --git a/src/panel-triggers/components/Problems/Problems.tsx b/src/panel-triggers/components/Problems/Problems.tsx index eff1c88..bf7f227 100644 --- a/src/panel-triggers/components/Problems/Problems.tsx +++ b/src/panel-triggers/components/Problems/Problems.tsx @@ -28,7 +28,7 @@ export interface ProblemListProps { getProblemEvents: (problem: ProblemDTO) => Promise; getProblemAlerts: (problem: ProblemDTO) => Promise; getScripts: (problem: ProblemDTO) => Promise; - onExecuteScript: (problem: ProblemDTO, scriptid: string) => Promise; + onExecuteScript: (problem: ProblemDTO, scriptid: string, scope: string) => Promise; onProblemAck?: (problem: ProblemDTO, data: AckProblemData) => void; onTagClick?: (tag: ZBXTag, datasource: DataSourceRef, ctrlKey?: boolean, shiftKey?: boolean) => void; onPageSizeChange?: (pageSize: number, pageIndex: number) => void;