From 963f444f171df65f85f00698a201a78fa095b42f Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Tue, 18 Apr 2017 16:28:48 -0500 Subject: [PATCH] fix: Allow line returns in snmprec files with the 4x data type (#6443) * fix: Allow line returns in snmprec files with the 4x data type Fill in IOS data files IOS-XE discovery fails, fix that * Restore IOS-XE, unsure if it can be removed --- doc/Developing/Support-New-OS.md | 3 +++ includes/definitions/iosxe.yaml | 2 +- tests/OSDiscoveryTest.php | 3 ++- tests/mocks/mock.snmp.inc.php | 6 ++++-- tests/snmpsim/ios-c3825.snmprec | 3 ++- tests/snmpsim/ios.snmprec | 2 +- tests/snmpsim/ios1.snmprec | 4 ++-- tests/snmpsim/iosxe-asr1000.snmprec | 3 ++- tests/snmpsim/iosxe.snmprec | 3 ++- tests/snmpsim/iosxr.snmprec | 2 +- 10 files changed, 20 insertions(+), 11 deletions(-) diff --git a/doc/Developing/Support-New-OS.md b/doc/Developing/Support-New-OS.md index 47415c3668..855da124eb 100644 --- a/doc/Developing/Support-New-OS.md +++ b/doc/Developing/Support-New-OS.md @@ -524,6 +524,7 @@ List of SNMP data types: | Type | Value | | ----------------- | ------------- | | OCTET STRING | 4 | +| HEX STRING | 4x | | Integer32 | 2 | | NULL | 5 | | OBJECT IDENTIFIER | 6 | @@ -534,5 +535,7 @@ List of SNMP data types: | Opaque | 68 | | Counter64 | 70 | +Hex encoded strings (4x) should be used for any strings that contain line returns + You can run `./scripts/pre-commit.php -u` to run the unit tests to check your code. If you would like to run tests locally against a full snmpsim instance, run `./scripts/pre-commit.php -u --snmpsim`. diff --git a/includes/definitions/iosxe.yaml b/includes/definitions/iosxe.yaml index 541f102ab3..753d1c4b3f 100644 --- a/includes/definitions/iosxe.yaml +++ b/includes/definitions/iosxe.yaml @@ -35,4 +35,4 @@ register_mibs: discovery: - sysDescr: - IOS-XE - - X86_64_LINUX_IOSD + - LINUX_IOSD diff --git a/tests/OSDiscoveryTest.php b/tests/OSDiscoveryTest.php index 65416ed729..32ef5880aa 100644 --- a/tests/OSDiscoveryTest.php +++ b/tests/OSDiscoveryTest.php @@ -37,7 +37,8 @@ class DiscoveryTest extends \PHPUnit_Framework_TestCase private function checkOS($expected_os, $filename = null) { $community = $filename ?: $expected_os; - + global $debug; + $debug = true; ob_start(); $os = getHostOS($this->genDevice($community)); $output = ob_get_contents(); diff --git a/tests/mocks/mock.snmp.inc.php b/tests/mocks/mock.snmp.inc.php index 1079d5039a..449ec6594e 100644 --- a/tests/mocks/mock.snmp.inc.php +++ b/tests/mocks/mock.snmp.inc.php @@ -43,10 +43,12 @@ function cache_snmprec($file) $line = strtok($data, "\r\n"); while ($line !== false) { list($oid, $type, $data) = explode('|', $line, 3); - if ($type == 4) { + if ($type == '4') { $data = trim($data); - } elseif ($type == 6) { + } elseif ($type == '6') { $data = trim($data, '.'); + } elseif ($type == '4x') { + $data = hex2str($data); } $snmpMockCache[$file][$oid] = array($type, $data); diff --git a/tests/snmpsim/ios-c3825.snmprec b/tests/snmpsim/ios-c3825.snmprec index c53961dd77..bf2428987e 100644 --- a/tests/snmpsim/ios-c3825.snmprec +++ b/tests/snmpsim/ios-c3825.snmprec @@ -1 +1,2 @@ -1.3.6.1.2.1.1.1.0|4|Cisco IOS Software, 3800 Software (C3825-ADVIPSERVICESK9-M), Version 12.4(22)T5, RELEASE SOFTWARE (fc3) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by Cisco Systems, Inc. Compiled Wed 28-Apr-10 11:30 by prod_rel_team +1.3.6.1.2.1.1.1.0|4x|436973636f20494f5320536f6674776172652c203338303020536f667477617265202843333832352d414456495053455256494345534b392d4d292c2056657273696f6e2031352e312834294d31302c2052454c4541534520534f4654574152452028666332290d0a546563686e6963616c20537570706f72743a20687474703a2f2f7777772e636973636f2e636f6d2f74656368737570706f72740d0a436f707972696768742028632920313938362d3230313520627920436973636f2053797374656d732c20496e632e0d0a436f6d70696c6564205475652032342d4d61722d31352030393a35302062792070726f645f72656c5f7465616d +1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.9.1.543 diff --git a/tests/snmpsim/ios.snmprec b/tests/snmpsim/ios.snmprec index f6015af2df..15f84889c2 100644 --- a/tests/snmpsim/ios.snmprec +++ b/tests/snmpsim/ios.snmprec @@ -1,2 +1,2 @@ -1.3.6.1.2.1.1.1.0|4|Cisco Internetwork Operating System Software IOS (tm) C2950 Software (C2950-I6K2L2Q4-M), Version 12.1(22)EA14, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by cisco Systems, Inc. Compiled Tue 26-O +1.3.6.1.2.1.1.1.0|4x|436973636f20496e7465726e6574776f726b204f7065726174696e672053797374656d20536f667477617265200d0a494f532028746d2920433239353020536f667477617265202843323935302d49364b324c3251342d4d292c2056657273696f6e2031322e3128323229454131342c2052454c4541534520534f4654574152452028666331290d0a546563686e6963616c20537570706f72743a20687474703a2f2f7777772e636973636f2e636f6d2f74656368737570706f72740d0a436f707972696768742028632920313938362d3230313020627920636973636f2053797374656d732c20496e632e0d0a436f6d70696c6564205475652032362d4f 1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.9.1.359 diff --git a/tests/snmpsim/ios1.snmprec b/tests/snmpsim/ios1.snmprec index d4f0942375..4b7f0cf93f 100644 --- a/tests/snmpsim/ios1.snmprec +++ b/tests/snmpsim/ios1.snmprec @@ -1,2 +1,2 @@ -1.3.6.1.2.1.1.1.0|4|Cisco Internetwork Operating System Software IOS (tm) C2950 Software (C2950-I6K2L2Q4-M), Version 12.1(22)EA14, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2010 by cisco Systems, Inc. Compiled Tue 26-O -1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.9.1.429 +1.3.6.1.2.1.1.1.0|4x|436973636f20494f5320536f6674776172652c20433337353020536f667477617265202843333735302d4950424153452d4d292c2056657273696f6e2031322e32283530295345332c2052454c4541534520534f4654574152452028666331290d0a546563686e6963616c20537570706f72743a20687474703a2f2f7777772e636973636f2e636f6d2f74656368737570706f72740d0a436f707972696768742028632920313938362d3230303920627920436973636f2053797374656d732c20496e632e0d0a436f6d70696c6564205765642032322d4a756c2d30392030363a31392062792070726f645f72656c5f7465616d +1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.9.1.516 diff --git a/tests/snmpsim/iosxe-asr1000.snmprec b/tests/snmpsim/iosxe-asr1000.snmprec index 14743268eb..eb67f0f857 100644 --- a/tests/snmpsim/iosxe-asr1000.snmprec +++ b/tests/snmpsim/iosxe-asr1000.snmprec @@ -1 +1,2 @@ -1.3.6.1.2.1.1.1.0|4|Cisco IOS Software, ASR1000 Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 15.5(3)S, RELEASE SOFTWARE (fc6) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2013 by Cisco Systems, Inc. Compiled Thu 01-Aug-13 03:38 by mcpre +1.3.6.1.2.1.1.1.0|4x|436973636f20494f5320536f6674776172652c2049535220536f66747761726520285838365f36345f4c494e55585f494f53442d554e4956455253414c4b392d4d292c2056657273696f6e2031352e3428332953322c2052454c4541534520534f4654574152452028666333290d0a546563686e6963616c20537570706f72743a20687474703a2f2f7777772e636973636f2e636f6d2f74656368737570706f72740d0a436f707972696768742028632920313938362d3230313520627920436973636f2053797374656d732c20496e632e0d0a436f6d70696c6564204672692033302d4a616e2d31352031353a3139206279206d63707265 +1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.9.1.2093 diff --git a/tests/snmpsim/iosxe.snmprec b/tests/snmpsim/iosxe.snmprec index fd07471533..f7193ad1dc 100644 --- a/tests/snmpsim/iosxe.snmprec +++ b/tests/snmpsim/iosxe.snmprec @@ -1 +1,2 @@ -1.3.6.1.2.1.1.1.0|4|Cisco IOS Software, IOS-XE Software (PPC_LINUX_IOSD-ADVENTERPRISEK9-M), Version 15.1(3)S, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2011 by Cisco Systems, Inc. Compiled Thu 21-Jul-11 21:59 by mcpre +1.3.6.1.2.1.1.1.0|4x|436973636f20494f5320536f6674776172652c204153523130303020536f66747761726520285050435f4c494e55585f494f53442d414456454e54455250524953454b392d4d292c2056657273696f6e2031352e352833295331612c2052454c4541534520534f4654574152452028666331290d0a546563686e6963616c20537570706f72743a20687474703a2f2f7777772e636973636f2e636f6d2f74656368737570706f72740d0a436f707972696768742028632920313938362d3230313520627920436973636f2053797374656d732c20496e632e0d0a436f6d70696c6564205765642030342d4e6f762d31352031373a3430206279206d63707265 +1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.9.1.1116 diff --git a/tests/snmpsim/iosxr.snmprec b/tests/snmpsim/iosxr.snmprec index 13808f7886..7f569dc01f 100644 --- a/tests/snmpsim/iosxr.snmprec +++ b/tests/snmpsim/iosxr.snmprec @@ -1,2 +1,2 @@ -1.3.6.1.2.1.1.1.0|4|Cisco IOS XR Software (Cisco ASR9K Series), Version 5.3.4[Default] Copyright (c) 2016 by Cisco Systems, Inc. +1.3.6.1.2.1.1.1.0|4x|436973636f20494f5320585220536f6674776172652028436973636f20415352394b20536572696573292c202056657273696f6e20352e332e345b44656661756c745d0d0a436f7079726967687420286329203230313720627920436973636f2053797374656d732c20496e632e 1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.9.1.1018