Source
xxxxxxxxxx
const $macros = $('input[name^="macros"], textarea[name^="macros"]', this.$container).not(':disabled');
/*
** 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/>.
**/
/**
* JavaScript class to manage host macros.
*/
class HostMacrosManager {
static ZBX_PROPERTY_OWN = 0x02;
static ZBX_MACRO_TYPE_TEXT = 0;
static ZBX_MACRO_TYPE_SECRET = 1;
static ZBX_MACRO_TYPE_VAULT = 2;
static ZBX_STYLE_TEXTAREA_FLEXIBLE = 'textarea-flexible';
static DISCOVERY_STATE_AUTOMATIC = 0x1;
static DISCOVERY_STATE_CONVERTING = 0x2;
static DISCOVERY_STATE_MANUAL = 0x3;
constructor({container, readonly, parent_hostid}) {
this.$container = container;
this.readonly = readonly;
this.parent_hostid = parent_hostid ?? null;
}
load(show_inherited_macros, templateids) {
const url = new Curl('zabbix.php');
url.setArgument('action', 'hostmacros.list');
const post_data = {
macros: this.getMacros(),
show_inherited_macros: show_inherited_macros ? 1 : 0,
templateids: templateids,
readonly: this.readonly ? 1 : 0
};
if (this.parent_hostid !== null) {
post_data.parent_hostid = this.parent_hostid;
}
$.ajax(url.getUrl(), {
data: post_data,
dataType: 'json',
method: 'POST',
beforeSend: () => {
this.loaderStart();
}
})
.done((response) => {
if (typeof response === 'object' && 'error' in response) {
const message_box = makeMessageBox('bad', response.error.messages, response.error.title);
this.$container.append(message_box);
}
else {
if (typeof response.messages !== 'undefined') {
this.$container.append(response.messages);
}
this.$container.append(response.body);
// Initialize macros.
if (this.readonly) {
$('.' + HostMacrosManager.ZBX_STYLE_TEXTAREA_FLEXIBLE, this.getMacroTable()).textareaFlexible();
}
else {
this.initMacroTable(show_inherited_macros);
}
// Display debug after loaded content if it is enabled for user.
if (typeof response.debug !== 'undefined') {
this.$container.append(response.debug);
// Override margin for inline usage.
$('.debug-output', this.$container).css('margin', '10px 0');
}
}
})
.always(() => {
this.loaderStop();
});
}