$this->assertArrayHasKey('actionid', $discoveryAction, 'Failed to get actionid of the discovery action');
require_once dirname(__FILE__).'/../include/CIntegrationTest.php';
class testDiscoveryRules extends CIntegrationTest {
const DRULE_NAME = 'Test discovery rule';
const DACTION_NAME = 'Test discovery action';
private static $discoveryRuleId;
private static $discoveryActionId;
private static $discoveredHostId;
private function waitForDiscovery($expectedTags, $notExpectedTags = []) {
for ($i = 0; $i < $max_attempts; $i++) {
$response = $this->call('host.get', [
'selectTags' => ['tag', 'value']
$this->assertArrayHasKey('result', $response, 'Failed to discover host before timeout');
$this->assertCount(1, $response['result'], 'Failed to discover host before timeout');
$this->assertArrayHasKey('tags', $response['result'][0], 'Failed to discover host before timeout');
$discoveredHost = $response['result'][0];
$this->assertArrayHasKey('hostid', $discoveredHost, 'Failed to get host ID of the discovered host');
self::$discoveredHostId = $discoveredHost['hostid'];
$tags = $discoveredHost['tags'];
$this->assertCount(count($expectedTags), $tags, 'Unexpected tags count was detected');
foreach($expectedTags as $expectedTag) {
$this->assertContains($expectedTag, $tags, 'Expected tag was not found after discovery');
foreach($notExpectedTags as $notExpectedTag) {