Source
xxxxxxxxxx
* @param {int} step_obj_nr Value defines which 'test' button was pressed to open test item dialog:
<?php
/*
** 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/>.
**/
?>
<script type="text/javascript">
/**
* Collect current preprocessing step properties.
*
* @param {array} step_nums List of step numbers to collect.
*
* @return array
*/
function getPreprocessingSteps(step_nums) {
var $preprocessing = jQuery('#preprocessing'),
steps = [];
step_nums.forEach(function(num) {
var type = jQuery('[name="preprocessing[' + num + '][type]"]', $preprocessing).val(),
error_handler = jQuery('[name="preprocessing[' + num + '][on_fail]"]').is(':checked')
? jQuery('[name="preprocessing[' + num + '][error_handler]"]:checked').val()
: <?= ZBX_PREPROC_FAIL_DEFAULT ?>,
params = [];
var on_fail = {
error_handler: error_handler,
error_handler_params: (error_handler == <?= ZBX_PREPROC_FAIL_SET_VALUE ?>
|| error_handler == <?= ZBX_PREPROC_FAIL_SET_ERROR ?>)
? jQuery('[name="preprocessing[' + num + '][error_handler_params]"]').val()
: ''
};
if (type == <?= ZBX_PREPROC_SNMP_WALK_TO_JSON ?>) {
const inputs = document.querySelectorAll(`.group-json-mapping[data-index="${num}"] input`);
[...inputs].map((input) => params.push(input.value));
} else {
if (jQuery('[name="preprocessing[' + num + '][params][0]"]', $preprocessing).length) {
params.push(jQuery('[name="preprocessing[' + num + '][params][0]"]', $preprocessing).val());
}
if (jQuery('[name="preprocessing[' + num + '][params][1]"]', $preprocessing).length) {
params.push(jQuery('[name="preprocessing[' + num + '][params][1]"]', $preprocessing).val());
}
if (jQuery('[name="preprocessing[' + num + '][params][2]"]:not(:disabled)', $preprocessing).length) {
if (type == <?= ZBX_PREPROC_CSV_TO_JSON ?>) {
if (jQuery('[name="preprocessing[' + num + '][params][2]"]', $preprocessing).is(':checked')) {
params.push(jQuery('[name="preprocessing[' + num + '][params][2]"]', $preprocessing).val());
}
}
else {
params.push(jQuery('[name="preprocessing[' + num + '][params][2]"]', $preprocessing).val());
}
}
}
steps.push(jQuery.extend({
type: type,
params: params
}, on_fail));
});
return steps;
}
/**
* Collect item properties based on it's type.
*
* @param {string} form_selector Form selector.
*
* @return object
*/
function getItemTestProperties(form_selector) {
var $form = jQuery(form_selector),
form_data,
properties = {};
// Form must be enabled at moment when values are collected.
if (jQuery('#key').prop('readonly')) {
$form = $form.clone();