Source
'ServerActive' => '127.0.0.1:'.self::getConfigurationValue(self::COMPONENT_SERVER, 'ListenPort'),
<?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/CIntegrationTest.php';
/**
* Test suite for autoregistration
*
* @required-components server, agent
* @configurationDataProvider agentConfigurationProvider
* @backup ids,hosts,items,actions,operations,optag,host_tag
* @backup auditlog,changelog,config,ha_node
*/
class testAutoregistration extends CIntegrationTest {
const HOST_METADATA1 = "autoreg 1";
const HOST_METADATA2 = "autoreg 2";
const AUTOREG_ACTION_NAME1 = 'Test autoregistration action 1';
const AUTOREG_ACTION_NAME2 = 'Test autoregistration action 2';
const ITEM_KEY = "item_key";
const LLD_KEY = "lld_key";
public static $HOST_METADATA = self::HOST_METADATA1;
public static $items = [
[
'name' => self::ITEM_KEY,
'key_' => self::ITEM_KEY,
'type' => ITEM_TYPE_TRAPPER,
'value_type' => ITEM_VALUE_TYPE_UINT64
]
];
public static $lldrules = [
[
'name' => self::LLD_KEY,
'key_' => self::LLD_KEY,
'type' => ITEM_TYPE_TRAPPER,
'lifetime_type' => 0,
'lifetime' => '1d',
'enabled_lifetime_type' => 0,
'enabled_lifetime' => '3h'
]
];
private function waitForAutoreg($expectedTags) {
$max_attempts = 5;
$sleep_time = 2;
for ($i = 0; $i < $max_attempts; $i++) {
try {
$response = $this->call('host.get', [
'selectTags' => ['tag', 'value']
]);
$this->assertArrayHasKey('result', $response,
'Failed to autoregister host before timeout');
$this->assertCount(1, $response['result'],
'Failed to autoregister host before timeout');
$this->assertArrayHasKey('tags', $response['result'][0],
'Failed to autoregister host before timeout');
$autoregHost = $response['result'][0];
$this->assertArrayHasKey('hostid', $autoregHost,
'Failed to get host ID of the autoregistered host');
$tags = $autoregHost['tags'];
$this->assertCount(count($expectedTags), $tags, 'Unexpected tags count was detected');
foreach ($expectedTags as $tag)
{
$this->assertContains($tag, $tags);
}
break;
} catch (Exception $e) {
if ($i == $max_attempts - 1)
throw $e;
else
sleep($sleep_time);