Source
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
class Script {
/**
* Executes script, handling optional manual input and confirmation.
*
* @param {string|null} scriptid Script ID.
* @param {string} confirmation Confirmation text.
* @param {Node} trigger_element UI element that was clicked to open overlay dialogue.
* @param {string|null} hostid Host ID.
* @param {string|null} eventid Event ID.
* @param {string|null} csrf_token CSRF token.
* @param {string|null} manualinput Manual input enabled/disabled or null.
* @param {string|null} manualinput_prompt Manual input prompt text.
* @param {int|null} manualinput_validator_type Manual input type - 0 (string) or 1 (dropdown).
* @param {string|null} manualinput_validator Validation rule - regular expression or list of allowed values.
* @param {string|null} manualinput_default_value Default value of manual input.
*/
static execute(scriptid, confirmation, trigger_element, hostid = null, eventid = null, csrf_token = null,
manualinput = null, manualinput_prompt = null, manualinput_validator_type = null,
manualinput_validator = null, manualinput_default_value = null) {
if (manualinput == ZBX_SCRIPT_MANUALINPUT_ENABLED) {
const overlay = Script.#getManualInput(scriptid, confirmation, trigger_element, hostid, eventid,
manualinput, manualinput_prompt, manualinput_validator_type, manualinput_validator,
manualinput_default_value
);
overlay.$dialogue[0].addEventListener('manualinput.ready', (e) => {
if (confirmation !== '') {
Script.#confirm({
dialogue_title: t('Execution confirmation'),
confirmation: e.detail.confirmation,
confirm_button_title: t('Execute'),
confirm_button_enabled: hostid !== null || eventid !== null,
trigger_element
})
.then(() => {
overlayDialogueDestroy(overlay.dialogueid);
Script.#execute(scriptid, eventid, hostid, e.detail.manualinput_value, csrf_token,
trigger_element
);
})
.catch(() => {
overlay.unsetLoading();
overlay.recoverFocus();
overlay.containFocus();
});
}