From fd9528501119dd211d038175858569d33291aa7f Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:18:36 +0300 Subject: [PATCH 01/34] New build 021. --- config/moring.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/moring.php b/config/moring.php index f33c3aad..5232d2fa 100644 --- a/config/moring.php +++ b/config/moring.php @@ -1,7 +1,7 @@ '020', + 'build' => '021', 'version' => '0.1.3', 'createYear' => '2019', 'bridgeUrl' => 'http://api.moring.ru/v1', From 0569eb58826d191aeb94bfb8a0851fe710f15d03 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:19:03 +0300 Subject: [PATCH 02/34] Fix unused vars. --- app/Repositories/Snmp/Vendors/Cisco.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Repositories/Snmp/Vendors/Cisco.php b/app/Repositories/Snmp/Vendors/Cisco.php index 965761f4..640cc82b 100644 --- a/app/Repositories/Snmp/Vendors/Cisco.php +++ b/app/Repositories/Snmp/Vendors/Cisco.php @@ -53,6 +53,8 @@ public function getFirmwareVersion($snmpFlow): string public function getPacketsVersion($snmpFlow): string { /* @var SNMP $snmpFlow */ + $snmpFlow->close(); + return (string) null; } @@ -115,6 +117,8 @@ public function getSerialNumber($snmpFlow): string public function getLicenseLevel($snmpFlow): string { /* @var SNMP $snmpFlow */ + $snmpFlow->close(); + return (string) null; } From 8e4e3c0d349c81066483f7415193d43a762f2222 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:19:15 +0300 Subject: [PATCH 03/34] Fix unused vars. --- app/Repositories/Snmp/Vendors/DLink.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Repositories/Snmp/Vendors/DLink.php b/app/Repositories/Snmp/Vendors/DLink.php index c667b059..c38ac79f 100644 --- a/app/Repositories/Snmp/Vendors/DLink.php +++ b/app/Repositories/Snmp/Vendors/DLink.php @@ -27,6 +27,8 @@ public function getModel($snmpFlow): string public function getFirmware($snmpFlow): string { /* @var SNMP $snmpFlow */ + $snmpFlow->close(); + return (string) 'D-Link Linux'; } @@ -50,6 +52,8 @@ public function getFirmwareVersion($snmpFlow): string public function getPacketsVersion($snmpFlow): string { /* @var SNMP $snmpFlow */ + $snmpFlow->close(); + return (string) null; } @@ -111,6 +115,8 @@ public function getSerialNumber($snmpFlow): string public function getLicenseLevel($snmpFlow): string { /* @var SNMP $snmpFlow */ + $snmpFlow->close(); + return (string) null; } From 76f7a6197da0d0b60a279528718f8843a0ea8115 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:19:22 +0300 Subject: [PATCH 04/34] Fix unused vars. --- app/Repositories/Snmp/Vendors/Eltex.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Repositories/Snmp/Vendors/Eltex.php b/app/Repositories/Snmp/Vendors/Eltex.php index 2d924140..f8324b04 100644 --- a/app/Repositories/Snmp/Vendors/Eltex.php +++ b/app/Repositories/Snmp/Vendors/Eltex.php @@ -27,6 +27,8 @@ public function getModel($snmpFlow): string public function getFirmware($snmpFlow): string { /* @var SNMP $snmpFlow */ + $snmpFlow->close(); + return (string) 'Eltex Linux'; } @@ -50,6 +52,8 @@ public function getFirmwareVersion($snmpFlow): string public function getPacketsVersion($snmpFlow): string { /* @var SNMP $snmpFlow */ + $snmpFlow->close(); + return (string) null; } @@ -111,6 +115,8 @@ public function getSerialNumber($snmpFlow): string public function getLicenseLevel($snmpFlow): string { /* @var SNMP $snmpFlow */ + $snmpFlow->close(); + return (string) null; } From 4de3bd9b5d11b1f24dd48d60af8a4c806bf6594d Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:19:43 +0300 Subject: [PATCH 05/34] Refactoring. --- app/Repositories/Devices/DevicesRepository.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Repositories/Devices/DevicesRepository.php b/app/Repositories/Devices/DevicesRepository.php index 96cb56e0..a145a8d8 100644 --- a/app/Repositories/Devices/DevicesRepository.php +++ b/app/Repositories/Devices/DevicesRepository.php @@ -140,22 +140,22 @@ public function setDataConnection($request): array public function getDeviceData(array $varsConnection): array { try { - $connection = new SnmpRepository(); - $snmpFlow = $connection->startSession($varsConnection)->walk('SNMPv2-MIB::sysDescr.0'); + $snmpObject = new SnmpRepository(); + $snmpFlow = $snmpObject->startSession($varsConnection); + $vendorNameRawString = $snmpObject->getVendorNameRawString($snmpFlow); } catch (Exception $e) { throw new Exception('Устройство не отвечает'); } $vendor = new Vendor(); - $vendorName = $vendor->parseName($snmpFlow); + $vendorName = $vendor->parseName($vendorNameRawString); if ($vendorName == null) { throw new Exception('Не удалось определить производителя.'); } /** @var VendorInterface $device */ - $snmpFlow = $connection->startSession($varsConnection); - $device = $vendor->getVendorClass($vendorName); + $device = $vendor->getVendorClass($vendorName); //Set vars $deviceData['hostname'] = $varsConnection['hostname']; From dc2817be6e0503ecfb18860af59464c022e48248 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:20:07 +0300 Subject: [PATCH 06/34] Refactoring. --- app/Repositories/Snmp/Vendor.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/Repositories/Snmp/Vendor.php b/app/Repositories/Snmp/Vendor.php index 701d5170..735e6dec 100644 --- a/app/Repositories/Snmp/Vendor.php +++ b/app/Repositories/Snmp/Vendor.php @@ -4,23 +4,23 @@ class Vendor { - public function parseName(array $snmpFlow): string + public function parseName(string $rawString): string { - if (isset($snmpFlow['SNMPv2-MIB::sysDescr.0'])) { - if (preg_match('/RouterOS/', $snmpFlow['SNMPv2-MIB::sysDescr.0'])) { - return 'Mikrotik'; + if (isset($rawString)) { + if (preg_match('/RouterOS/', $rawString)) { + return (string) 'Mikrotik'; } - if (preg_match('/Cisco/', $snmpFlow['SNMPv2-MIB::sysDescr.0'])) { - return 'Cisco'; + if (preg_match('/Cisco/', $rawString)) { + return (string) 'Cisco'; } - if (preg_match('/[D][EG][S]/', $snmpFlow['SNMPv2-MIB::sysDescr.0'])) { - return 'DLink'; + if (preg_match('/[D][EG][S]/', $rawString)) { + return (string) 'DLink'; } - if (preg_match('/MES/', $snmpFlow['SNMPv2-MIB::sysDescr.0'])) { - return 'Eltex'; + if (preg_match('/MES/', $rawString)) { + return (string) 'Eltex'; } } From 8ebf916fcad7e605142858c060934b0dbebbe2f1 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:21:10 +0300 Subject: [PATCH 07/34] Refactoring. --- app/Repositories/Snmp/SnmpRepository.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Repositories/Snmp/SnmpRepository.php b/app/Repositories/Snmp/SnmpRepository.php index b3c6b534..02abdbde 100644 --- a/app/Repositories/Snmp/SnmpRepository.php +++ b/app/Repositories/Snmp/SnmpRepository.php @@ -9,11 +9,12 @@ class SnmpRepository extends Repository { public function startSession($varsConnection) { - return new SNMP(SNMP::VERSION_2c, $varsConnection['hostname'], $varsConnection['snmpCommunity']); + return new SNMP(SNMP::VERSION_2c, $varsConnection['hostname'], $varsConnection['snmpCommunity']); } - public function name($nameArray) + public function getVendorNameRawString($snmpFlow) { - return $nameArray['1.3.6.1.2.1.1.1.0']; + /** @var SNMP $snmpFlow */ + return $snmpFlow->get('1.3.6.1.2.1.1.1.0'); } } From 6d82542d977f1b949ecf8b9216dddf8244fcf2e0 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:21:40 +0300 Subject: [PATCH 08/34] Added new SNMP test. --- tests/Unit/SNMP_Vendors/CiscoTest.php | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/Unit/SNMP_Vendors/CiscoTest.php diff --git a/tests/Unit/SNMP_Vendors/CiscoTest.php b/tests/Unit/SNMP_Vendors/CiscoTest.php new file mode 100644 index 00000000..ab21cfcf --- /dev/null +++ b/tests/Unit/SNMP_Vendors/CiscoTest.php @@ -0,0 +1,35 @@ +startSession($this->setVarsConnection()); + $vendorNameRawString = $snmpObject->getVendorNameRawString($snmpFlow); + + $vendor = new Vendor(); + $this->assertEquals('Cisco', $vendor->parseName($vendorNameRawString)); + } + + public function testGetVendorClass(): void + { + $vendor = new Vendor(); + $this->assertInstanceOf(Cisco::class, $vendor->getVendorClass('Cisco')); + } + + private function setVarsConnection() + { + $array['hostname'] = '127.0.0.1:9002'; + $array['snmpCommunity'] = 'public'; + + return $array; + } +} From 888e4e9744ffec8175efc668210541530ea7f1c4 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:21:47 +0300 Subject: [PATCH 09/34] Added new SNMP test. --- tests/Unit/SNMP_Vendors/CloudMikrotikTest.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/Unit/SNMP_Vendors/CloudMikrotikTest.php diff --git a/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php b/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php new file mode 100644 index 00000000..73630747 --- /dev/null +++ b/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php @@ -0,0 +1,35 @@ +startSession($this->setVarsConnection()); + $vendorNameRawString = $snmpObject->getVendorNameRawString($snmpFlow); + + $vendor = new Vendor(); + $this->assertEquals('Mikrotik', $vendor->parseName($vendorNameRawString)); + } + + public function testGetVendorClass(): void + { + $class = new Mikrotik(); + $this->assertEquals($class, (new Vendor())->getVendorClass('Mikrotik')); + } + + private function setVarsConnection() + { + $array['hostname'] = '127.0.0.1:9001'; + $array['snmpCommunity'] = 'public'; + + return $array; + } +} From 39630fdd23240c5efee3b3ad6fef7500c4852ccc Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:22:40 +0300 Subject: [PATCH 10/34] Added new SNMP test. --- tests/Unit/SNMP_Vendors/DLinkTest.php | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/Unit/SNMP_Vendors/DLinkTest.php diff --git a/tests/Unit/SNMP_Vendors/DLinkTest.php b/tests/Unit/SNMP_Vendors/DLinkTest.php new file mode 100644 index 00000000..1b544e9a --- /dev/null +++ b/tests/Unit/SNMP_Vendors/DLinkTest.php @@ -0,0 +1,35 @@ +startSession($this->setVarsConnection()); + $vendorNameRawString = $snmpObject->getVendorNameRawString($snmpFlow); + + $vendor = new Vendor(); + $this->assertEquals('DLink', $vendor->parseName($vendorNameRawString)); + } + + public function testGetVendorClass(): void + { + $class = new DLink(); + $this->assertEquals($class, (new Vendor())->getVendorClass('DLink')); + } + + private function setVarsConnection() + { + $array['hostname'] = '127.0.0.1:9003'; + $array['snmpCommunity'] = 'public'; + + return $array; + } +} From 0b7efb3f8603c4ed537274743f6c0b77a4618014 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:22:49 +0300 Subject: [PATCH 11/34] Added new SNMP test. --- tests/Unit/SNMP_Vendors/EltexTest.php | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/Unit/SNMP_Vendors/EltexTest.php diff --git a/tests/Unit/SNMP_Vendors/EltexTest.php b/tests/Unit/SNMP_Vendors/EltexTest.php new file mode 100644 index 00000000..93f3d83c --- /dev/null +++ b/tests/Unit/SNMP_Vendors/EltexTest.php @@ -0,0 +1,35 @@ +startSession($this->setVarsConnection()); + $vendorNameRawString = $snmpObject->getVendorNameRawString($snmpFlow); + + $vendor = new Vendor(); + $this->assertEquals('Eltex', $vendor->parseName($vendorNameRawString)); + } + + public function testGetVendorClass(): void + { + $class = new Eltex(); + $this->assertEquals($class, (new Vendor())->getVendorClass('Eltex')); + } + + private function setVarsConnection() + { + $array['hostname'] = '127.0.0.1:9004'; + $array['snmpCommunity'] = 'public'; + + return $array; + } +} From 9032f66aab3d45fb8e30ecfa69bdbdd950aa9970 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:22:58 +0300 Subject: [PATCH 12/34] Added new SNMP test. --- tests/Unit/SNMP_Vendors/EmptyVendorTest.php | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/Unit/SNMP_Vendors/EmptyVendorTest.php diff --git a/tests/Unit/SNMP_Vendors/EmptyVendorTest.php b/tests/Unit/SNMP_Vendors/EmptyVendorTest.php new file mode 100644 index 00000000..da6432f4 --- /dev/null +++ b/tests/Unit/SNMP_Vendors/EmptyVendorTest.php @@ -0,0 +1,28 @@ +startSession($this->setVarsConnection()); + $vendorNameRawString = $snmpObject->getVendorNameRawString($snmpFlow); + + $vendor = new Vendor(); + $this->assertEquals(null, $vendor->parseName($vendorNameRawString)); + } + + private function setVarsConnection() + { + $array['hostname'] = '127.0.0.1:9006'; + $array['snmpCommunity'] = 'public'; + + return $array; + } +} From 8e3f8fbe6c1b5f67428ccf692d3d9c4f4efb214f Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:23:04 +0300 Subject: [PATCH 13/34] Added new SNMP test. --- .../SNMP_Vendors/HardwareMikrotikTest.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php diff --git a/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php b/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php new file mode 100644 index 00000000..375a3df9 --- /dev/null +++ b/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php @@ -0,0 +1,35 @@ +startSession($this->setVarsConnection()); + $vendorNameRawString = $snmpObject->getVendorNameRawString($snmpFlow); + + $vendor = new Vendor(); + $this->assertEquals('Mikrotik', $vendor->parseName($vendorNameRawString)); + } + + public function testGetVendorClass(): void + { + $class = new Mikrotik(); + $this->assertEquals($class, (new Vendor())->getVendorClass('Mikrotik')); + } + + private function setVarsConnection() + { + $array['hostname'] = '127.0.0.1:9005'; + $array['snmpCommunity'] = 'public'; + + return $array; + } +} From 604a9cf177a41acee92833b3c9337f2c25567c6f Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:26:02 +0300 Subject: [PATCH 14/34] Added new SNMP emulation server. --- .github/workflows/laravel.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/laravel.yml b/.github/workflows/laravel.yml index 41fb68ee..c298a553 100644 --- a/.github/workflows/laravel.yml +++ b/.github/workflows/laravel.yml @@ -53,6 +53,9 @@ jobs: - name: Run SNMP server (Mikrotik hardware) run: python /home/runner/work/moring/moring/utils/snmp-server/snmp-server.py -p 9005 -c /home/runner/work/moring/moring/utils/snmp-server/configs/HardwareMikrotik.py & + - name: Run SNMP server (Empty vendor) + run: python /home/runner/work/moring/moring/utils/snmp-server/snmp-server.py -p 9006 -c /home/runner/work/moring/moring/utils/snmp-server/configs/EmptyVendor.py & + - name: Check SNMP server 1 run: snmpwalk -v2c -c public 127.0.0.1:9001 @@ -68,6 +71,9 @@ jobs: - name: Check SNMP server 5 run: snmpwalk -v2c -c public 127.0.0.1:9005 + - name: Check SNMP server 6 + run: snmpwalk -v2c -c public 127.0.0.1:9006 + - name: Copy .env run: php -r "file_exists('.env') || copy('.env.testing.example', '.env');" From 16905430dad8aaa1cb188de1facef6aa9a3b4fdc Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:26:34 +0300 Subject: [PATCH 15/34] Added new SNMP test. --- commands/testing_local.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands/testing_local.sh b/commands/testing_local.sh index ae78e4cb..1860a603 100644 --- a/commands/testing_local.sh +++ b/commands/testing_local.sh @@ -26,13 +26,16 @@ PID4=$! python utils/snmp-server/snmp-server.py -p 9005 -c utils/snmp-server/configs/HardwareMikrotik.py & PID5=$! +python utils/snmp-server/snmp-server.py -p 9006 -c utils/snmp-server/configs/EmptyVendor.py & +PID6=$! + echo 'Starting PHPunit' #./vendor/bin/phpunit --coverage-html report_coverage ./vendor/bin/phpunit #./vendor/bin/phpunit --filter testGetSerialNumber tests/Unit/SNMP/CloudMikrotikEmptyOIDTest.php echo 'Killing SNMP servers' -kill $PID1 $PID2 $PID3 $PID4 $PID5 +kill $PID1 $PID2 $PID3 $PID4 $PID5 $PID6 echo 'Removing .env file' rm -f .env From bf64119c7a869c057527094ce84325b79275ad3c Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:30:28 +0300 Subject: [PATCH 16/34] Code style fix. --- app/Repositories/Snmp/SnmpRepository.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Repositories/Snmp/SnmpRepository.php b/app/Repositories/Snmp/SnmpRepository.php index 02abdbde..593dcc89 100644 --- a/app/Repositories/Snmp/SnmpRepository.php +++ b/app/Repositories/Snmp/SnmpRepository.php @@ -9,12 +9,12 @@ class SnmpRepository extends Repository { public function startSession($varsConnection) { - return new SNMP(SNMP::VERSION_2c, $varsConnection['hostname'], $varsConnection['snmpCommunity']); + return new SNMP(SNMP::VERSION_2c, $varsConnection['hostname'], $varsConnection['snmpCommunity']); } public function getVendorNameRawString($snmpFlow) { /** @var SNMP $snmpFlow */ - return $snmpFlow->get('1.3.6.1.2.1.1.1.0'); + return $snmpFlow->get('1.3.6.1.2.1.1.1.0'); } } From 4ce4c469bd0fa52c1a8bd81bd448010db2e75833 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:30:34 +0300 Subject: [PATCH 17/34] Code style fix. --- tests/Unit/SNMP_Vendors/CiscoTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/SNMP_Vendors/CiscoTest.php b/tests/Unit/SNMP_Vendors/CiscoTest.php index ab21cfcf..3a105d1a 100644 --- a/tests/Unit/SNMP_Vendors/CiscoTest.php +++ b/tests/Unit/SNMP_Vendors/CiscoTest.php @@ -2,9 +2,9 @@ namespace Tests\Unit\SNMP_Vendors; +use App\Repositories\Snmp\SnmpRepository; use App\Repositories\Snmp\Vendor; use App\Repositories\Snmp\Vendors\Cisco; -use App\Repositories\Snmp\SnmpRepository; use Tests\TestCase; class CiscoTest extends TestCase From a0ebcf775533f35eef516a8803764f23fe6e2c70 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:30:40 +0300 Subject: [PATCH 18/34] Code style fix. --- tests/Unit/SNMP_Vendors/CloudMikrotikTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php b/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php index 73630747..44166c0b 100644 --- a/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php +++ b/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php @@ -2,8 +2,8 @@ namespace Tests\Unit\SNMP_Vendors; -use App\Repositories\Snmp\Vendor; use App\Repositories\Snmp\SnmpRepository; +use App\Repositories\Snmp\Vendor; use App\Repositories\Snmp\Vendors\Mikrotik; use Tests\TestCase; From d52a23e069c7de884e8d6c73e754c6862bac4350 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:30:46 +0300 Subject: [PATCH 19/34] Code style fix. --- tests/Unit/SNMP_Vendors/DLinkTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/SNMP_Vendors/DLinkTest.php b/tests/Unit/SNMP_Vendors/DLinkTest.php index 1b544e9a..a375e65f 100644 --- a/tests/Unit/SNMP_Vendors/DLinkTest.php +++ b/tests/Unit/SNMP_Vendors/DLinkTest.php @@ -2,9 +2,9 @@ namespace Tests\Unit\SNMP_Vendors; +use App\Repositories\Snmp\SnmpRepository; use App\Repositories\Snmp\Vendor; use App\Repositories\Snmp\Vendors\DLink; -use App\Repositories\Snmp\SnmpRepository; use Tests\TestCase; class DLinkTest extends TestCase From 90a543de5fbd631ff8abe3fbd20794029991f93c Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:30:55 +0300 Subject: [PATCH 20/34] Code style fix. --- tests/Unit/SNMP_Vendors/EltexTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/SNMP_Vendors/EltexTest.php b/tests/Unit/SNMP_Vendors/EltexTest.php index 93f3d83c..c3630345 100644 --- a/tests/Unit/SNMP_Vendors/EltexTest.php +++ b/tests/Unit/SNMP_Vendors/EltexTest.php @@ -2,9 +2,9 @@ namespace Tests\Unit\SNMP_Vendors; +use App\Repositories\Snmp\SnmpRepository; use App\Repositories\Snmp\Vendor; use App\Repositories\Snmp\Vendors\Eltex; -use App\Repositories\Snmp\SnmpRepository; use Tests\TestCase; class EltexTest extends TestCase From f1ae6c03728620fea0b090566a99b791590f8f44 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:31:01 +0300 Subject: [PATCH 21/34] Code style fix. --- tests/Unit/SNMP_Vendors/EmptyVendorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/SNMP_Vendors/EmptyVendorTest.php b/tests/Unit/SNMP_Vendors/EmptyVendorTest.php index da6432f4..74556b4c 100644 --- a/tests/Unit/SNMP_Vendors/EmptyVendorTest.php +++ b/tests/Unit/SNMP_Vendors/EmptyVendorTest.php @@ -2,8 +2,8 @@ namespace Tests\Unit\SNMP_Vendors; -use App\Repositories\Snmp\Vendor; use App\Repositories\Snmp\SnmpRepository; +use App\Repositories\Snmp\Vendor; use Tests\TestCase; class EmptyVendorTest extends TestCase From 72bc28e9e779bcd7aa15470311afa172b83ad0d5 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:31:07 +0300 Subject: [PATCH 22/34] Code style fix. --- tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php b/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php index 375a3df9..bc7ac417 100644 --- a/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php +++ b/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php @@ -2,10 +2,10 @@ namespace Tests\Unit\SNMP_Vendors; -use App\Repositories\Snmp\Vendor; use App\Repositories\Snmp\SnmpRepository; -use Tests\TestCase; +use App\Repositories\Snmp\Vendor; use App\Repositories\Snmp\Vendors\Mikrotik; +use Tests\TestCase; class HardwareMikrotikTest extends TestCase { From d6f06b6043d0bb179220ff75a724e90a42a2fa38 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 12:35:08 +0300 Subject: [PATCH 23/34] Added new & update oldest configs. --- utils/snmp-server/configs/DLink.py | 13 +++++++------ utils/snmp-server/configs/Eltex.py | 13 +++++++------ utils/snmp-server/configs/EmptyVendor.py | 17 +++++++++++++++++ utils/snmp-server/configs/HowGetNumericOid.md | 15 +++++++++------ 4 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 utils/snmp-server/configs/EmptyVendor.py diff --git a/utils/snmp-server/configs/DLink.py b/utils/snmp-server/configs/DLink.py index 118fb80b..6f8bf9cf 100644 --- a/utils/snmp-server/configs/DLink.py +++ b/utils/snmp-server/configs/DLink.py @@ -6,12 +6,13 @@ def my_response(oid): DATA = { - '1.3.6.1.2.1.16.19.2.0': octet_string('1.16.B002'), # SNMPv2-SMI::mib-2.16.19.2.0 - '1.3.6.1.2.1.1.3.0': octet_string('2520849600'), # DISMAN-EVENT-MIB::sysUpTimeInstance - '1.3.6.1.2.1.1.4.0': octet_string('admin@mail.test'), # SNMPv2-MIB::sysContact.0 - '1.3.6.1.2.1.1.6.0': octet_string('DC Super'), # SNMPv2-MIB::sysLocation.0 - '1.3.6.1.2.1.47.1.1.1.1.11.1' : octet_string('RZ1O1DA000532'), # SNMPv2-SMI::mib-2.47.1.1.1.1.11.1 - '1.3.6.1.2.1.47.1.1.1.1.7.1': octet_string('DGS-3000-10TC') # SNMPv2-SMI::mib-2.47.1.1.1.1.7.1 + '1.3.6.1.2.1.1.1.0': octet_string('DGS-3000-10TC Gigabit Ethernet Switch'), # SNMPv2-MIB::sysDescr.0 + '1.3.6.1.2.1.16.19.2.0': octet_string('1.16.B002'), # SNMPv2-SMI::mib-2.16.19.2.0 + '1.3.6.1.2.1.1.3.0': octet_string('2520849600'), # DISMAN-EVENT-MIB::sysUpTimeInstance + '1.3.6.1.2.1.1.4.0': octet_string('admin@mail.test'), # SNMPv2-MIB::sysContact.0 + '1.3.6.1.2.1.1.6.0': octet_string('DC Super'), # SNMPv2-MIB::sysLocation.0 + '1.3.6.1.2.1.47.1.1.1.1.11.1' : octet_string('RZ1O1DA000532'), # SNMPv2-SMI::mib-2.47.1.1.1.1.11.1 + '1.3.6.1.2.1.47.1.1.1.1.7.1': octet_string('DGS-3000-10TC') # SNMPv2-SMI::mib-2.47.1.1.1.1.7.1 } # Example: diff --git a/utils/snmp-server/configs/Eltex.py b/utils/snmp-server/configs/Eltex.py index 2d21e711..8e35e27a 100644 --- a/utils/snmp-server/configs/Eltex.py +++ b/utils/snmp-server/configs/Eltex.py @@ -6,12 +6,13 @@ def my_response(oid): DATA = { - '1.3.6.1.2.1.47.1.1.1.1.10.67108992': octet_string('4.0.7'), # SNMPv2-SMI::mib-2.47.1.1.1.1.10.67108992 - '1.3.6.1.2.1.1.3.0': octet_string('2409917400'), # DISMAN-EVENT-MIB::sysUpTimeInstance - '1.3.6.1.2.1.1.4.0': octet_string('admin@mail.test'), # SNMPv2-MIB::sysContact.0 - '1.3.6.1.2.1.1.6.0': octet_string('DC Super'), # SNMPv2-MIB::sysLocation.0 - '1.3.6.1.2.1.47.1.1.1.1.11.67108992' : octet_string('ES32001131'), # SNMPv2-SMI::mib-2.47.1.1.1.1.11.67108992 - '1.3.6.1.2.1.47.1.1.1.1.13.67108992': octet_string('MES2324B') # SNMPv2-SMI::mib-2.47.1.1.1.1.13.67108992 + '1.3.6.1.2.1.1.1.0': octet_string('MES2324B 28-port 1G/10G Managed Switch'), # SNMPv2-MIB::sysDescr.0 + '1.3.6.1.2.1.47.1.1.1.1.10.67108992': octet_string('4.0.7'), # SNMPv2-SMI::mib-2.47.1.1.1.1.10.67108992 + '1.3.6.1.2.1.1.3.0': octet_string('2409917400'), # DISMAN-EVENT-MIB::sysUpTimeInstance + '1.3.6.1.2.1.1.4.0': octet_string('admin@mail.test'), # SNMPv2-MIB::sysContact.0 + '1.3.6.1.2.1.1.6.0': octet_string('DC Super'), # SNMPv2-MIB::sysLocation.0 + '1.3.6.1.2.1.47.1.1.1.1.11.67108992' : octet_string('ES32001131'), # SNMPv2-SMI::mib-2.47.1.1.1.1.11.67108992 + '1.3.6.1.2.1.47.1.1.1.1.13.67108992': octet_string('MES2324B') # SNMPv2-SMI::mib-2.47.1.1.1.1.13.67108992 } # Example: diff --git a/utils/snmp-server/configs/EmptyVendor.py b/utils/snmp-server/configs/EmptyVendor.py new file mode 100644 index 00000000..3a283b6e --- /dev/null +++ b/utils/snmp-server/configs/EmptyVendor.py @@ -0,0 +1,17 @@ +# SNMP server response config example + +def my_response(oid): + res = '|'.join(oid.split('.')) + return octet_string('response: {}'.format(res)) + +DATA = { + '1.3.6.1.2.1.1.1.0': octet_string(''), # SNMPv2-MIB::sysDescr.0 +} + +# Example: +# SNMPv2-MIB::sysDescr.0 = STRING: RouterOS CHR +# DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (199892900) 23 days, 3:15:29.00 +# SNMPv2-MIB::sysContact.0 = STRING: admin@mail.test +# SNMPv2-MIB::sysLocation.0 = STRING: DC Super +# SNMPv2-SMI::enterprises.14988.1.1.4.3.0 = INTEGER: 1 +# SNMPv2-SMI::enterprises.14988.1.1.4.4.0 = STRING: "6.46.4 diff --git a/utils/snmp-server/configs/HowGetNumericOid.md b/utils/snmp-server/configs/HowGetNumericOid.md index 151b2168..d7e9d252 100644 --- a/utils/snmp-server/configs/HowGetNumericOid.md +++ b/utils/snmp-server/configs/HowGetNumericOid.md @@ -1,4 +1,5 @@ -* Start SNMP server +* Start SNMP server + ```bash python snmp-server.py -p 9005 ``` @@ -8,12 +9,14 @@ SNMP server listening on 0.0.0.0:9005 ``` -* Send command: +* Send command: + ```bash snmpwalk -v2c -c public 127.0.0.1:9005 SNMPv2-MIB::sysDescr.0 ``` -* Answer from virtual SNMP server - ```bash - SNMPv2-MIB::sysDescr.0 = STRING: 1.3.6.1.2.1.1.1.0 - ``` +* Answer from virtual SNMP server + + ```bash + SNMPv2-MIB::sysDescr.0 = STRING: 1.3.6.1.2.1.1.1.0 + ``` From 04a34c7873412bd979a348b576193faacbdfdafb Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 13:43:29 +0300 Subject: [PATCH 24/34] Added snmp port. --- app/Repositories/Snmp/SnmpRepository.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Repositories/Snmp/SnmpRepository.php b/app/Repositories/Snmp/SnmpRepository.php index 593dcc89..ef67429c 100644 --- a/app/Repositories/Snmp/SnmpRepository.php +++ b/app/Repositories/Snmp/SnmpRepository.php @@ -9,7 +9,10 @@ class SnmpRepository extends Repository { public function startSession($varsConnection) { - return new SNMP(SNMP::VERSION_2c, $varsConnection['hostname'], $varsConnection['snmpCommunity']); + return new SNMP( + SNMP::VERSION_2c, + $varsConnection['hostname'] . ':' . $varsConnection['port'], $varsConnection['community'] + ); } public function getVendorNameRawString($snmpFlow) From 6ef52ba02f1e759feea069616f9c02928eb3ded2 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 13:44:37 +0300 Subject: [PATCH 25/34] Renaming vars. --- tests/Unit/SNMP_Vendors/CiscoTest.php | 4 ++-- tests/Unit/SNMP_Vendors/CloudMikrotikTest.php | 8 ++++---- tests/Unit/SNMP_Vendors/DLinkTest.php | 4 ++-- tests/Unit/SNMP_Vendors/EltexTest.php | 4 ++-- tests/Unit/SNMP_Vendors/EmptyVendorTest.php | 4 ++-- tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/Unit/SNMP_Vendors/CiscoTest.php b/tests/Unit/SNMP_Vendors/CiscoTest.php index 3a105d1a..c0df0dc8 100644 --- a/tests/Unit/SNMP_Vendors/CiscoTest.php +++ b/tests/Unit/SNMP_Vendors/CiscoTest.php @@ -27,8 +27,8 @@ public function testGetVendorClass(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9002'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9002'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php b/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php index 44166c0b..4f520f82 100644 --- a/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php +++ b/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php @@ -11,8 +11,8 @@ class CloudMikrotikTest extends TestCase { public function testParseName(): void { - $snmpObject = new SnmpRepository(); - $snmpFlow = $snmpObject->startSession($this->setVarsConnection()); + $snmpObject = new SnmpRepository(); + $snmpFlow = $snmpObject->startSession($this->setVarsConnection()); $vendorNameRawString = $snmpObject->getVendorNameRawString($snmpFlow); $vendor = new Vendor(); @@ -27,8 +27,8 @@ public function testGetVendorClass(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9001'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9001'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP_Vendors/DLinkTest.php b/tests/Unit/SNMP_Vendors/DLinkTest.php index a375e65f..a6aea2ae 100644 --- a/tests/Unit/SNMP_Vendors/DLinkTest.php +++ b/tests/Unit/SNMP_Vendors/DLinkTest.php @@ -27,8 +27,8 @@ public function testGetVendorClass(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9003'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9003'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP_Vendors/EltexTest.php b/tests/Unit/SNMP_Vendors/EltexTest.php index c3630345..389cb6ba 100644 --- a/tests/Unit/SNMP_Vendors/EltexTest.php +++ b/tests/Unit/SNMP_Vendors/EltexTest.php @@ -27,8 +27,8 @@ public function testGetVendorClass(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9004'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9004'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP_Vendors/EmptyVendorTest.php b/tests/Unit/SNMP_Vendors/EmptyVendorTest.php index 74556b4c..dbeffaa2 100644 --- a/tests/Unit/SNMP_Vendors/EmptyVendorTest.php +++ b/tests/Unit/SNMP_Vendors/EmptyVendorTest.php @@ -20,8 +20,8 @@ public function testParseName(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9006'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9006'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php b/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php index bc7ac417..aeca8834 100644 --- a/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php +++ b/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php @@ -27,8 +27,8 @@ public function testGetVendorClass(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9005'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9005'; + $array['community'] = 'public'; return $array; } From fa560a21115b82ed93ef589a59df9e98f4797fec Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 13:45:18 +0300 Subject: [PATCH 26/34] Renaming vars. --- tests/Unit/SNMP/CiscoTest.php | 4 +-- .../Unit/SNMP/CloudMikrotikExceptionTest.php | 4 +-- tests/Unit/SNMP/CloudMikrotikTest.php | 4 +-- tests/Unit/SNMP/DLinkTest.php | 26 +++++++++---------- tests/Unit/SNMP/EltexTest.php | 26 +++++++++---------- tests/Unit/SNMP/HardwareMikrotikTest.php | 4 +-- 6 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/Unit/SNMP/CiscoTest.php b/tests/Unit/SNMP/CiscoTest.php index eac60337..a18e7ee3 100644 --- a/tests/Unit/SNMP/CiscoTest.php +++ b/tests/Unit/SNMP/CiscoTest.php @@ -91,8 +91,8 @@ public function testGetPlatformType(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9002'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9002'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP/CloudMikrotikExceptionTest.php b/tests/Unit/SNMP/CloudMikrotikExceptionTest.php index 5c73028e..dd351f8e 100644 --- a/tests/Unit/SNMP/CloudMikrotikExceptionTest.php +++ b/tests/Unit/SNMP/CloudMikrotikExceptionTest.php @@ -24,8 +24,8 @@ public function testGetFirmwareVersion(): void private function setVarsConnection() { - $array['hostname'] = '0.0.0.0'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '0.0.0.0'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP/CloudMikrotikTest.php b/tests/Unit/SNMP/CloudMikrotikTest.php index e34e1213..13c15d3b 100644 --- a/tests/Unit/SNMP/CloudMikrotikTest.php +++ b/tests/Unit/SNMP/CloudMikrotikTest.php @@ -91,8 +91,8 @@ public function testGetPlatformType(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9001'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9001'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP/DLinkTest.php b/tests/Unit/SNMP/DLinkTest.php index f8b3dc75..85836d6e 100644 --- a/tests/Unit/SNMP/DLinkTest.php +++ b/tests/Unit/SNMP/DLinkTest.php @@ -12,7 +12,7 @@ public function testGetModel(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals('DGS-3000-10TC', $vendor->getModel($snmpConnection)); } @@ -20,7 +20,7 @@ public function testGetFirmware(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals('D-Link Linux', $vendor->getFirmware($snmpConnection)); } @@ -28,7 +28,7 @@ public function testGetFirmwareVersion(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals('1.16.B002', $vendor->getFirmwareVersion($snmpConnection)); } @@ -36,7 +36,7 @@ public function testGetPacketsVersion(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals(null, $vendor->getPacketsVersion($snmpConnection)); } @@ -44,7 +44,7 @@ public function testGetUptime(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals('2520849600', $vendor->getUptime($snmpConnection)); } @@ -52,7 +52,7 @@ public function testGetContact(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals('admin@mail.test', $vendor->getContact($snmpConnection)); } @@ -60,7 +60,7 @@ public function testGetLocation(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals('DC Super', $vendor->getLocation($snmpConnection)); } @@ -68,7 +68,7 @@ public function testGetSerialNumber(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals('RZ1O1DA000532', $vendor->getSerialNumber($snmpConnection)); } @@ -76,7 +76,7 @@ public function testGetLicenseLevel(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); + $vendor = new DLink(); $this->assertEquals(null, $vendor->getLicenseLevel($snmpConnection)); } @@ -84,15 +84,15 @@ public function testGetPlatformType(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new DLink(); - $model = $vendor->getModel($snmpConnection); + $vendor = new DLink(); + $model = $vendor->getModel($snmpConnection); $this->assertEquals(0, $vendor->getPlatformType($model)); } private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9003'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9003'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP/EltexTest.php b/tests/Unit/SNMP/EltexTest.php index 90dcac71..219e3ef4 100644 --- a/tests/Unit/SNMP/EltexTest.php +++ b/tests/Unit/SNMP/EltexTest.php @@ -12,7 +12,7 @@ public function testGetModel(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals('MES2324B', $vendor->getModel($snmpConnection)); } @@ -20,7 +20,7 @@ public function testGetFirmware(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals('Eltex Linux', $vendor->getFirmware($snmpConnection)); } @@ -28,7 +28,7 @@ public function testGetFirmwareVersion(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals('4.0.7', $vendor->getFirmwareVersion($snmpConnection)); } @@ -36,7 +36,7 @@ public function testGetPacketsVersion(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals(null, $vendor->getPacketsVersion($snmpConnection)); } @@ -44,7 +44,7 @@ public function testGetUptime(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals('2409917400', $vendor->getUptime($snmpConnection)); } @@ -52,7 +52,7 @@ public function testGetContact(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals('admin@mail.test', $vendor->getContact($snmpConnection)); } @@ -60,7 +60,7 @@ public function testGetLocation(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals('DC Super', $vendor->getLocation($snmpConnection)); } @@ -68,7 +68,7 @@ public function testGetSerialNumber(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals('ES32001131', $vendor->getSerialNumber($snmpConnection)); } @@ -76,7 +76,7 @@ public function testGetLicenseLevel(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); + $vendor = new Eltex(); $this->assertEquals(null, $vendor->getLicenseLevel($snmpConnection)); } @@ -84,15 +84,15 @@ public function testGetPlatformType(): void { $snmpConnection = (new SnmpRepository())->startSession($this->setVarsConnection()); - $vendor = new Eltex(); - $model = $vendor->getModel($snmpConnection); + $vendor = new Eltex(); + $model = $vendor->getModel($snmpConnection); $this->assertEquals(0, $vendor->getPlatformType($model)); } private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9004'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9004'; + $array['community'] = 'public'; return $array; } diff --git a/tests/Unit/SNMP/HardwareMikrotikTest.php b/tests/Unit/SNMP/HardwareMikrotikTest.php index 1045f092..eac708e2 100644 --- a/tests/Unit/SNMP/HardwareMikrotikTest.php +++ b/tests/Unit/SNMP/HardwareMikrotikTest.php @@ -91,8 +91,8 @@ public function testGetPlatformType(): void private function setVarsConnection() { - $array['hostname'] = '127.0.0.1:9005'; - $array['snmpCommunity'] = 'public'; + $array['hostname'] = '127.0.0.1:9005'; + $array['community'] = 'public'; return $array; } From 8d04f9ab6ac160d8db34db48b3000a51b933d955 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 13:45:35 +0300 Subject: [PATCH 27/34] Renaming vars. --- app/Console/Commands/SnmpDevicesChecker.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/SnmpDevicesChecker.php b/app/Console/Commands/SnmpDevicesChecker.php index 80c6177e..72b82a03 100644 --- a/app/Console/Commands/SnmpDevicesChecker.php +++ b/app/Console/Commands/SnmpDevicesChecker.php @@ -55,12 +55,12 @@ public function handle(int $device_id = null) foreach ($devices as $device) { try { - $deviceConnection['hostname'] = $device->hostname; - $deviceConnection['title'] = $device->title; - $deviceConnection['snmpCommunity'] = $device->snmp_community; - $deviceConnection['snmpPort'] = $device->snmp_port; - $deviceConnection['snmpVersion'] = $device->snmp_version; - $deviceData = $this->devicesRepository->getDeviceData($deviceConnection); + $deviceConnection['hostname'] = $device->hostname; + $deviceConnection['title'] = $device->title; + $deviceConnection['community'] = $device->snmp_community; + $deviceConnection['port'] = $device->snmp_port; + $deviceConnection['snmpVersion'] = $device->snmp_version; + $deviceData = $this->devicesRepository->getDeviceData($deviceConnection); $this->devicesRepository->update($deviceData, $device->id); } catch (\Exception $exception) { if ($this->settingsController->getTelegramStatus() === 1) { From 9e3292a9e68fccc8cc675691cd8b2ada069cd9d3 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 13:45:49 +0300 Subject: [PATCH 28/34] Renaming vars. --- .../Devices/DevicesRepository.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Repositories/Devices/DevicesRepository.php b/app/Repositories/Devices/DevicesRepository.php index a145a8d8..4f18badc 100644 --- a/app/Repositories/Devices/DevicesRepository.php +++ b/app/Repositories/Devices/DevicesRepository.php @@ -123,11 +123,11 @@ public function setDataConnection($request): array $deviceData = []; // Getting vars from template - $deviceData['hostname'] = $request->input('hostname'); // Hostname device - $deviceData['title'] = $request->input('title'); // Short description - $deviceData['snmpCommunity'] = $request->input('snmp_community'); // Device community - $deviceData['snmpPort'] = $request->input('snmp_port'); // Device snmp port - $deviceData['snmpVersion'] = $request->input('snmp_version'); // Device snmp version 1/2/3 + $deviceData['hostname'] = $request->input('hostname'); // Hostname device + $deviceData['title'] = $request->input('title'); // Short description + $deviceData['community'] = $request->input('snmp_community'); // Device community + $deviceData['port'] = $request->input('snmp_port'); // Device snmp port + $deviceData['snmpVersion'] = $request->input('snmp_version'); // Device snmp version 1/2/3 return (array) $deviceData; } @@ -158,11 +158,11 @@ public function getDeviceData(array $varsConnection): array $device = $vendor->getVendorClass($vendorName); //Set vars - $deviceData['hostname'] = $varsConnection['hostname']; - $deviceData['title'] = $varsConnection['title']; - $deviceData['snmpCommunity'] = $varsConnection['snmpCommunity']; - $deviceData['snmpPort'] = $varsConnection['snmpPort']; - $deviceData['snmpVersion'] = $varsConnection['snmpVersion']; + $deviceData['hostname'] = $varsConnection['hostname']; + $deviceData['title'] = $varsConnection['title']; + $deviceData['community'] = $varsConnection['community']; + $deviceData['port'] = $varsConnection['port']; + $deviceData['snmpVersion'] = $varsConnection['snmpVersion']; // Get & set vars from device $deviceData['location'] = $device->getLocation($snmpFlow); @@ -210,8 +210,8 @@ public function store(array $deviceData, $deviceId = null): void $device->serial_number = $deviceData['serialNumber']; $device->packets_version = $deviceData['packetsVersion']; $device->platform_type = $deviceData['platformType']; - $device->snmp_port = $deviceData['snmpPort']; - $device->snmp_community = $deviceData['snmpCommunity']; + $device->snmp_port = $deviceData['port']; + $device->snmp_community = $deviceData['community']; $device->snmp_version = $deviceData['snmpVersion']; $device->save(); } From fbcd76b510d3d376a6b9c9e31f462049856e2498 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 13:46:11 +0300 Subject: [PATCH 29/34] New build 022. --- config/moring.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/moring.php b/config/moring.php index 5232d2fa..23a09c5c 100644 --- a/config/moring.php +++ b/config/moring.php @@ -1,7 +1,7 @@ '021', + 'build' => '022', 'version' => '0.1.3', 'createYear' => '2019', 'bridgeUrl' => 'http://api.moring.ru/v1', From 44aee03d306daca5323a8bc1dd769218500e9a35 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 14:18:59 +0300 Subject: [PATCH 30/34] Added snmp port. --- tests/Unit/SNMP/CiscoTest.php | 1 + tests/Unit/SNMP/CloudMikrotikExceptionTest.php | 1 + tests/Unit/SNMP/CloudMikrotikTest.php | 1 + tests/Unit/SNMP/DLinkTest.php | 1 + tests/Unit/SNMP/EltexTest.php | 1 + tests/Unit/SNMP/HardwareMikrotikTest.php | 1 + tests/Unit/SNMP_Vendors/CiscoTest.php | 1 + tests/Unit/SNMP_Vendors/CloudMikrotikTest.php | 1 + tests/Unit/SNMP_Vendors/DLinkTest.php | 1 + tests/Unit/SNMP_Vendors/EltexTest.php | 1 + tests/Unit/SNMP_Vendors/EmptyVendorTest.php | 1 + tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php | 1 + 12 files changed, 12 insertions(+) diff --git a/tests/Unit/SNMP/CiscoTest.php b/tests/Unit/SNMP/CiscoTest.php index a18e7ee3..944ea244 100644 --- a/tests/Unit/SNMP/CiscoTest.php +++ b/tests/Unit/SNMP/CiscoTest.php @@ -93,6 +93,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9002'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP/CloudMikrotikExceptionTest.php b/tests/Unit/SNMP/CloudMikrotikExceptionTest.php index dd351f8e..6ff0cd49 100644 --- a/tests/Unit/SNMP/CloudMikrotikExceptionTest.php +++ b/tests/Unit/SNMP/CloudMikrotikExceptionTest.php @@ -26,6 +26,7 @@ private function setVarsConnection() { $array['hostname'] = '0.0.0.0'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP/CloudMikrotikTest.php b/tests/Unit/SNMP/CloudMikrotikTest.php index 13c15d3b..7b64e5bf 100644 --- a/tests/Unit/SNMP/CloudMikrotikTest.php +++ b/tests/Unit/SNMP/CloudMikrotikTest.php @@ -93,6 +93,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9001'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP/DLinkTest.php b/tests/Unit/SNMP/DLinkTest.php index 85836d6e..6d21962f 100644 --- a/tests/Unit/SNMP/DLinkTest.php +++ b/tests/Unit/SNMP/DLinkTest.php @@ -93,6 +93,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9003'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP/EltexTest.php b/tests/Unit/SNMP/EltexTest.php index 219e3ef4..f301362a 100644 --- a/tests/Unit/SNMP/EltexTest.php +++ b/tests/Unit/SNMP/EltexTest.php @@ -93,6 +93,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9004'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP/HardwareMikrotikTest.php b/tests/Unit/SNMP/HardwareMikrotikTest.php index eac708e2..bbe7aa9e 100644 --- a/tests/Unit/SNMP/HardwareMikrotikTest.php +++ b/tests/Unit/SNMP/HardwareMikrotikTest.php @@ -93,6 +93,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9005'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP_Vendors/CiscoTest.php b/tests/Unit/SNMP_Vendors/CiscoTest.php index c0df0dc8..8edbb6dc 100644 --- a/tests/Unit/SNMP_Vendors/CiscoTest.php +++ b/tests/Unit/SNMP_Vendors/CiscoTest.php @@ -29,6 +29,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9002'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php b/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php index 4f520f82..c04ed484 100644 --- a/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php +++ b/tests/Unit/SNMP_Vendors/CloudMikrotikTest.php @@ -29,6 +29,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9001'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP_Vendors/DLinkTest.php b/tests/Unit/SNMP_Vendors/DLinkTest.php index a6aea2ae..74af0c24 100644 --- a/tests/Unit/SNMP_Vendors/DLinkTest.php +++ b/tests/Unit/SNMP_Vendors/DLinkTest.php @@ -29,6 +29,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9003'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP_Vendors/EltexTest.php b/tests/Unit/SNMP_Vendors/EltexTest.php index 389cb6ba..20a19a71 100644 --- a/tests/Unit/SNMP_Vendors/EltexTest.php +++ b/tests/Unit/SNMP_Vendors/EltexTest.php @@ -29,6 +29,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9004'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP_Vendors/EmptyVendorTest.php b/tests/Unit/SNMP_Vendors/EmptyVendorTest.php index dbeffaa2..503e9e2a 100644 --- a/tests/Unit/SNMP_Vendors/EmptyVendorTest.php +++ b/tests/Unit/SNMP_Vendors/EmptyVendorTest.php @@ -22,6 +22,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9006'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } diff --git a/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php b/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php index aeca8834..82f92b71 100644 --- a/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php +++ b/tests/Unit/SNMP_Vendors/HardwareMikrotikTest.php @@ -29,6 +29,7 @@ private function setVarsConnection() { $array['hostname'] = '127.0.0.1:9005'; $array['community'] = 'public'; + $array['port'] = 161; return $array; } From 0fc7c30adc98b6c9d96fe102cb132228ebe2e951 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 17:17:50 +0300 Subject: [PATCH 31/34] Added check exist device. --- .../Admin/Network/NetworkDevicesController.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/Http/Controllers/Admin/Network/NetworkDevicesController.php b/app/Http/Controllers/Admin/Network/NetworkDevicesController.php index 85984302..c65b10e9 100644 --- a/app/Http/Controllers/Admin/Network/NetworkDevicesController.php +++ b/app/Http/Controllers/Admin/Network/NetworkDevicesController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Admin\Network; +use App\Models\Devices; use App\Http\Controllers\Controller; use App\Http\Requests\Sites\UpdateAndStoreDeviceRequest; use App\Repositories\Devices\DevicesLogsRepository; @@ -107,6 +108,16 @@ public function update(UpdateAndStoreDeviceRequest $request) public function store(UpdateAndStoreDeviceRequest $request): RedirectResponse { try { + $device = Devices::where('hostname', $request->hostname) + ->where('snmp_version', $request->snmp_version) + ->where('snmp_port', $request->snmp_port) + ->where('snmp_community', $request->snmp_community) + ->get(); + + if ($device->isNotEmpty()) { + throw new Exception('Данное устройство уже есть в списке'); + } + $deviceConnection = $this->deviceRepository->setDataConnection($request); $deviceData = $this->deviceRepository->getDeviceData($deviceConnection); $this->deviceRepository->store($deviceData); From d30a267c79669071f325b407f1afcd79cbb1793a Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 17:18:06 +0300 Subject: [PATCH 32/34] New build. --- config/moring.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/moring.php b/config/moring.php index 23a09c5c..3766a697 100644 --- a/config/moring.php +++ b/config/moring.php @@ -1,7 +1,7 @@ '022', + 'build' => '023', 'version' => '0.1.3', 'createYear' => '2019', 'bridgeUrl' => 'http://api.moring.ru/v1', From 03506913d82fe91e808140a11ae4664b6b786b59 Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 17:21:38 +0300 Subject: [PATCH 33/34] Code style fix. --- app/Http/Controllers/Admin/Network/NetworkDevicesController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/Network/NetworkDevicesController.php b/app/Http/Controllers/Admin/Network/NetworkDevicesController.php index c65b10e9..2fdba0a4 100644 --- a/app/Http/Controllers/Admin/Network/NetworkDevicesController.php +++ b/app/Http/Controllers/Admin/Network/NetworkDevicesController.php @@ -2,9 +2,9 @@ namespace App\Http\Controllers\Admin\Network; -use App\Models\Devices; use App\Http\Controllers\Controller; use App\Http\Requests\Sites\UpdateAndStoreDeviceRequest; +use App\Models\Devices; use App\Repositories\Devices\DevicesLogsRepository; use App\Repositories\Devices\DevicesRepository; use App\Repositories\Devices\DevicesVendorsRepository; From b41186ff7608c773bf204be48529c03ac887c64a Mon Sep 17 00:00:00 2001 From: Anton Zheltyshev Date: Fri, 27 Mar 2020 17:36:33 +0300 Subject: [PATCH 34/34] New version 0.1.4 --- CHANGELOG.md | 8 ++++++++ config/moring.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f15b5391..1f8f481a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +[v.0.1.4 (Build.023)](https://github.com/TripleSD/moring/releases/tag/0.1.4) + - **(New)** - Добавлены новые автотесты для SNMP классов + - **(New)** - Добавлена проверка на повторное добавление SNMP устройства + - **(Upd)** - Дополнены текущие автотесты для SNMP классов + - **(Upd)** - Выполнен рефакторинг SNMP классов + - **(Upd)** - Выполнен рефакторинг Device классов + - **(Fix)** - Исправлена передача порта SNMP устройства из формы в обработчик + [v.0.1.3 (Build.020)](https://github.com/TripleSD/moring/releases/tag/0.1.3) - **(Add)** - Добавлен пакет [delimitry/snmp-server](https://github.com/delimitry/snmp-server) для эмуляции snmp устройств - **(Upd)** - Осуществлен рефакторинг SNMP классов для ускоения запроса и получения SNMP информации diff --git a/config/moring.php b/config/moring.php index 3766a697..16b616e6 100644 --- a/config/moring.php +++ b/config/moring.php @@ -2,7 +2,7 @@ return [ 'build' => '023', - 'version' => '0.1.3', + 'version' => '0.1.4', 'createYear' => '2019', 'bridgeUrl' => 'http://api.moring.ru/v1', 'bridgeCurrentMoringVersionUrl' => '/moring/version',