'subfilter_tags' => [T_ZBX_STR, O_OPT, null, null, null],
'checkbox_hash' => [T_ZBX_STR, O_OPT, null, null, null],
'sort' => [T_ZBX_STR, O_OPT, P_SYS,
IN('"delay","history","key_","name","status","trends","type"'),
'sortorder' => [T_ZBX_STR, O_OPT, P_SYS, IN('"'.ZBX_SORT_DOWN.'","'.ZBX_SORT_UP.'"'), null]
if (getRequest('type') == ITEM_TYPE_HTTPAGENT && getRequest('interfaceid') == INTERFACE_TYPE_OPT) {
unset($fields['interfaceid']);
unset($_REQUEST['interfaceid']);
$valid_input = check_fields($fields);
$_REQUEST['params'] = getRequest($paramsFieldName, '');
unset($_REQUEST[$paramsFieldName]);
$subfiltersList = ['subfilter_types', 'subfilter_value_types', 'subfilter_status', 'subfilter_state',
'subfilter_inherited', 'subfilter_with_triggers', 'subfilter_hosts', 'subfilter_interval', 'subfilter_history',
'subfilter_trends', 'subfilter_discovered'
$delay .= ';'.implode(';', $intervals);
$preprocessing = getRequest('preprocessing', []);
$preprocessing = normalizeItemPreprocessingSteps($preprocessing);
if ($type == ITEM_TYPE_HTTPAGENT) {
'timeout' => getRequest('timeout', DB::getDefault('items', 'timeout')),
'url' => getRequest('url'),
'query_fields' => getRequest('query_fields', []),
'posts' => getRequest('posts'),
'status_codes' => getRequest('status_codes', DB::getDefault('items', 'status_codes')),
'follow_redirects' => (int) getRequest('follow_redirects'),
'post_type' => (int) getRequest('post_type'),
'http_proxy' => getRequest('http_proxy'),
'headers' => getRequest('headers', []),
'retrieve_mode' => (int) getRequest('retrieve_mode'),
'request_method' => (int) getRequest('request_method'),
'output_format' => (int) getRequest('output_format'),
'allow_traps' => (int) getRequest('allow_traps', HTTPCHECK_ALLOW_TRAPS_OFF),
'ssl_cert_file' => getRequest('ssl_cert_file'),
'ssl_key_file' => getRequest('ssl_key_file'),
'ssl_key_password' => getRequest('ssl_key_password'),
'verify_peer' => (int) getRequest('verify_peer'),
'verify_host' => (int) getRequest('verify_host'),
'authtype' => getRequest('http_authtype', HTTPTEST_AUTH_NONE),
'username' => getRequest('http_username', ''),
'password' => getRequest('http_password', '')
'hostid' => getRequest('hostid'),
'name' => getRequest('name', ''),
'type' => getRequest('type', ITEM_TYPE_ZABBIX),
'key_' => getRequest('key', ''),
'interfaceid' => getRequest('interfaceid', 0),
'snmp_oid' => getRequest('snmp_oid', ''),
'authtype' => getRequest('authtype', ITEM_AUTHTYPE_PASSWORD),
'username' => getRequest('username', ''),
'valuemapid' => getRequest('valuemapid', 0),
'logtimefmt' => getRequest('logtimefmt', ''),
'trapper_hosts' => getRequest('trapper_hosts', ''),
'inventory_link' => getRequest('inventory_link', 0),
'description' => getRequest('description', ''),
'status' => getRequest('status', ITEM_STATUS_DISABLED),
if ($item['type'] == ITEM_TYPE_HTTPAGENT) {
'timeout' => getRequest('timeout', DB::getDefault('items', 'timeout')),
'url' => getRequest('url'),
'query_fields' => getRequest('query_fields', []),
'posts' => getRequest('posts'),
'status_codes' => getRequest('status_codes', DB::getDefault('items', 'status_codes')),
'follow_redirects' => (int) getRequest('follow_redirects'),
'post_type' => (int) getRequest('post_type'),
'http_proxy' => getRequest('http_proxy'),
'headers' => getRequest('headers', []),
'retrieve_mode' => (int) getRequest('retrieve_mode'),
'request_method' => (int) getRequest('request_method'),
'output_format' => (int) getRequest('output_format'),
'allow_traps' => (int) getRequest('allow_traps', HTTPCHECK_ALLOW_TRAPS_OFF),
'ssl_cert_file' => getRequest('ssl_cert_file'),
'ssl_key_file' => getRequest('ssl_key_file'),
'ssl_key_password' => getRequest('ssl_key_password'),
'verify_peer' => (int) getRequest('verify_peer'),
'verify_host' => (int) getRequest('verify_host'),
'authtype' => getRequest('http_authtype', HTTPTEST_AUTH_NONE),
'username' => getRequest('http_username', ''),
'password' => getRequest('http_password', '')
$item = prepareItemHttpAgentFormData($http_item) + $item;
if ($item['type'] == ITEM_TYPE_JMX) {
$item['jmx_endpoint'] = getRequest('jmx_endpoint', '');
$item['preprocessing'] = $preprocessing;
$item = prepareScriptItemFormData($script_item) + $item;
if ($item['value_type'] == ITEM_VALUE_TYPE_LOG || $item['value_type'] == ITEM_VALUE_TYPE_TEXT) {
unset($item['valuemapid']);
$result = (bool) API::Item()->create($item);
$db_items = API::Item()->get([
'output' => ['name', 'type', 'key_', 'interfaceid', 'snmp_oid', 'authtype', 'username', 'password',
'publickey', 'privatekey', 'params', 'ipmi_sensor', 'value_type', 'units', 'delay', 'history',
'trends', 'valuemapid', 'logtimefmt', 'trapper_hosts', 'inventory_link', 'description', 'status',
'templateid', 'flags', 'jmx_endpoint', 'master_itemid', 'timeout', 'url', 'query_fields', 'posts',
'status_codes', 'follow_redirects', 'post_type', 'http_proxy', 'headers', 'retrieve_mode',
'request_method', 'output_format', 'ssl_cert_file', 'ssl_key_file', 'ssl_key_password',
'verify_peer', 'verify_host', 'allow_traps', 'parameters'
if ($db_item['units'] !== getRequest('units', '')) {
$item['units'] = getRequest('units', '');
if ($value_type != ITEM_VALUE_TYPE_LOG && $value_type != ITEM_VALUE_TYPE_TEXT
&& bccomp($db_item['valuemapid'], getRequest('valuemapid', 0)) != 0) {
$item['valuemapid'] = getRequest('valuemapid', 0);
if ($db_item['logtimefmt'] !== getRequest('logtimefmt', '')) {
$item['logtimefmt'] = getRequest('logtimefmt', '');
if (bccomp($db_item['interfaceid'], getRequest('interfaceid', 0)) != 0) {
$item['interfaceid'] = getRequest('interfaceid', 0);
if ($db_item['authtype'] != getRequest('authtype', ITEM_AUTHTYPE_PASSWORD)) {
$item['authtype'] = getRequest('authtype', ITEM_AUTHTYPE_PASSWORD);
if ($db_item['username'] !== getRequest('username', '')) {
$item['username'] = getRequest('username', '');
if ($db_item['password'] !== getRequest('password', '')) {
$item['password'] = getRequest('password', '');
if ($db_item['publickey'] !== getRequest('publickey', '')) {
$item['publickey'] = getRequest('publickey', '');
if ($db_item['privatekey'] !== getRequest('privatekey', '')) {
$item['privatekey'] = getRequest('privatekey', '');
if ($db_item['params'] !== getRequest('params', '')) {
$item['params'] = getRequest('params', '');
if ($db_item['preprocessing'] !== $preprocessing) {
$item['preprocessing'] = $preprocessing;
if (bccomp($db_item['interfaceid'], getRequest('interfaceid', 0)) != 0) {
$item['interfaceid'] = getRequest('interfaceid', 0);
if ($db_item['authtype'] != getRequest('authtype', ITEM_AUTHTYPE_PASSWORD)) {
$item['authtype'] = getRequest('authtype', ITEM_AUTHTYPE_PASSWORD);
if ($db_item['username'] !== getRequest('username', '')) {
$item['username'] = getRequest('username', '');
if ($db_item['password'] !== getRequest('password', '')) {
$item['password'] = getRequest('password', '');
if ($db_item['publickey'] !== getRequest('publickey', '')) {
$item['publickey'] = getRequest('publickey', '');
if ($db_item['privatekey'] !== getRequest('privatekey', '')) {
$item['privatekey'] = getRequest('privatekey', '');
if ($db_item['params'] !== getRequest('params', '')) {
$item['params'] = getRequest('params', '');
if ($db_item['delay'] != $delay) {
$def_item_history = (getRequest('history_mode', ITEM_STORAGE_CUSTOM) == ITEM_STORAGE_OFF)
: DB::getDefault('items', 'history');
if ((string) $db_item['history'] !== (string) getRequest('history', $def_item_history)) {
$item['history'] = getRequest('history', $def_item_history);
$def_item_trends = (getRequest('trends_mode', ITEM_STORAGE_CUSTOM) == ITEM_STORAGE_OFF)
if ($db_item['jmx_endpoint'] !== getRequest('jmx_endpoint', '')) {
$item['jmx_endpoint'] = getRequest('jmx_endpoint', '');
if ($db_item['inventory_link'] != getRequest('inventory_link', 0)) {
$item['inventory_link'] = getRequest('inventory_link', 0);
if ($db_item['description'] !== getRequest('description', '')) {
$item['description'] = getRequest('description', '');
if ($db_item['preprocessing'] !== $preprocessing) {
$item['preprocessing'] = $preprocessing;
if (getRequest('type') == ITEM_TYPE_HTTPAGENT) {
'timeout' => getRequest('timeout', DB::getDefault('items', 'timeout')),
'url' => getRequest('url'),
'query_fields' => getRequest('query_fields', []),
'posts' => getRequest('posts'),
'status_codes' => getRequest('status_codes', DB::getDefault('items', 'status_codes')),
'follow_redirects' => (int) getRequest('follow_redirects'),
'post_type' => (int) getRequest('post_type'),
'http_proxy' => getRequest('http_proxy'),
'headers' => getRequest('headers', []),
'retrieve_mode' => (int) getRequest('retrieve_mode'),
'request_method' => (int) getRequest('request_method'),
'output_format' => (int) getRequest('output_format'),
'allow_traps' => (int) getRequest('allow_traps', HTTPCHECK_ALLOW_TRAPS_OFF),
'ssl_cert_file' => getRequest('ssl_cert_file'),
'ssl_key_file' => getRequest('ssl_key_file'),
'ssl_key_password' => getRequest('ssl_key_password'),
'verify_peer' => (int) getRequest('verify_peer'),
'verify_host' => (int) getRequest('verify_host'),
'authtype' => getRequest('http_authtype', HTTPTEST_AUTH_NONE),
'username' => getRequest('http_username', ''),
'password' => getRequest('http_password', '')
if ($db_item['templateid'] == 0 && $type == ITEM_TYPE_HTTPAGENT) {
$item = prepareItemHttpAgentFormData($http_item) + $item;
if ($db_item['status'] != getRequest('status', ITEM_STATUS_DISABLED)) {
$item['status'] = getRequest('status', ITEM_STATUS_DISABLED);
if (getRequest('type') == ITEM_TYPE_DEPENDENT && hasRequest('master_itemid')
&& bccomp($db_item['master_itemid'], getRequest('master_itemid')) != 0) {
if ($db_item['params'] !== getRequest('params', '')) {
$item['params'] = getRequest('params', '');
CArrayHelper::sort($db_item['tags'], ['tag', 'value']);
CArrayHelper::sort($tags, ['tag', 'value']);
if (array_values($db_item['tags']) !== array_values($tags)) {
$item['itemid'] = getRequest('itemid');
$result = (bool) API::Item()->update($item);