Source
<?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/>.
**/
/**
* Controller to perform 'get value from host' action in item test dialog.
*/
class CControllerPopupItemTestGetValue extends CControllerPopupItemTest {
protected function checkInput() {
$fields = [
'authtype' => 'in '.implode(',', [ZBX_HTTP_AUTH_NONE, ZBX_HTTP_AUTH_BASIC, ZBX_HTTP_AUTH_NTLM, ZBX_HTTP_AUTH_KERBEROS, ZBX_HTTP_AUTH_DIGEST, ITEM_AUTHTYPE_PASSWORD, ITEM_AUTHTYPE_PUBLICKEY]),
'headers' => 'array',
'hostid' => 'db hosts.hostid',
'test_with' => 'in '.implode(',', [self::TEST_WITH_SERVER, self::TEST_WITH_PROXY]),
'proxyid' => 'id',
'http_authtype' => 'in '.implode(',', [ZBX_HTTP_AUTH_NONE, ZBX_HTTP_AUTH_BASIC, ZBX_HTTP_AUTH_NTLM, ZBX_HTTP_AUTH_KERBEROS, ZBX_HTTP_AUTH_DIGEST, ITEM_AUTHTYPE_PASSWORD, ITEM_AUTHTYPE_PUBLICKEY]),
'http_password' => 'string',
'http_proxy' => 'string',
'http_username' => 'string',
'flags' => 'in '. implode(',', [ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_RULE, ZBX_FLAG_DISCOVERY_PROTOTYPE, ZBX_FLAG_DISCOVERY_CREATED]),
'follow_redirects' => 'in 0,1',
'key' => 'string',
'interface' => 'array',
'ipmi_sensor' => 'string',
'item_type' => 'required|int32',
'jmx_endpoint' => 'string',
'macros' => 'array',
'output_format' => 'in '.implode(',', [HTTPCHECK_STORE_RAW, HTTPCHECK_STORE_JSON]),
'params_ap' => 'string',
'params_es' => 'string',
'params_f' => 'string',
'script' => 'string',
'browser_script' => 'string',
'password' => 'string',
'post_type' => 'in '.implode(',', [ZBX_POSTTYPE_RAW, ZBX_POSTTYPE_JSON, ZBX_POSTTYPE_XML]),
'posts' => 'string',
'privatekey' => 'string',
'publickey' => 'string',
'query_fields' => 'array',
'parameters' => 'array',
'request_method' => 'in '.implode(',', [HTTPCHECK_REQUEST_GET, HTTPCHECK_REQUEST_POST, HTTPCHECK_REQUEST_PUT, HTTPCHECK_REQUEST_HEAD]),
'retrieve_mode' => 'in '.implode(',', [HTTPTEST_STEP_RETRIEVE_MODE_CONTENT, HTTPTEST_STEP_RETRIEVE_MODE_HEADERS, HTTPTEST_STEP_RETRIEVE_MODE_BOTH]),
'snmp_oid' => 'string',
'ssl_cert_file' => 'string',
'ssl_key_file' => 'string',
'ssl_key_password' => 'string',
'status_codes' => 'string',
'test_type' => 'required|in '.implode(',', [self::ZBX_TEST_TYPE_ITEM, self::ZBX_TEST_TYPE_ITEM_PROTOTYPE, self::ZBX_TEST_TYPE_LLD]),
'time_change' => 'int32',
'timeout' => 'string',
'username' => 'string',
'url' => 'string',
'value' => 'string',
'value_type' => 'in '.implode(',', [ITEM_VALUE_TYPE_UINT64, ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_TEXT]),
'verify_host' => 'in 0,1',
'verify_peer' => 'in 0,1'
];
$ret = $this->validateInput($fields);
if ($ret) {
$testable_item_types = self::getTestableItemTypes($this->getInput('hostid', '0'));
$this->item_type = $this->getInput('item_type');
$this->test_type = $this->getInput('test_type');
$this->is_item_testable = in_array($this->item_type, $testable_item_types);
if (!$this->is_item_testable) {
error(_s('Test of "%1$s" items is not supported.', item_type2str($this->item_type)));
$ret = false;
}
// Check if key is valid for item types it's mandatory.
if ($ret && in_array($this->item_type, $this->item_types_has_key_mandatory)) {
$key = $this->getInput('key', '');
/*
* VMware and icmpping simple checks are not supported.
* This normally cannot be achieved from UI so no need for error message.