forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddHostTest.php
90 lines (80 loc) · 3.57 KB
/
AddHostTest.php
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
<?php
/**
* addhostTest.php
*
* Tests for addhost funcion
*
* 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 3 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, see <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*
* @copyright 2020 Lars Elgtvedt Susaas
* @author Lars Elgtvedt Susaas
*/
namespace LibreNMS\Tests;
use App\Models\Device;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use LibreNMS\Config;
class AddHostTest extends DBTestCase
{
use DatabaseTransactions;
private $host = 'testHost';
public function testAddsnmpV1(): void
{
addHost($this->host, 'v1', 111, 'tcp', 0, true, 'ifIndex');
$device = Device::findByHostname($this->host);
$this->assertNotNull($device);
$this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
$this->assertEquals(1, $device->port_association_mode, 'Wrong port association mode');
$this->assertEquals('v1', $device->snmpver, 'Wrong snmp version');
$this->assertEquals(111, $device->port, 'Wrong snmp port');
$this->assertEquals('tcp', $device->transport, 'Wrong snmp transport (udp/tcp)');
}
public function testAddsnmpV2(): void
{
addHost($this->host, 'v2c', 111, 'tcp', 0, true, 'ifName');
$device = Device::findByHostname($this->host);
$this->assertNotNull($device);
$this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
$this->assertEquals(2, $device->port_association_mode, 'Wrong port association mode');
$this->assertEquals(Config::get('snmp.community')[0], $device->community, 'Wrong snmp community');
$this->assertEquals('v2c', $device->snmpver, 'Wrong snmp version');
}
public function testAddsnmpV3(): void
{
addHost($this->host, 'v3', 111, 'tcp', 0, true, 'ifIndex');
$device = Device::findByHostname($this->host);
$this->assertNotNull($device);
$this->assertEquals(0, $device->snmp_disable, 'snmp is disabled');
$this->assertEquals(1, $device->port_association_mode, 'Wrong port association mode');
$this->assertEquals(Config::get('snmp.v3')[0]['authlevel'], $device->authlevel, 'Wrong snmp v3 authlevel');
$this->assertEquals('v3', $device->snmpver, 'Wrong snmp version');
$this->assertEquals(Config::get('snmp.v3')[0]['authname'], $device->authname, 'Wrong snmp v3 username');
$this->assertEquals(Config::get('snmp.v3')[0]['authpass'], $device->authpass, 'Wrong snmp v3 password');
}
public function testAddping(): void
{
$additional = [
'snmp_disable' => 1,
'os' => 'nameOfOS',
'hardware' => 'hardware',
];
addHost($this->host, '', 0, 0, 0, true, 'ifIndex', $additional);
$device = Device::findByHostname($this->host);
$this->assertNotNull($device);
$this->assertEquals(1, $device->snmp_disable, 'snmp is not disabled');
$this->assertEquals('hardware', $device->hardware, 'Wrong hardware');
$this->assertEquals('nameOfOS', $device->os, 'Wrong os');
}
}