diff --git a/.gitignore b/.gitignore index 7648488..814e49c 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ dist/ htmlcov/ migrations/ test_result.txt +.python-version diff --git a/.travis.yml b/.travis.yml index 3e70880..23f85b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,9 @@ language: python sudo: false env: -- TOXENV=py27 -- TOXENV=py36 +- TOXENV=py38 +- TOXENV=py39 +- TOXENV=py310 install: - pip install virtualenv tox docutils coveralls diff --git a/README.rst b/README.rst index 5fe40e9..a1134b1 100644 --- a/README.rst +++ b/README.rst @@ -17,17 +17,17 @@ If you have any need to handle the equipment that this module does not support, then please send the sysDescr value to this package author. Or, please contact using function of the such as github pull request. -.. image:: https://secure.travis-ci.org/mtoshi/sysdescrparser.svg?branch=master - :target: http://travis-ci.org/mtoshi/sysdescrparser -.. image:: https://coveralls.io/repos/mtoshi/sysdescrparser/badge.svg?branch=master - :target: https://coveralls.io/r/mtoshi/sysdescrparser?branch=master +.. image:: https://secure.travis-ci.org/rlaneyjr/sysdescrparser.svg?branch=master + :target: http://travis-ci.org/rlaneyjr/sysdescrparser +.. image:: https://coveralls.io/repos/rlaneyjr/sysdescrparser/badge.svg?branch=master + :target: https://coveralls.io/r/rlaneyjr/sysdescrparser?branch=master .. image:: https://img.shields.io/pypi/v/sysdescrparser.svg :target: https://pypi.python.org/pypi/sysdescrparser/ :alt: Latest Version Requirements ------------- -* Python2.7, 3.5, 3.6, 3.7, PyPy. +* Python3.8, 3.9, 3.10, PyPy. Instration ----------- @@ -37,7 +37,7 @@ Instration or - $ git clone https://github.com/mtoshi/sysdescrparser + $ git clone https://github.com/rlaneyjr/sysdescrparser $ cd sysdescrparser $ sudo python setup.py install @@ -88,7 +88,7 @@ Parsing logic and Support Vendor and OS ---------------------------------------- * About parsing logic and support of vendor and os. Of course you are able to see this python code and also see how it works easily from sample data. - https://github.com/mtoshi/sysdescrparser/blob/master/samples/sample_data.json + https://github.com/rlaneyjr/sysdescrparser/blob/master/samples/sample_data.json It will be able to understand almost. (Sometimes, using hard code. And also using UNKNOWN values.) This sample data is also used directly by code test. diff --git a/samples/sample.py b/samples/sample.py index e4087fd..515c116 100644 --- a/samples/sample.py +++ b/samples/sample.py @@ -4,7 +4,7 @@ import os import json -from sysdescrparser import sysdescrparser +from sysdescrparser.sysdescrparser import sysdescrparser def main(): diff --git a/samples/sample_data.json b/samples/sample_data.json index e8dfba7..24e9325 100644 --- a/samples/sample_data.json +++ b/samples/sample_data.json @@ -39,6 +39,46 @@ "version": "12.2(50)SG3" }, + { + "raw": "Cisco IOS Software [Everest], Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Experimental Version 16.4.20170410:165034 [v164_throttle-BLD-BLD_V164_THROTTLE_LATEST_20170410_174845 105]", + "vendor": "CISCO", + "os": "IOSXE", + "model": "CAT3K_CAA-UNIVERSALK9-M", + "version": "16.4.20170410:165034" + }, + + { + "raw": "Cisco IOS XE Software, Version 16.06.05 Cisco IOS Software [Everest], ISR Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.6.5, RELEASE SOFTWARE (fc3)", + "vendor": "CISCO", + "os": "IOSXE", + "model": "X86_64_LINUX_IOSD-UNIVERSALK9-M", + "version": "16.06.05" + }, + + { + "raw": "Cisco IOS Software, IOS-XE Software, Catalyst 4500 L3 Switch Software (cat4500e-UNIVERSALK9-M), Version 03.03.02.SG RELEASE SOFTWARE (fc1)", + "vendor": "CISCO", + "os": "IOSXE", + "model": "cat4500e-UNIVERSALK9-M", + "version": "03.03.02.SG" + }, + + { + "raw": "Cisco IOS Software [Denali], Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 16.3.1a, RELEASE SOFTWARE (fc4)", + "vendor": "CISCO", + "os": "IOSXE", + "model": "CAT3K_CAA-UNIVERSALK9-M", + "version": "16.3.1a" + }, + + { + "raw": "Cisco IOS Software [Fuji], ASR1000 Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 16.7.1prd4, RELEASE SOFTWARE (fc1)", + "vendor": "CISCO", + "os": "IOSXE", + "model": "X86_64_LINUX_IOSD-UNIVERSALK9-M", + "version": "16.7.1prd4" + }, + { "raw": "Cisco NX-OS(tm) cgr1000, Software (cgr1000-uk9), Version 5.2(1)CG2(1), Interim version 5.2(1)CG2(0.167), RELEASE SOFTWARE Copyright (c) 2002-2011 by Cisco Systems, Inc. Compiled 1/1/2012 1:00:00", "vendor": "CISCO", @@ -95,6 +135,38 @@ "version": "3.6.0[00]" }, + { + "raw": "RouterOS 6.43.4 (stable) on RB750", + "vendor": "MikroTik", + "os": "RouterOS", + "model": "RB750", + "version": "6.43.4" + }, + + { + "raw": "RouterOS 6.43.4 (stable) on RB951-2n", + "vendor": "MikroTik", + "os": "RouterOS", + "model": "RB951-2n", + "version": "6.43.4" + }, + + { + "raw": "RouterOS 6.47 (stable) on CCR1036-12G-4S", + "vendor": "MikroTik", + "os": "RouterOS", + "model": "CCR1036-12G-4S", + "version": "6.47" + }, + + { + "raw": "RouterOS 6.44.5 (long-term) on CCR1036-12G-4S", + "vendor": "MikroTik", + "os": "RouterOS", + "model": "CCR1036-12G-4S", + "version": "6.44.5" + }, + { "raw": "Juniper Networks, Inc. ex2200-24t-4g internet router, kernel JUNOS 10.2R1.8 #0: 2010-05-27 20:13:49 UTC", "vendor": "JUNIPER", @@ -593,34 +665,58 @@ { "raw": "Linux HOSTNAME 3.2.0-4-amd64 #1 SMP Debian 3.2.65-1+deb7u1", - "vendor": "UNKNOWN", - "os": "LINUX", + "vendor": "LINUX", + "os": "LINUX_KERNEL", "model": "UNKNOWN", "version": "3.2.0-4-amd64" }, { "raw": "Linux HOSTNAME 2.6.32-358.6.2.el6.x86_64 #1 SMP Thu May 16 20:59:36 UTC 2013 x86_64", - "vendor": "UNKNOWN", - "os": "LINUX", - "model": "UNKNOWN", - "version": "2.6.32-358.6.2.el6.x86_64" + "vendor": "CENTOS", + "os": "CENTOS", + "model": "2.6.32-358.6.2.el6.x86_64", + "version": "6.0" }, { "raw": "Linux HOSTNAME 2.6.21-1.3194.fc7 #1 SMP Wed May 23 22:35:01 EDT 2007 i686", - "vendor": "UNKNOWN", - "os": "LINUX", + "vendor": "LINUX", + "os": "LINUX_KERNEL", "model": "UNKNOWN", "version": "2.6.21-1.3194.fc7" }, { "raw": "Linux hostname 3.2.0-56-generic-pae #86-Ubuntu SMP Wed Oct 23 17:51:27 UTC 2013 i686", - "vendor": "UNKNOWN", - "os": "LINUX", - "model": "UNKNOWN", - "version": "3.2.0-56-generic-pae" + "vendor": "CANONICAL", + "os": "UBUNTU_LINUX", + "model": "3.2.0-56-generic-pae", + "version": "UNKNOWN" + }, + + { + "raw": "Linux ubuntu-bionic 4.15.0-70-generic #79-Ubuntu SMP Tue Nov 12 10:36:11 UTC 2019 x86_64", + "vendor": "CANONICAL", + "os": "UBUNTU_LINUX", + "model": "4.15.0-70-generic", + "version": "18.04" + }, + + { + "raw": "Linux ubuntu-xenial 4.4.0-169-generic #198-Ubuntu SMP Tue Nov 12 10:38:00 UTC 2019 x86_64", + "vendor": "CANONICAL", + "os": "UBUNTU_LINUX", + "model": "4.4.0-169-generic", + "version": "16.04" + }, + + { + "raw": "Linux vagrant-ubuntu-trusty-64 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64", + "vendor": "CANONICAL", + "os": "UBUNTU_LINUX", + "model": "3.13.0-170-generic", + "version": "14.04" }, { @@ -791,6 +887,30 @@ "version": "Rev.8.03.92" }, + { + "raw": "ArubaOS (MODEL: 515), Version 8.6.0.4-8.6.0.4", + "vendor": "ARUBA", + "os": "ArubaOS", + "model": "515", + "version": "8.6.0.4-8.6.0.4" + }, + + { + "raw": "ArubaOS (MODEL: Aruba7010), Version 8.3.0.0 (64659)", + "vendor": "ARUBA", + "os": "ArubaOS", + "model": "7010", + "version": "8.3.0.0 (64659)" + }, + + { + "raw": "ArubaOS (MODEL: Aruba7210), Version 6.5.1.6 (60228)", + "vendor": "ARUBA", + "os": "ArubaOS", + "model": "7210", + "version": "6.5.1.6 (60228)" + }, + { "raw": "xxxxxxxxxxxxxxx", "vendor": "UNKNOWN", diff --git a/setup.py b/setup.py index df7089f..c962150 100644 --- a/setup.py +++ b/setup.py @@ -40,13 +40,10 @@ def run_tests(self): classifiers = [ "Development Status :: 3 - Alpha", "Programming Language :: Python", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.3", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: System :: Networking", @@ -65,17 +62,17 @@ def run_tests(self): EXCLUDE_FROM_PACKAGES = ['tests'] setup( - name="sysdescrparser", - version="0.1.6", - description='SNMP sysDescr parser.', + name="snmpsysdescrparser", + version="0.1.22", + description='SNMP sysDescr parser fork for Windows Support', long_description=README, - author='Toshikatsu Murakoshi', - author_email='mtoshi.g@gmail.com', - url='https://github.com/mtoshi/sysdescrparser', + author='Yazdan', + author_email='yzdannn@gmail.com', + url='https://github.com/rlaneyjr/sysdescrparser', license='MIT', classifiers=classifiers, packages=find_packages(exclude=EXCLUDE_FROM_PACKAGES), - py_modules=['sysdescrparser'], + py_modules=['snmpsysdescrparser'], data_files=[], install_requires=requires, include_package_data=True, diff --git a/sysdescrparser/__init__.py b/sysdescrparser/__init__.py index 27067a4..9544d8b 100644 --- a/sysdescrparser/__init__.py +++ b/sysdescrparser/__init__.py @@ -2,10 +2,4 @@ """Sysdescrparser.""" -import sys - -# pylint: disable=unused-import -if sys.version_info.major == 2: - from sysdescrparser import sysdescrparser -else: - from sysdescrparser.sysdescrparser import sysdescrparser +# Removed lifting to force full path use diff --git a/sysdescrparser/a10.py b/sysdescrparser/a10.py index 3a2805e..66a8905 100644 --- a/sysdescrparser/a10.py +++ b/sysdescrparser/a10.py @@ -2,7 +2,7 @@ """sysdescrparser.a10.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/a10_acos.py b/sysdescrparser/a10_acos.py index 22c3f00..59850ef 100644 --- a/sysdescrparser/a10_acos.py +++ b/sysdescrparser/a10_acos.py @@ -4,7 +4,7 @@ import re -from a10 import A10 +from sysdescrparser.a10 import A10 # pylint: disable=no-member diff --git a/sysdescrparser/arista.py b/sysdescrparser/arista.py index 74a9998..ebd7532 100644 --- a/sysdescrparser/arista.py +++ b/sysdescrparser/arista.py @@ -2,7 +2,7 @@ """sysdescrparser.arista.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/arista_eos.py b/sysdescrparser/arista_eos.py index ba726b6..58434c0 100644 --- a/sysdescrparser/arista_eos.py +++ b/sysdescrparser/arista_eos.py @@ -4,7 +4,7 @@ import re -from arista import Arista +from sysdescrparser.arista import Arista # pylint: disable=no-member diff --git a/sysdescrparser/aruba.py b/sysdescrparser/aruba.py new file mode 100644 index 0000000..a279df9 --- /dev/null +++ b/sysdescrparser/aruba.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- + +"""sysdescrparser.aruba.""" + +import re +from sysdescrparser.sysdescr import SysDescr + + +# pylint: disable=no-name-in-module +# pylint: disable=no-member +class Aruba(SysDescr): + + """Class Aruba. + + This class is only for vendor definition. + + """ + + def __init__(self, raw): + """Constructor.""" + super(Aruba, self).__init__(raw) + self.vendor = 'ARUBA' + self.model = self.UNKNOWN + self.os = 'ArubaOS' + self.version = self.UNKNOWN + + def parse(self): + """Parsing for sysDescr value.""" + regex = (r'ArubaOS' + r'.* \(MODEL: (?:Aruba)?(.*)\), Version (.*)') + pat = re.compile(regex) + res = pat.search(self.raw) + if res: + self.model = res.group(1) + self.version = res.group(2) + return self + + return False diff --git a/sysdescrparser/brocade.py b/sysdescrparser/brocade.py index dd536b8..65bc637 100644 --- a/sysdescrparser/brocade.py +++ b/sysdescrparser/brocade.py @@ -2,7 +2,7 @@ """sysdescrparser.brocade.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/brocade_ironware.py b/sysdescrparser/brocade_ironware.py index d13f637..814a852 100644 --- a/sysdescrparser/brocade_ironware.py +++ b/sysdescrparser/brocade_ironware.py @@ -4,7 +4,7 @@ import re -from brocade import Brocade +from sysdescrparser.brocade import Brocade # pylint: disable=no-member diff --git a/sysdescrparser/brocade_networkos.py b/sysdescrparser/brocade_networkos.py index 5a6a7f2..e9b1f55 100644 --- a/sysdescrparser/brocade_networkos.py +++ b/sysdescrparser/brocade_networkos.py @@ -4,7 +4,7 @@ import re -from brocade import Brocade +from sysdescrparser.brocade import Brocade # pylint: disable=no-member diff --git a/sysdescrparser/brocade_serveriron.py b/sysdescrparser/brocade_serveriron.py index 1960aea..4a949a5 100644 --- a/sysdescrparser/brocade_serveriron.py +++ b/sysdescrparser/brocade_serveriron.py @@ -4,7 +4,7 @@ import re -from brocade import Brocade +from sysdescrparser.brocade import Brocade # pylint: disable=no-member diff --git a/sysdescrparser/cisco.py b/sysdescrparser/cisco.py index e40ed3c..3d5d836 100644 --- a/sysdescrparser/cisco.py +++ b/sysdescrparser/cisco.py @@ -2,7 +2,7 @@ """sysdescrparser.cisco.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/cisco_asa.py b/sysdescrparser/cisco_asa.py new file mode 100644 index 0000000..1fa09d3 --- /dev/null +++ b/sysdescrparser/cisco_asa.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +"""sysdescrparser.cisco_iosxe.""" + +import re +from sysdescrparser.cisco import Cisco + + +# pylint: disable=no-member +class CiscoASA(Cisco): + """Class CiscoASA. + + SNMP sysDescr for CiscoASA. + + """ + + def __init__(self, raw): + """Constructor.""" + super(CiscoASA, self).__init__(raw) + self.os = 'Adaptive_Security_Appliance' + self.model = self.UNKNOWN + self.version = self.UNKNOWN + + def parse(self): + """Parse.""" + regex = (r'Cisco Adaptive Security Appliance ' + r'Version (\d.*)') + pat = re.compile(regex) + res = pat.search(self.raw) + if res: + self.version = res.group(1) + return self + + return False + + + diff --git a/sysdescrparser/cisco_ios.py b/sysdescrparser/cisco_ios.py index a6172a2..559cb05 100644 --- a/sysdescrparser/cisco_ios.py +++ b/sysdescrparser/cisco_ios.py @@ -4,7 +4,7 @@ import re -from cisco import Cisco +from sysdescrparser.cisco import Cisco # pylint: disable=no-member diff --git a/sysdescrparser/cisco_iosxe.py b/sysdescrparser/cisco_iosxe.py new file mode 100644 index 0000000..ac680b6 --- /dev/null +++ b/sysdescrparser/cisco_iosxe.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +"""sysdescrparser.cisco_iosxe.""" + + +import re +from sysdescrparser.cisco import Cisco + + +# pylint: disable=no-member +class CiscoIOSXE(Cisco): + + """Class CiscoIOSXE. + + SNMP sysDescr for CiscoIOSXE. + + """ + + def __init__(self, raw): + """Constructor.""" + super(CiscoIOSXE, self).__init__(raw) + self.os = 'IOSXE' + self.model = self.UNKNOWN + self.version = self.UNKNOWN + + def parse(self): + """Parse.""" + main_version_name = "ios-xe" + + misc_version_names = ["gibraltar", "fuji", "everest", "denali", ] + misc_version_names_regex = "|".join( + rf"\[{version_name}\]" + for version_name in misc_version_names + ) + + ios_xe_regex = f"{main_version_name}|{misc_version_names_regex}" + + ios_xe = re.search( + ios_xe_regex, self.raw, flags=re.IGNORECASE + ) + if not ios_xe: + return False + + version_regex = r"version\s+(?P[^\s,]+)" + catched_version = re.search( + version_regex, self.raw, flags=re.IGNORECASE + ) + if catched_version: + version = catched_version.groupdict()['version'] + self.version = version + + model_regex = r"software\s+\((?P.*)\)," + catched_model = re.search(model_regex, self.raw, flags=re.IGNORECASE) + if catched_model: + model = catched_model.groupdict()['model'] + self.model = model + + return self diff --git a/sysdescrparser/cisco_iosxr.py b/sysdescrparser/cisco_iosxr.py index e28c0f6..0387de5 100644 --- a/sysdescrparser/cisco_iosxr.py +++ b/sysdescrparser/cisco_iosxr.py @@ -4,7 +4,7 @@ import re -from cisco import Cisco +from sysdescrparser.cisco import Cisco # pylint: disable=no-member diff --git a/sysdescrparser/cisco_nxos.py b/sysdescrparser/cisco_nxos.py index 64181c7..fb7f397 100644 --- a/sysdescrparser/cisco_nxos.py +++ b/sysdescrparser/cisco_nxos.py @@ -4,7 +4,7 @@ import re -from cisco import Cisco +from sysdescrparser.cisco import Cisco # pylint: disable=no-member diff --git a/sysdescrparser/citrix.py b/sysdescrparser/citrix.py index 8abe3e1..8dcc04a 100644 --- a/sysdescrparser/citrix.py +++ b/sysdescrparser/citrix.py @@ -2,7 +2,7 @@ """sysdescrparser.citrix.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/citrix_netscaler.py b/sysdescrparser/citrix_netscaler.py index 5548e80..f302145 100644 --- a/sysdescrparser/citrix_netscaler.py +++ b/sysdescrparser/citrix_netscaler.py @@ -4,7 +4,7 @@ import re -from citrix import Citrix +from sysdescrparser.citrix import Citrix # pylint: disable=no-member diff --git a/sysdescrparser/extreme.py b/sysdescrparser/extreme.py index efec554..d280bf1 100644 --- a/sysdescrparser/extreme.py +++ b/sysdescrparser/extreme.py @@ -2,7 +2,7 @@ """sysdescrparser.extreme.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/extreme_xos.py b/sysdescrparser/extreme_xos.py index b4b083b..83971aa 100644 --- a/sysdescrparser/extreme_xos.py +++ b/sysdescrparser/extreme_xos.py @@ -4,7 +4,7 @@ import re -from extreme import Extreme +from sysdescrparser.extreme import Extreme # pylint: disable=no-member diff --git a/sysdescrparser/fortinet.py b/sysdescrparser/fortinet.py new file mode 100644 index 0000000..b7cfb93 --- /dev/null +++ b/sysdescrparser/fortinet.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +"""sysdescrparser.FortiNet.""" + +from sysdescrparser.sysdescr import SysDescr + + +# pylint: disable=no-name-in-module +class FortiNet(SysDescr): + + """Class FortiNet. + + This class is only for vendor definition. + + """ + + def __init__(self, raw): + """Constructor.""" + super(FortiNet, self).__init__(raw) + self.vendor = 'fortinet' + self.model = self.UNKNOWN + self.os = self.UNKNOWN + self.version = self.UNKNOWN + + def parse(self): + """Parsing for sysDescr value.""" + return self diff --git a/sysdescrparser/fortinet_fortios.py b/sysdescrparser/fortinet_fortios.py new file mode 100644 index 0000000..3ecd89c --- /dev/null +++ b/sysdescrparser/fortinet_fortios.py @@ -0,0 +1,29 @@ +import re +from sysdescrparser.fortinet import FortiNet + + +class FortiOs(FortiNet): + """Class FortiOs. + + SNMP sysDescr for fortigate. + + """ + + def __init__(self, raw): + """Constructor.""" + super(FortiOs, self).__init__(raw) + self.os = 'fortios' + self.model = self.UNKNOWN + self.version = self.UNKNOWN + + def parse(self): + """Parse.""" + regex = r'Fortinet Firewall (.*) v((\d\.)*\d)' + pat = re.compile(regex) + res = pat.search(self.raw) + if res: + self.model = res.group(1) + self.version = res.group(2) + return self + + return False diff --git a/sysdescrparser/foundry.py b/sysdescrparser/foundry.py index 111c1c7..27994c2 100644 --- a/sysdescrparser/foundry.py +++ b/sysdescrparser/foundry.py @@ -2,7 +2,7 @@ """sysdescrparser.foundry.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/foundry_ironware.py b/sysdescrparser/foundry_ironware.py index e6a5705..b9ef632 100644 --- a/sysdescrparser/foundry_ironware.py +++ b/sysdescrparser/foundry_ironware.py @@ -4,7 +4,7 @@ import re -from foundry import Foundry +from sysdescrparser.foundry import Foundry # pylint: disable=no-member diff --git a/sysdescrparser/freebsd.py b/sysdescrparser/freebsd.py index dbf88a8..9fe49c0 100644 --- a/sysdescrparser/freebsd.py +++ b/sysdescrparser/freebsd.py @@ -3,7 +3,7 @@ """sysdescrparser.freebsd.""" import re -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/hp.py b/sysdescrparser/hp.py index c7b0954..15abf7e 100644 --- a/sysdescrparser/hp.py +++ b/sysdescrparser/hp.py @@ -2,7 +2,7 @@ """sysdescrparser.hp.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/hp_procurve.py b/sysdescrparser/hp_procurve.py index cba287e..7474ccf 100644 --- a/sysdescrparser/hp_procurve.py +++ b/sysdescrparser/hp_procurve.py @@ -4,7 +4,7 @@ import re -from hp import HP +from sysdescrparser.hp import HP # pylint: disable=no-member diff --git a/sysdescrparser/iij.py b/sysdescrparser/iij.py index f432a8f..7e407bb 100644 --- a/sysdescrparser/iij.py +++ b/sysdescrparser/iij.py @@ -2,7 +2,7 @@ """sysdescrparser.iij.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/iij_seil.py b/sysdescrparser/iij_seil.py index e48f37a..43f4965 100644 --- a/sysdescrparser/iij_seil.py +++ b/sysdescrparser/iij_seil.py @@ -4,7 +4,7 @@ import re -from iij import IIJ +from sysdescrparser.iij import IIJ # pylint: disable=no-member diff --git a/sysdescrparser/juniper.py b/sysdescrparser/juniper.py index 87ed389..136bf97 100644 --- a/sysdescrparser/juniper.py +++ b/sysdescrparser/juniper.py @@ -2,7 +2,7 @@ """sysdescrparser.juniper.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/juniper_junos.py b/sysdescrparser/juniper_junos.py index 0dd7087..b93cfac 100644 --- a/sysdescrparser/juniper_junos.py +++ b/sysdescrparser/juniper_junos.py @@ -4,7 +4,7 @@ import re -from juniper import Juniper +from sysdescrparser.juniper import Juniper # pylint: disable=no-member diff --git a/sysdescrparser/juniper_screenos.py b/sysdescrparser/juniper_screenos.py index 1d78751..4952e9f 100644 --- a/sysdescrparser/juniper_screenos.py +++ b/sysdescrparser/juniper_screenos.py @@ -4,7 +4,7 @@ import re -from juniper import Juniper +from sysdescrparser.juniper import Juniper # pylint: disable=no-member diff --git a/sysdescrparser/linux.py b/sysdescrparser/linux.py index e54f979..7941747 100644 --- a/sysdescrparser/linux.py +++ b/sysdescrparser/linux.py @@ -3,7 +3,8 @@ """sysdescrparser.linux.""" import re -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr +from sysdescrparser.utils import os_version_names_regex, extract_version_number # pylint: disable=no-name-in-module @@ -16,16 +17,36 @@ class Linux(SysDescr): """ + versions = { + "ubuntu_linux": { + "lucid": "10.04", + "precise": "12.04", + "trusty": "14.04", + "xenial": "16.04", + "bionic": "18.04", + }, + "centos": { + "centos6": "6.0", + "el6": "6.0", + "centos7": "7.0", + "el7": "7.0", + "centos": "", + } + } + def __init__(self, raw): """Constructor.""" super(Linux, self).__init__(raw) - self.vendor = self.UNKNOWN + self.vendor = 'LINUX' self.model = self.UNKNOWN - self.os = 'LINUX' + self.os = 'LINUX_KERNEL' self.version = self.UNKNOWN def parse(self): """Parsing for sysDescr value.""" + version_name = "" + kernel_version = "" + regex = (r'^Linux\s+') pat = re.compile(regex) res = pat.search(self.raw) @@ -34,6 +55,65 @@ def parse(self): pat = re.compile(regex) res = pat.split(self.raw) if len(res) > 2: - self.version = res[2] - return self + kernel_version = res[2] + + ubuntu_version_names_regex = os_version_names_regex(self.__class__.versions["ubuntu_linux"]) + ubuntu_lts_match = re.search( + ubuntu_version_names_regex, + self.raw, + flags=re.IGNORECASE + ) + ubuntu_main_version_name_match = re.search( + "ubuntu", + self.raw, + flags=re.IGNORECASE + ) + + centos_version_names_regex = os_version_names_regex(self.__class__.versions["centos"]) + centos_match = re.search( + centos_version_names_regex, + self.raw, + flags=re.IGNORECASE + ) + + if ubuntu_lts_match or ubuntu_main_version_name_match: + self.vendor = "CANONICAL" + self.os = "UBUNTU_LINUX" + + if not ubuntu_lts_match: + version_name = self.UNKNOWN + + else: + version_name = ubuntu_lts_match.group() + + if centos_match: + self.vendor = "CENTOS" + self.os = "CENTOS" + version_name = centos_match.group() + + if version_name and version_name != 'UNKNOWN': + # make it lower cause our versions dict keys are lower + os_lookup_name = self.os.lower() + os_versions = self.__class__.versions[os_lookup_name] + version_number = extract_version_number( + os_versions, + version_name, + ) + if version_number: + self.version = version_number + + else: + self.version = self.UNKNOWN + + self.model = kernel_version if kernel_version else self.UNKNOWN + + elif version_name == 'UNKNOWN': + self.version = version_name + self.model = kernel_version if kernel_version else self.UNKNOWN + + else: + self.version = kernel_version + + return self + return False diff --git a/sysdescrparser/mikrotik_routeros.py b/sysdescrparser/mikrotik_routeros.py new file mode 100644 index 0000000..9c3752e --- /dev/null +++ b/sysdescrparser/mikrotik_routeros.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +"""sysdescrparser.mikrotik_routeros.""" + +from sysdescrparser.sysdescr import SysDescr +import re + + +# pylint: disable=no-member +class MikroTikRouterOS(SysDescr): + + """Class MikroTikRouterOS. + + SNMP sysDescr for MikroTikRouterOs. + + """ + + def __init__(self, raw): + """Constructor.""" + super(MikroTikRouterOS, self).__init__(raw) + self.vendor = 'MikroTik' + self.os = 'RouterOS' + self.model = self.UNKNOWN + self.version = self.UNKNOWN + + def parse(self): + """Parse.""" + regex = r"RouterOS\s+([\d.]+)\s+\(([\w|-]+)\)\s+on\s+([\w\-\+]+)" + pat = re.compile(regex) + res = pat.search(self.raw) + if res: + self.version = res.group(1) + self.model = res.group(3) + return self + + return False diff --git a/sysdescrparser/paloalto.py b/sysdescrparser/paloalto.py index 98335bb..54a2323 100644 --- a/sysdescrparser/paloalto.py +++ b/sysdescrparser/paloalto.py @@ -2,7 +2,7 @@ """sysdescrparser.paloalto.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/paloalto_panos.py b/sysdescrparser/paloalto_panos.py index 78a6d7e..ab6175d 100644 --- a/sysdescrparser/paloalto_panos.py +++ b/sysdescrparser/paloalto_panos.py @@ -4,7 +4,7 @@ import re -from paloalto import PaloAlto +from sysdescrparser.paloalto import PaloAlto # pylint: disable=no-member diff --git a/sysdescrparser/sun.py b/sysdescrparser/sun.py index 5bd3c21..613cddd 100644 --- a/sysdescrparser/sun.py +++ b/sysdescrparser/sun.py @@ -2,7 +2,7 @@ """sysdescrparser.sun.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/sun_sunos.py b/sysdescrparser/sun_sunos.py index 0c53b2a..545bb6d 100644 --- a/sysdescrparser/sun_sunos.py +++ b/sysdescrparser/sun_sunos.py @@ -4,7 +4,7 @@ import re -from sun import Sun +from sysdescrparser.sun import Sun # pylint: disable=no-member diff --git a/sysdescrparser/sysdescrparser.py b/sysdescrparser/sysdescrparser.py index dea69df..d6b6d6f 100644 --- a/sysdescrparser/sysdescrparser.py +++ b/sysdescrparser/sysdescrparser.py @@ -3,32 +3,37 @@ """sysdescrparser.""" -import sys -import os -sys.path.append(os.path.dirname(__file__)) - -# pylint: disable=C0413 -from cisco_ios import CiscoIOS -from cisco_nxos import CiscoNXOS -from cisco_iosxr import CiscoIOSXR -from juniper_junos import JuniperJunos -from juniper_screenos import JuniperScreenOS -from brocade_ironware import BrocadeIronWare -from brocade_serveriron import BrocadeServerIron -from brocade_networkos import BrocadeNetworkOS -from foundry_ironware import FoundryIronWare -from arista_eos import AristaEOS -from hp_procurve import HPProCurve -from extreme_xos import ExtremeXOS -from paloalto_panos import PaloAltoPANOS -from a10_acos import A10ACOS -from citrix_netscaler import CitrixNetscaler -from linux import Linux -from sun_sunos import SunSUNOS -from freebsd import FreeBSD -from iij_seil import IIJSeil -from yamaha_rtx import YamahaRTX -from unknown import Unknown +# Why this? +# import sys +# import os +# sys.path.append(os.path.dirname(__file__)) + +from sysdescrparser.aruba import Aruba +from sysdescrparser.cisco_asa import CiscoASA +from sysdescrparser.cisco_ios import CiscoIOS +from sysdescrparser.cisco_nxos import CiscoNXOS +from sysdescrparser.cisco_iosxe import CiscoIOSXE +from sysdescrparser.cisco_iosxr import CiscoIOSXR +from sysdescrparser.mikrotik_routeros import MikroTikRouterOS +from sysdescrparser.juniper_junos import JuniperJunos +from sysdescrparser.juniper_screenos import JuniperScreenOS +from sysdescrparser.brocade_ironware import BrocadeIronWare +from sysdescrparser.brocade_serveriron import BrocadeServerIron +from sysdescrparser.brocade_networkos import BrocadeNetworkOS +from sysdescrparser.foundry_ironware import FoundryIronWare +from sysdescrparser.arista_eos import AristaEOS +from sysdescrparser.hp_procurve import HPProCurve +from sysdescrparser.extreme_xos import ExtremeXOS +from sysdescrparser.paloalto_panos import PaloAltoPANOS +from sysdescrparser.a10_acos import A10ACOS +from sysdescrparser.citrix_netscaler import CitrixNetscaler +from sysdescrparser.linux import Linux +from sysdescrparser.sun_sunos import SunSUNOS +from sysdescrparser.freebsd import FreeBSD +from sysdescrparser.iij_seil import IIJSeil +from sysdescrparser.yamaha_rtx import YamahaRTX +from sysdescrparser.fortinet_fortios import FortiOs +from sysdescrparser.unknown import Unknown def sysdescrparser(sysdescr): @@ -67,20 +72,39 @@ def sysdescrparser(sysdescr): Currently supported Vendor and OS. - https://github.com/mtoshi/sysdescrparser/blob/master/samples/sample_data.json + https://github.com/rlaneyjr/sysdescrparser/blob/master/samples/sample_data.json See also: - https://github.com/mtoshi/sysdescrparser/blob/master/README.rst + https://github.com/rlaneyjr/sysdescrparser/blob/master/README.rst + """ # + # aruba + # + obj = Aruba(sysdescr) + if obj.parse(): + return obj + # + # cisco asa + # + obj = CiscoASA(sysdescr) + if obj.parse(): + return obj + # # cisco nxos # obj = CiscoNXOS(sysdescr) if obj.parse(): return obj # + # cisco iosxe + # + obj = CiscoIOSXE(sysdescr) + if obj.parse(): + return obj + # # cisco iosxr # obj = CiscoIOSXR(sysdescr) @@ -93,6 +117,11 @@ def sysdescrparser(sysdescr): if obj.parse(): return obj # + # mikrotik routeros + obj = MikroTikRouterOS(sysdescr) + if obj.parse(): + return obj + # # juniper junos # obj = JuniperJunos(sysdescr) @@ -195,6 +224,12 @@ def sysdescrparser(sysdescr): if obj.parse(): return obj # + # fortigate + # + obj = FortiOs(sysdescr) + if obj.parse(): + return obj + # # Unknown # obj = Unknown(sysdescr) diff --git a/sysdescrparser/tests/test_sysdescrparser.py b/sysdescrparser/tests/test_sysdescrparser.py index c2967f1..5dd5773 100644 --- a/sysdescrparser/tests/test_sysdescrparser.py +++ b/sysdescrparser/tests/test_sysdescrparser.py @@ -5,8 +5,8 @@ import unittest import os import json -from sysdescrparser import sysdescrparser -from sysdescr import SysDescr +from sysdescrparser.sysdescrparser import sysdescrparser +from sysdescrparser.sysdescr import SysDescr class UnitTests(unittest.TestCase): diff --git a/sysdescrparser/unknown.py b/sysdescrparser/unknown.py index 9089dd2..227a5ee 100644 --- a/sysdescrparser/unknown.py +++ b/sysdescrparser/unknown.py @@ -3,7 +3,7 @@ """sysdescrparser.unknown.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr class Unknown(SysDescr): diff --git a/sysdescrparser/utils/__init__.py b/sysdescrparser/utils/__init__.py new file mode 100644 index 0000000..2291a58 --- /dev/null +++ b/sysdescrparser/utils/__init__.py @@ -0,0 +1,11 @@ +def os_version_names_regex(os_dict): + os_version_names = os_dict.keys() + return "|".join(os_version_names) + + +def extract_version_number(os_dict, version_name): + version_name = version_name.lower() + version_number = os_dict[version_name] + version_number = str(version_number) + return version_number + diff --git a/sysdescrparser/yamaha.py b/sysdescrparser/yamaha.py index 4d7d349..7858473 100644 --- a/sysdescrparser/yamaha.py +++ b/sysdescrparser/yamaha.py @@ -2,7 +2,7 @@ """sysdescrparser.yamaha.""" -from sysdescr import SysDescr +from sysdescrparser.sysdescr import SysDescr # pylint: disable=no-name-in-module diff --git a/sysdescrparser/yamaha_rtx.py b/sysdescrparser/yamaha_rtx.py index 23fd0a3..dbb4293 100644 --- a/sysdescrparser/yamaha_rtx.py +++ b/sysdescrparser/yamaha_rtx.py @@ -4,7 +4,7 @@ import re -from yamaha import Yamaha +from sysdescrparser.yamaha import Yamaha # pylint: disable=no-member diff --git a/tox.ini b/tox.ini index 02ace34..8235a08 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,8 @@ [tox] envlist = - py27, - py35, - py36, - py37, + py38, + py39, + py310, PyPy, pylint, docs