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

testPageHostInterfaces.php « hosts « selenium « tests « ui - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8919b9570c3d0d48204fea1750cd703d44f9a09c (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
<?php
/*
** Zabbix
** Copyright (C) 2001-2022 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 dirname(__FILE__).'/../../include/CWebTest.php';
require_once dirname(__FILE__).'/../../include/helpers/CDataHelper.php';

/**
 * @backup hosts
 * @onBefore prepareInterfacesData
 */
class testPageHostInterfaces extends CWebTest {

	const RED = 'rgba(214, 78, 78, 1)';
	const GREEN = 'rgba(52, 175, 103, 1)';
	const ORANGE = 'rgba(241, 165, 11, 1)';
	const GREY = 'rgba(235, 235, 235, 1)';


	public static function prepareInterfacesData() {
		$interfaces = [
			[
				'type' => 1,
				'main' => 1,
				'useip' => 0,
				'ip' => '127.1.1.1',
				'dns' => '1available.zabbix.com',
				'port' => '10050',
				'available' => 1
			],
			[
				'type' => 1,
				'main' => 0,
				'useip' => 0,
				'ip' => '127.1.1.2',
				'dns' => '2available.zabbix.com',
				'port' => '10051',
				'available' => 1
			],
			[
				'type' => 2,
				'main' => 1,
				'useip' => 1,
				'ip' => '127.0.0.98',
				'dns' => 'snmpv3zabbix.com',
				'port' => '163',
				'details' => [
					'version' => '3',
					'bulk' => '1',
					'securityname' => 'zabbix'
				],
				'available' => 1
			],
			[
				'type' => 2,
				'main' => 0,
				'useip' => 0,
				'ip' => '',
				'dns' => 'snmpv3auth.com',
				'port' => '163',
				'details' => [
					'version' => '3',
					'bulk' => '1',
					'securitylevel' => 2,
					'authprotocol' => 2,
					'privprotocol' => 4
				],
				'available' => 1
			],
			[
				'type' => 2,
				'main' => 0,
				'useip' => 1,
				'ip' => '127.0.0.99',
				'dns' => 'snmpv2zabbix.com',
				'port' => '162',
				'details' => [
					'version' => '2',
					'bulk' => '1',
					'community' => '{$SNMP_COMMUNITY}'
				],
				'available' => 2
			],
			[
				'type' => 3,
				'main' => 1,
				'useip' => 0,
				'ip' => '127.0.0.1',
				'dns' => '1unavail.IPMI.zabbix.com',
				'port' => '623',
				'available' => 2,
				'error' => '1 Error IPMI'
			],
			[
				'type' => 3,
				'main' => 0,
				'useip' => 0,
				'ip' => '127.0.0.1',
				'dns' => '2unavail.IPMI.zabbix.com',
				'port' => '624',
				'available' => 2,
				'error' => '2 Error IPMI'
			]
		];

		$groups = [
			[
				'groupid' => 4
			]
		];

		CDataHelper::createHosts([
			[
				'host' => 'Host with Orange interface',
				'name' => 'Host with Orange interface',
				'description' => 'API Created Host with Orange interface for Host availability test',
				'interfaces' => $interfaces,
				'groups' => $groups,
				'status' => HOST_STATUS_MONITORED
			]
		]);
	}

	public function getCheckInterfacesData() {
		return [
			[
				[
					'host' => 'Not available host',
					'interfaces' => [
						'ZBX' => [
							'color' => self::RED,
							'rows' => [
								[
									'Interface' => 'zabbixzabbixzabbix.com:10050',
									'Status' => [
										'text' => 'Not available',
										'color' => self::RED
									],
									'Error' => 'ERROR Agent'
								]
							]
						],
						'SNMP' => [
							'color' => self::RED,
							'rows' => [
								[
									'Interface' => "zabbixzabbixzabbix.com:10050\nSNMPv2, Community: {\$SNMP_COMMUNITY}",
									'Status' => [
										'text' => 'Not available',
										'color' => self::RED
									],
									'Error' => 'ERROR SNMP'
								]
							]
						],
						'IPMI' => [
							'color' => self::RED,
							'rows' => [
								[
									'Interface' => 'zabbixzabbixzabbix.com:10050',
									'Status' => [
										'text' => 'Not available',
										'color' => self::RED
									],
									'Error' => 'ERROR IPMI'
								]
							]
						],
						'JMX' => [
							'color' => self::RED,
							'rows' => [
								[
									'Interface' => 'zabbixzabbixzabbix.com:10050',
									'Status' => [
										'text' => 'Not available',
										'color' => self::RED
									],
									'Error' => 'ERROR JMX'
								]
							]
						]
					]
				]
			],
			[
				[
					'host' => 'Host with Orange interface',
					'interfaces' => [
						'ZBX' => [
							'color' => self::GREEN,
							'rows' => [
								[
									'Interface' => '1available.zabbix.com:10050',
									'Status' => [
										'text' => 'Available',
										'color' => self::GREEN
									],
									'Error' => ''
								],
								[
									'Interface' => '2available.zabbix.com:10051',
									'Status' => [
										'text' => 'Available',
										'color' => self::GREEN
									],
									'Error' => ''
								]
							]
						],
						'SNMP' => [
							'color' => self::ORANGE,
							'rows' => [
								[
									'Interface' => "127.0.0.98:163\nSNMPv3, Context name:",
									'Status' => [
										'text' => 'Available',
										'color' => self::GREEN
									],
									'Error' => ''
								],
								[
									'Interface' => "127.0.0.99:162\nSNMPv2, Community: {\$SNMP_COMMUNITY}",
									'Status' => [
										'text' => 'Not available',
										'color' => self::RED
									],
									'Error' => ''
								],
								[
									'Interface' => "snmpv3auth.com:163\nSNMPv3, Context name: , (priv: AES192C, auth: SHA224)",
									'Status' => [
										'text' => 'Available',
										'color' => self::GREEN
									],
									'Error' => ''
								]
							]
						],
						'IPMI' => [
							'color' => self::RED,
							'rows' => [
								[
									'Interface' => '1unavail.IPMI.zabbix.com:623',
									'Status' => [
										'text' => 'Not available',
										'color' => self::RED
									],
									'Error' => '1 Error IPMI'
								],
								[
									'Interface' => '2unavail.IPMI.zabbix.com:624',
									'Status' => [
										'text' => 'Not available',
										'color' => self::RED
									],
									'Error' => '2 Error IPMI'
								]
							]
						]
					]
				]
			],
			[
				[
					'host' => 'Template inheritance test host',
					'interfaces' => [
						'ZBX' => [
							'color' => self::GREY,
							'rows' => [
								[
									'Interface' => '127.0.0.1:10051',
									'Status' => [
										'text' => 'Unknown',
										'color' => self::GREY
									],
									'Error' => ''
								],
								[
									'Interface' => '127.0.0.2:10052',
									'Status' => [
										'text' => 'Unknown',
										'color' => self::GREY
									],
									'Error' => ''
								]
							]
						],
						'SNMP' => [
							'color' => self::GREY,
							'rows' => [
								[
									'Interface' => "127.0.0.3:10053\nSNMPv2, Community: {\$SNMP_COMMUNITY}",
									'Status' => [
										'text' => 'Unknown',
										'color' => self::GREY
									],
									'Error' => ''
								]
							]
						],
						'IPMI' => [
							'color' => self::GREY,
							'rows' => [
								[
									'Interface' => '127.0.0.4:10054',
									'Status' => [
										'text' => 'Unknown',
										'color' => self::GREY
									],
									'Error' => ''
								]
							]
						],
						'JMX' => [
							'color' => self::GREY,
							'rows' => [
								[
									'Interface' => '127.0.0.5:10055',
									'Status' => [
										'text' => 'Unknown',
										'color' => self::GREY
									],
									'Error' => ''
								]
							]
						]
					]
				]
			],
			[
				[
					'host' => 'Available host',
					'interfaces' => [
						'ZBX' => [
							'color' => self::GREEN,
							'rows' => [
								[
									'Interface' => '127.0.0.1:10050',
									'Status' => [
										'text' => 'Available',
										'color' => self::GREEN
									],
									'Error' => ''
								]
							]
						],
						'SNMP' => [
							'color' => self::GREEN,
							'rows' => [
								[
									'Interface' => "zabbixzabbixzabbix.com:10050\nSNMPv2, Community: {\$SNMP_COMMUNITY}",
									'Status' => [
										'text' => 'Available',
										'color' => self::GREEN
									],
									'Error' => ''
								]
							]
						],
						'IPMI' => [
							'color' => self::GREEN,
							'rows' => [
								[
									'Interface' => 'zabbixzabbixzabbix.com:10050',
									'Status' => [
										'text' => 'Available',
										'color' => self::GREEN
									],
									'Error' => ''
								]
							]
						],
						'JMX' => [
							'color' => self::GREEN,
							'rows' => [
								[
									'Interface' => 'zabbixzabbixzabbix.com:10050',
									'Status' => [
										'text' => 'Available',
										'color' => self::GREEN
									],
									'Error' => ''
								]
							]
						]
					]
				]
			]
		];
	}

	/**
	 * Test displaying host interfaces on Monitoring->Hosts page.
	 *
	 * @dataProvider getCheckInterfacesData
	 */
	public function testPageHostInterfaces_MonitoringHosts($data) {
		$this->checkInterfaces($data, 'zabbix.php?action=host.view', 'host_view');
	}

	/**
	 * Test displaying host interfaces on Configuration->Hosts page.
	 *
	 * @dataProvider getCheckInterfacesData
	 */
	public function testPageHostInterfaces_ConfigurationHosts($data) {
		$this->checkInterfaces($data, self::HOST_LIST_PAGE, 'hosts');
	}

	/**
	 * Test displaying host interfaces on Discovery rules page.
	 *
	 * @dataProvider getCheckInterfacesData
	 */
	public function testPageHostInterfaces_DiscoveryPage($data) {
		$id = CDBHelper::getValue('SELECT hostid FROM hosts WHERE host ='.zbx_dbstr($data['host']));
		$link = 'host_discovery.php?filter_set=1&filter_hostids%5B0%5D='.$id.'&context=host';
		$this->checkInterfaces($data, $link, $selector = null, true);
	}

	/**
	 * Function for checking interfaces.
	 *
	 * @param array     $data          data from data provider
	 * @param string    $link          checked page link
	 * @param string    $selector      table selector on page
	 * @param boolean   $navigation    is it upper navigation block or not
	 */
	private function checkInterfaces($data, $link, $selector = null, $navigation = false) {
		if ($navigation) {
			$this->page->login()->open($link)->waitUntilReady();
			$availability = $this->query('xpath://div[@class="status-container"]')->waitUntilPresent()->one();
		}
		else {
			$this->page->login()->open($link)->waitUntilReady();
			$table = $this->query('xpath://form[@name='.zbx_dbstr($selector).']/table[@class="list-table"]')
					->waitUntilReady()->asTable()->one();
			$availability = $table->findRow('Name', $data['host'])->getColumn('Availability');
		}

		$host_interfaces = [];
		foreach ($availability->query('xpath:.//span[@data-hintbox="1"]')->all() as $interface) {
			$interface_name = $interface->getText();
			// Write interfaces names into array.
			$host_interfaces[] = $interface_name;
			// Check interface color in availability column.
			$this->assertEquals($data['interfaces'][$interface_name]['color'], $interface->getCSSValue('background-color'));
			// Open interface popup.
			$interface->click();
			$overlay = $this->query('xpath://div[@class="overlay-dialogue"]')->asOverlayDialog()->waitUntilPresent()->one();
			$interface_table = $overlay->query('xpath:.//table[@class="list-table"]')->asTable()->one();
			// Check table headers in popup.
			$this->assertSame(['Interface', 'Status', 'Error'], $interface_table->getHeadersText());

			// Check every interface row.
			foreach ($interface_table->getRows() as $i => $row) {
				$interface_details  = $data['interfaces'][$interface_name]['rows'][$i];
				$this->assertEquals($interface_details['Interface'], $row->getColumn('Interface')->getText());
				$this->assertEquals($interface_details['Status']['text'], $row->getColumn('Status')->getText());
				$this->assertEquals($interface_details['Status']['color'], $row->getColumn('Status')
						->query('xpath:.//span[contains(@class, "status")]')->one()->getCSSValue('background-color'));
				$this->assertEquals($interface_details['Error'], $row->getColumn('Error')->getText());
			}

			$overlay->close();
			$overlay->waitUntilNotPresent();
		}
		// Assert interface names in Availability column.
		$this->assertEquals(array_keys($data['interfaces']), $host_interfaces);
	}
}