Welcome to mirror list, hosted at ThFree Co, Russian Federation.

CIntegrationTest.php « include « tests « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c12a29e12630b3d20d6c58237ed2085deb093343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** 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 General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/

require_once 'vendor/autoload.php';

require_once dirname(__FILE__).'/CAPITest.php';
require_once dirname(__FILE__).'/CZabbixClient.php';
require_once dirname(__FILE__).'/helpers/CLogHelper.php';

/**
 * Base class for integration tests.
 */
class CIntegrationTest extends CAPITest {

	// Default iteration count for wait operations.
	const WAIT_ITERATIONS			= 60;

	// Default delays (in seconds):
	const WAIT_ITERATION_DELAY		= 1; // Wait iteration delay.
	const COMPONENT_STARTUP_DELAY	= 10; // Component start delay.
	const CACHE_RELOAD_DELAY		= 5; // Configuration cache reload delay.
	const DATA_PROCESSING_DELAY		= 5; // Data processing delay.

	// Zabbix component constants.
	const COMPONENT_SERVER	= 'server';
	const COMPONENT_PROXY	= 'proxy';
	const COMPONENT_AGENT	= 'agentd';
	const COMPONENT_AGENT2	= 'agent2';

	// Zabbix component port constants.
	const AGENT_PORT_SUFFIX = '50';
	const SERVER_PORT_SUFFIX = '51';
	const PROXY_PORT_SUFFIX = '52';

	/**
	 * Components required by test suite.
	 *
	 * @var array
	 */
	private static $suite_components = [];

	/**
	 * Hosts to be enabled for test suite.
	 *
	 * @var array
	 */
	private static $suite_hosts = [];

	/**
	 * Configuration provider for test suite.
	 *
	 * @var array
	 */
	private static $suite_configuration = [];

	/**
	 * Components required by test case.
	 *
	 * @var array
	 */
	private $case_components = [];

	/**
	 * Hosts to be enabled for test case.
	 *
	 * @var array
	 */
	private $case_hosts = [];

	/**
	 * Configuration provider for test case.
	 *
	 * @var array
	 */
	private static $case_configuration = [];

	/**
	 * Process annotations defined on suite / case level.
	 *
	 * @param string $type    annotation type ('class' or 'method')
	 *
	 * @throws Exception    on invalid configuration provider
	 */
	protected function processAnnotations($type) {
		$annotations = $this->getAnnotationsByType($this->annotations, $type);
		$result = [
			'components'	=> [],
			'hosts'			=> [],
			'configuration'	=> []
		];

		// Get required components.
		foreach ($this->getAnnotationTokensByName($annotations, 'required-components') as $component) {
			if ($component === 'agent') {
				$component = self::COMPONENT_AGENT;
			}

			self::validateComponent($component);
			$result['components'][$component] = true;
		}

		$result['components'] = array_keys($result['components']);

		// Get hosts to enable.
		foreach ($this->getAnnotationTokensByName($annotations, 'hosts') as $host) {
			$result['hosts'][$host] = true;
		}

		$result['hosts'] = array_keys($result['hosts']);

		// Get configuration from configuration data provider.
		foreach ($this->getAnnotationTokensByName($annotations, 'configurationDataProvider') as $provider) {
			if (!method_exists($this, $provider) || !is_array($config = call_user_func([$this, $provider]))) {
				throw new Exception('Configuration data provider "'.$provider.'" is not valid.');
			}

			$result['configuration'] = array_merge($result['configuration'], $config);
		}

		return $result;
	}

	/**
	 * Set status for hosts.
	 *
	 * @param array   $hosts     array of hostids or host names
	 * @param integer $status    status to be set
	 */
	protected static function setHostStatus($hosts, $status) {
		if (is_scalar($hosts)) {
			$hosts = [$hosts];
		}

		if ($hosts && is_array($hosts)) {
			$filters = [];
			$criteria = [];

			foreach ($hosts as $host) {
				$filters[(is_numeric($host) ? 'hostid' : 'host')][] = zbx_dbstr($host);
			}

			foreach ($filters as $key => $values) {
				$criteria[] = $key.' in ('.implode(',', $values).')';
			}

			DBexecute('UPDATE hosts SET status='.zbx_dbstr($status).' WHERE '.implode(' OR ', $criteria));
		}
	}

	/**
	 * @inheritdoc
	 */
	protected function onBeforeTestSuite() {
		parent::onBeforeTestSuite();

		$result = $this->processAnnotations('class');
		self::$suite_components = $result['components'];
		self::$suite_hosts = $result['hosts'];
		self::$suite_configuration = self::getDefaultComponentConfiguration();

		foreach (self::getComponents() as $component) {
			if (!array_key_exists($component, $result['configuration'])) {
				continue;
			}

			self::$suite_configuration[$component] = array_merge(self::$suite_configuration[$component],
					$result['configuration'][$component]
			);
		}

		try {
			if ($this->prepareData() === false) {
				throw new Exception('Failed to prepare data for test suite.');
			}
		} catch (Exception $exception) {
			self::markTestSuiteSkipped();
			throw $exception;
		}

		self::setHostStatus(self::$suite_hosts, HOST_STATUS_MONITORED);

		foreach (self::$suite_components as $component) {
			self::prepareComponentConfiguration($component, self::$suite_configuration);
			self::startComponent($component);
		}
	}

	/**
	 * Prepare data for test suite.
	 */
	public function prepareData() {
		// Code is not missing here.

		return true;
	}

	/**
	 * Callback executed before every test case.
	 *
	 * @before
	 */
	public function onBeforeTestCase() {
		parent::onBeforeTestCase();

		$result = $this->processAnnotations('method');
		$this->case_components = array_diff($result['components'], self::$suite_components);
		$this->case_hosts = array_diff($result['hosts'], self::$suite_hosts);
		self::$case_configuration = self::$suite_configuration;

		foreach (self::getComponents() as $component) {
			if (!array_key_exists($component, $result['configuration'])) {
				continue;
			}

			self::$case_configuration[$component] = array_merge(self::$case_configuration[$component],
					$result['configuration'][$component]
			);
		}

		self::setHostStatus($this->case_hosts, HOST_STATUS_MONITORED);

		foreach (self::$suite_components as $component) {
			if (self::$case_configuration[$component] === self::$suite_configuration[$component]) {
				continue;
			}

			self::prepareComponentConfiguration($component, self::$case_configuration);
			self::restartComponent($component);
		}

		foreach ($this->case_components as $component) {
			self::prepareComponentConfiguration($component, self::$case_configuration);
			self::startComponent($component);
		}
	}

	/**
	 * Callback executed after every test case.
	 *
	 * @after
	 */
	public function onAfterTestCase() {
		foreach ($this->case_components as $component) {
			try {
				self::stopComponent($component);
			}
			catch (Exception $e) {
				self::addWarning($e->getMessage());
			}
		}

		foreach (self::$suite_components as $component) {
			if (array_key_exists($component, self::$case_configuration)
					&& self::$case_configuration[$component] === self::$suite_configuration[$component]) {
				continue;
			}

			self::prepareComponentConfiguration($component, self::$suite_configuration);
			self::restartComponent($component);
		}

		self::setHostStatus($this->case_hosts, HOST_STATUS_NOT_MONITORED);
		self::$case_configuration = [];

		parent::onAfterTestCase();
	}

	/**
	 * Callback executed after every test suite.
	 *
	 * @afterClass
	 */
	public static function onAfterTestSuite() {
		foreach (self::$suite_components as $component) {
			try {
				self::stopComponent($component);
			}
			catch (Exception $e) {
				self::addWarning($e->getMessage());
			}
		}

		if (self::$suite_hosts) {
			global $DB;
			DBconnect($error);
			self::setHostStatus(self::$suite_hosts, HOST_STATUS_NOT_MONITORED);
			DBclose();
		}

		parent::onAfterTestSuite();
	}

	/**
	 * Get list of possible component names.
	 *
	 * @return array
	 */
	private static function getComponents() {
		return [
			self::COMPONENT_SERVER, self::COMPONENT_PROXY, self::COMPONENT_AGENT, self::COMPONENT_AGENT2
		];
	}

	/**
	 * Validate component name.
	 *
	 * @param string $component    component name to be validated.
	 *
	 * @throws Exception    on invalid component name
	 */
	private static function validateComponent($component) {
		if (!in_array($component, self::getComponents())) {
			throw new Exception('Unknown component name "'.$component.'".');
		}
	}

	/**
	 * Wait for component to start.
	 *
	 * @param string $component    component name
	 *
	 * @throws Exception    on failed wait operation
	 */
	protected static function waitForStartup($component) {
		self::validateComponent($component);

		for ($r = 0; $r < self::WAIT_ITERATIONS; $r++) {
			$pid = @file_get_contents(self::getPidPath($component));
			if ($pid && is_numeric($pid) && posix_kill($pid, 0)) {
				sleep(self::COMPONENT_STARTUP_DELAY);

				return;
			}

			sleep(self::WAIT_ITERATION_DELAY);
		}

		throw new Exception('Failed to wait for component "'.$component.'" to start.');
	}

	/**
	 * Wait for component to stop.
	 *
	 * @param string $component    component name
	 *
	 * @throws Exception    on failed wait operation
	 */
	protected static function waitForShutdown($component) {
		self::validateComponent($component);

		for ($r = 0; $r < self::WAIT_ITERATIONS; $r++) {
			if (!file_exists(self::getPidPath($component))) {
				return;
			}

			sleep(self::WAIT_ITERATION_DELAY);
		}

		throw new Exception('Failed to wait for component "'.$component.'" to stop.');
	}

	/**
	 * Execute command and the execution result.
	 *
	 * @param string $command   command to be executed
	 * @param array  $params    parameters to be passed
	 * @param string $suffix    command suffix
	 *
	 * @return string
	 *
	 * @throws Exception    on execution error
	 */
	private static function executeCommand($command, $params = [], $suffix = '') {
		$return = null;
		$output = null;

		if ($params) {
			foreach ($params as &$param) {
				$param = escapeshellarg($param);
			}
			unset($param);

			$params = ' '.implode(' ', $params);
		}
		else {
			$params = null;
		}

		exec($command.$params.$suffix, $output, $return);

		if ($return !== 0) {
			throw new Exception('Failed to execute command "'.$command.$params.$suffix.'".');
		}

		return $output;
	}

	/**
	 * Get default configuration of components.
	 *
	 * @return array
	 */
	protected static function getDefaultComponentConfiguration() {
		global $DB;

		$db = [
			'DBName' => $DB['DATABASE'],
			'DBUser' => $DB['USER'],
			'DBPassword' => $DB['PASSWORD']
		];

		if ($DB['SERVER'] !== 'localhost' && $DB['SERVER'] !== '127.0.0.1') {
			$db['DBHost'] = $DB['SERVER'];
		}

		if ($DB['PORT'] != 0) {
			$db['DBPort'] = $DB['PORT'];
		}

		if ($DB['SCHEMA']) {
			$db['DBSchema'] = $DB['SCHEMA'];
		}

		$configuration = [
			self::COMPONENT_SERVER => array_merge($db, [
				'LogFile' => PHPUNIT_COMPONENT_DIR.'zabbix_server.log',
				'PidFile' => PHPUNIT_COMPONENT_DIR.'zabbix_server.pid',
				'SocketDir' => PHPUNIT_COMPONENT_DIR,
				'ListenPort' => PHPUNIT_PORT_PREFIX.self::SERVER_PORT_SUFFIX
			]),
			self::COMPONENT_PROXY => array_merge($db, [
				'LogFile' => PHPUNIT_COMPONENT_DIR.'zabbix_proxy.log',
				'PidFile' => PHPUNIT_COMPONENT_DIR.'zabbix_proxy.pid',
				'SocketDir' => PHPUNIT_COMPONENT_DIR,
				'ListenPort' => PHPUNIT_PORT_PREFIX.self::PROXY_PORT_SUFFIX
			]),
			self::COMPONENT_AGENT => [
				'LogFile' => PHPUNIT_COMPONENT_DIR.'zabbix_agent.log',
				'PidFile' => PHPUNIT_COMPONENT_DIR.'zabbix_agent.pid',
				'ListenPort' => PHPUNIT_PORT_PREFIX.self::AGENT_PORT_SUFFIX
			],
			self::COMPONENT_AGENT2 => [
				'LogFile' => PHPUNIT_COMPONENT_DIR.'zabbix_agent2.log',
				'PidFile' => PHPUNIT_COMPONENT_DIR.'zabbix_agent2.pid',
				'ListenPort' => PHPUNIT_PORT_PREFIX.self::AGENT_PORT_SUFFIX
			]
		];

		$configuration[self::COMPONENT_PROXY]['DBName'] .= '_proxy';

		return $configuration;
	}

	/**
	 * Create configuration file for component.
	 *
	 * @param string $component    component name
	 * @param array  $values       configuration array
	 *
	 * @throws Exception    on failed configuration file write
	 */
	protected static function prepareComponentConfiguration($component, $values) {
		self::validateComponent($component);

		$path = PHPUNIT_CONFIG_SOURCE_DIR.'zabbix_'.$component.'.conf';
		if (!file_exists($path) || ($config = @file_get_contents($path)) === false) {
			throw new Exception('There is no configuration file for component "'.$component.'": '.$path.'.');
		}

		if (array_key_exists($component, $values) && $values[$component] && is_array($values[$component])) {
			foreach ($values[$component] as $key => $value) {
				$result = preg_replace('/^'.$key.'\s*=.*$/m', $key.'='.$value, $config);
				if ($result !== $config) {
					$config = $result;
					continue;
				}
				else {
					$config .= "\n".$key.'='.$value;
				}
			}
		}

		if (file_put_contents(PHPUNIT_CONFIG_DIR.'zabbix_'.$component.'.conf', $config) === false) {
			throw new Exception('Failed to create configuration file for component "'.$component.'": '.
					PHPUNIT_CONFIG_DIR.'zabbix_'.$component.'.conf.'
			);
		}
	}

	/**
	 * Start component.
	 *
	 * @param string $component    component name
	 *
	 * @throws Exception    on missing configuration or failed start
	 */
	protected function startComponent($component) {
		self::validateComponent($component);

		$config = PHPUNIT_CONFIG_DIR.'zabbix_'.$component.'.conf';
		if (!file_exists($config)) {
			throw new Exception('There is no configuration file for component "'.$component.'".');
		}

		self::clearLog($component);
		$suffix = ($component === self::COMPONENT_AGENT2) ? ' > /dev/null 2>&1 &' : '';
		self::executeCommand(PHPUNIT_BINARY_DIR.'zabbix_'.$component, ['-c', $config], $suffix);
		self::waitForStartup($component);
	}

	/**
	 * Stop component.
	 *
	 * @param string $component    component name
	 *
	 * @throws Exception    on missing configuration or failed stop
	 */
	protected static function stopComponent($component) {
		self::validateComponent($component);

		$pid = @file_get_contents(self::getPidPath($component));
		if ($pid && is_numeric($pid)) {
			posix_kill($pid, SIGTERM);
		}
		self::waitForShutdown($component);
	}

	/**
	 * Restart component.
	 *
	 * @param string $component    component name
	 *
	 * @throws Exception    on missing configuration or failed restart
	 */
	protected static function restartComponent($component) {
		self::stopComponent($component);
		self::startComponent($component);
	}

	/**
	 * Get client for component.
	 *
	 * @param string $component    component name
	 *
	 * @throws Exception    on invalid component type
	 */
	protected function getClient($component) {
		self::validateComponent($component);

		if ($component === self::COMPONENT_AGENT || $component === self::COMPONENT_AGENT2) {
			throw new Exception('There is no client available for Zabbix Agent.');
		}

		return new CZabbixClient('localhost', self::getConfigurationValue($component, 'ListenPort', 10051),
				ZBX_SOCKET_TIMEOUT, ZBX_SOCKET_BYTES_LIMIT
		);
	}

	/**
	 * Get name of active component used in test.
	 *
	 * @return string
	 */
	protected function getActiveComponent() {
		$components = [];
		foreach (array_merge(self::$suite_components, $this->case_components) as $component) {
			if ($component !== self::COMPONENT_AGENT && $component !== self::COMPONENT_AGENT2) {
				$components[] = $component;
			}
		}

		if (count($components) === 1) {
			return $components[0];
		}
		else {
			return self::COMPONENT_SERVER;
		}
	}

	/**
	 * Send value for items to server.
	 *
	 * @param string $type         data type
	 * @param array  $values       item values
	 * @param string $component    component name or null for active component
	 *
	 * @return array    processing result
	 */
	protected function sendDataValues($type, $values, $component = null) {
		if ($component === null) {
			$component = $this->getActiveComponent();
		}

		$result = $this->getClient($component)->sendDataValues($type, $values);

		// Check that discovery data was sent.
		$this->assertTrue(array_key_exists('processed', $result), 'Result doesn\'t contain "processed" count.');
		$this->assertEquals(count($values), $result['processed'],
				'Processed value count doesn\'t match sent value count.'
		);

		sleep(self::DATA_PROCESSING_DELAY);

		return $result;
	}

	/**
	 * Send single item value.
	 *
	 * @param string $type         data type
	 * @param string $host         host name
	 * @param string $key          item key
	 * @param mixed  $value        item value
	 * @param string $component    component name or null for active component
	 *
	 * @return array    processing result
	 */
	protected function sendDataValue($type, $host, $key, $value, $component = null) {
		if (!is_scalar($value)) {
			$value = json_encode($value);
		}

		$data = [
			'host' => $host,
			'key' => $key,
			'value' => $value
		];

		return $this->sendDataValues($type, [$data], $component);
	}

	/**
	 * Send values to trapper items.
	 *
	 * @param array  $values       item values
	 * @param string $component    component name or null for active component
	 *
	 * @return array    processing result
	 */
	protected function sendSenderValues($values, $component = null) {
		return $this->sendDataValues('sender', $values, $component);
	}

	/**
	 * Send single value for trapper item.
	 *
	 * @param string $host         host name
	 * @param string $key          item key
	 * @param mixed  $value        item value
	 * @param string $component    component name or null for active component
	 *
	 * @return array    processing result
	 */
	protected function sendSenderValue($host, $key, $value, $component = null) {
		return $this->sendDataValue('sender', $host, $key, $value, $component);
	}

	/**
	 * Send values to active agent items.
	 *
	 * @param array  $values       item values
	 * @param string $component    component name or null for active component
	 *
	 * @return array    processing result
	 */
	protected function sendAgentValues($values, $component = null) {
		return $this->sendDataValues('agent', $values, $component);
	}

	/**
	 * Send single value for active agent item.
	 *
	 * @param string $host         host name
	 * @param string $key          item key
	 * @param mixed  $value        item value
	 * @param string $component    component name or null for active component
	 *
	 * @return array    processing result
	 */
	protected function sendAgentValue($host, $key, $value, $component = null) {
		return $this->sendDataValue('agent', $host, $key, $value, $component);
	}

	/**
	 * Get list of active checks for host.
	 *
	 * @param string $host         host name
	 * @param string $component    component name or null for active component
	 *
	 * @return array
	 */
	protected function getActiveAgentChecks($host, $component = null) {
		if ($component === null) {
			$component = $this->getActiveComponent();
		}

		$client = $this->getClient($component);
		$checks = $client->getActiveChecks($host);

		if (!is_array($checks)) {
			$this->fail('Cannot retrieve active checks for host "'.$host.'": '.$client->getError().'.');
		}

		return $checks;
	}

	/**
	 * Reload configuration cache.
	 *
	 * @param string $component    component name or null for active component
	 */
	protected function reloadConfigurationCache($component = null) {
		if ($component === null) {
			$component = $this->getActiveComponent();
		}

		$params = ['--runtime-control', 'config_cache_reload'];
		self::executeCommand(PHPUNIT_BINARY_DIR.'zabbix_'.$component, $params, '> /dev/null 2>&1');
		sleep(self::CACHE_RELOAD_DELAY);
	}

	/**
	 * Request data from API until data is present (@see call).
	 *
	 * @param string  $method        API method to be called
	 * @param mixed   $params        API call params
	 * @param integer $iterations    iteration count
	 * @param integer $delay         iteration delay
	 *
	 * @return array
	 */
	public function callUntilDataIsPresent($method, $params, $iterations = null, $delay = null) {
		if ($iterations === null) {
			$iterations = self::WAIT_ITERATIONS;
		}

		if ($delay === null) {
			$delay = self::WAIT_ITERATION_DELAY;
		}

		$exception = null;
		for ($i = 0; $i < $iterations; $i++) {
			try {
				$response = $this->call($method, $params);

				if (is_array($response['result']) && count($response['result']) > 0) {
					return $response;
				}
			} catch (Exception $e) {
				$exception = $e;
			}

			sleep($delay);
		}

		if ($exception !== null) {
			throw $exception;
		}

		$this->fail('Data requested from '.$method.' API is not present within specified interval. Params used:'.
				"\n".json_encode($params)
		);
	}

	/**
	 * Get path of the log file for component.
	 *
	 * @param string $component    name of the component
	 *
	 * @return string
	 */
	protected static function getLogPath($component) {
		self::validateComponent($component);

		return self::getConfigurationValue($component, 'LogFile', '/tmp/zabbix_'.$component.'.log');
	}

	/**
	 * Get path of the pid file for component.
	 *
	 * @param string $component    name of the component
	 *
	 * @return string
	 */
	protected static function getPidPath($component) {
		self::validateComponent($component);

		return self::getConfigurationValue($component, 'PidFile', '/tmp/zabbix_'.$component.'.log');
	}

	/**
	 * Get current configuration value.
	 *
	 * @param string $component    name of the component
	 * @param string $key          name of the configuration parameter
	 * @param mixed  $default      default value
	 *
	 * @return mixed
	 */
	protected static function getConfigurationValue($component, $key, $default = null) {
		$configuration = (self::$case_configuration) ? self::$case_configuration : self::$suite_configuration;

		if (array_key_exists($component, $configuration) && array_key_exists($key, $configuration[$component])) {
			return $configuration[$component][$key];
		}

		return $default;
	}

	/**
	 * Clear contents of log.
	 *
	 * @param string $component    name of the component
	 */
	protected static function clearLog($component) {
		CLogHelper::clearLog(self::getLogPath($component));
	}

	/**
	 * Check if line is present.
	 *
	 * @param string       $component     name of the component
	 * @param string|array $lines         line(s) to look for
	 * @param boolean      $incremental   flag to be used to enable incremental read
	 *
	 * @return boolean
	 */
	protected static function isLogLinePresent($component, $lines, $incremental = true) {
		return CLogHelper::isLogLinePresent(self::getLogPath($component), $lines, $incremental);
	}

	/**
	 * Wait until line is present in log.
	 *
	 * @param string       $component     name of the component
	 * @param string|array $lines         line(s) to look for
	 * @param boolean      $incremental   flag to be used to enable incremental read
	 * @param integer      $iterations    iteration count
	 * @param integer      $delay         iteration delay
	 *
	 * @throws Exception    on failed wait operation
	 */
	protected function waitForLogLineToBePresent($component, $lines, $incremental = true, $iterations = null, $delay = null) {
		if ($iterations === null) {
			$iterations = self::WAIT_ITERATIONS;
		}

		if ($delay === null) {
			$delay = self::WAIT_ITERATION_DELAY;
		}

		for ($r = 0; $r < $iterations; $r++) {
			if ($this->isLogLinePresent($component, $lines, $incremental)) {
				return;
			}

			sleep($delay);
		}

		if (is_array($lines)) {
			$quoted = [];
			foreach ($lines as $line) {
				$quoted[] = '"'.$line.'"';
			}

			$description = 'any of the lines ['.implode(', ', $quoted).']';
		}
		else {
			$description = 'line "'.$lines.'"';
		}

		throw new Exception('Failed to wait for '.$description.' to be present in '.$component.' log file.');
	}
}