Source
'expected_error' => 'Invalid parameter "/output/1": value must be one of "scriptid", "name", "command", "host_access", "usrgrpid", "groupid", "description", "confirmation", "type", "execute_on", "timeout", "parameters", "scope", "port", "authtype", "username", "password", "publickey", "privatekey", "menu_path", "url", "new_window", "manualinput", "manualinput_prompt", "manualinput_validator_type", "manualinput_validator", "manualinput_default_value".'
<?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/>.
**/
require_once dirname(__FILE__).'/../include/CAPITest.php';
require_once dirname(__FILE__).'/../../include/triggers.inc.php';
require_once dirname(__FILE__).'/../../include/translateDefines.inc.php';
/**
* @backup ids
* @onBefore prepareScriptsData
* @onAfter clearData
*/
class testScripts extends CAPITest {
private static $data = [
'groupids' => [],
'hostids' => [],
'itemids' => [],
'triggerids' => [],
'eventids' => [],
'usermacroid' => null,
'usrgrpids' => [],
'roleids' => [],
'userids' => [],
'scriptids' => [],
'actionids' => [],
// Created scripts during script.create test (deleted at the end).
'created' => []
];
/**
* Prepare data for tests. Create host groups, hosts, items, triggers, events, user groups, roles, users,
* global macros, scripts and actions.
*/
public function prepareScriptsData(): void {
// Create host groups.
$hostgroups_data = [
'rw' => [
'name' => 'API test host group, read-write'
],
'r' => [
'name' => 'API test host group, read'
],
'd' => [
'name' => 'API test host group, deny'
],
// Parent group with read-write permissions, child group with read permissions etc.
'inherit_a_rw' => [
'name' => 'API test host group inherit, A, read-write'
],
'inherit_b_r' => [
'name' => 'API test host group inherit, A, read-write/API test host group inherit, B, read'
],
'inherit_c_rw' => [
'name' => 'API test host group inherit, A, read-write/API test host group inherit, B, read/API test host group inherit, C, read-write'
],
'inherit_d_rw' => [
'name' => 'API test host group inherit, A, read-write/API test host group inherit, B, read/API test host group inherit, C, read-write/API test host group inherit, D, read-write'
]
];
// Try to create host groups. In case of failure, print the exception message.
try {
$hostgroups = CDataHelper::call('hostgroup.create', array_values($hostgroups_data));
}
catch (Exception $e) {
$this->assertTrue(false, $e->getMessage());
}
self::$data['groupids'] = array_combine(array_keys($hostgroups_data), $hostgroups['groupids']);
// Create hosts.
$hosts_data = [
// Host with no macro, no interface and no inventory. User will have read-write permissions.
'plain_rw' => [
'host' => 'api_test_host_plain_rw',