<?php
require_once dirname(__FILE__).'/../include/CIntegrationTest.php';
class testEscalations extends CIntegrationTest {
private static $hostid;
private static $triggerid;
private static $maint_start_tm;
private static $trigger_actionid;
private static $scriptid_problem;
private static $scriptid_recovery;
const TRAPPER_ITEM_NAME = 'trap';
const HOST_NAME = 'test_actions';
const COMMAND_PROBLEM = 'echo "problem"';
const COMMAND_RECOVERY = 'echo "recovery"';
public function prepareData() {
$response = $this->call('host.create', [
'host' => self::HOST_NAME,
'interfaces' => [
'type' => 1,
'main' => 1,
'useip' => 1,
'ip' => '127.0.0.1',
'dns' => '',
'port' => $this->getConfigurationValue(self::COMPONENT_AGENT, 'ListenPort')
],
'groups' => ['groupid' => 4]
]);
$this->assertArrayHasKey('hostids', $response['result']);
$this->assertArrayHasKey(0, $response['result']['hostids']);
self::$hostid = $response['result']['hostids'][0];
$response = $this->call('host.get', [
'output' => ['host'],
'hostids' => [self::$hostid],
'selectInterfaces' => ['interfaceid']
]);
$this->assertArrayHasKey(0, $response['result']);
$this->assertArrayHasKey('interfaces', $response['result'][0]);
$this->assertArrayHasKey(0, $response['result'][0]['interfaces']);
$response = $this->call('item.create', [
'hostid' => self::$hostid,
'name' => self::TRAPPER_ITEM_NAME,
'key_' => self::TRAPPER_ITEM_NAME,
'type' => ITEM_TYPE_TRAPPER,
'value_type' => ITEM_VALUE_TYPE_UINT64
]);
$this->assertArrayHasKey('itemids', $response['result']);
$this->assertEquals(1, count($response['result']['itemids']));
$response = $this->call('trigger.create', [
'description' => 'Trapper received 1',
'expression' => 'last(/'.self::HOST_NAME.'/'.self::TRAPPER_ITEM_NAME.')>0'
]);
$this->assertArrayHasKey('triggerids', $response['result']);
$this->assertEquals(1, count($response['result']['triggerids']));
self::$triggerid = $response['result']['triggerids'][0];