From 8ab64ab2ac7c0bfc0f65a1ac012154d52365afc1 Mon Sep 17 00:00:00 2001 From: pablodav Date: Thu, 30 Mar 2017 11:36:21 -0300 Subject: [PATCH 01/10] Added options to check interface by ifDescr regex, and also by ifAlias regex --- lib/nelmon/cli/check_admin_up_oper_down.py | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/nelmon/cli/check_admin_up_oper_down.py b/lib/nelmon/cli/check_admin_up_oper_down.py index 9c2c8e0..c041fda 100755 --- a/lib/nelmon/cli/check_admin_up_oper_down.py +++ b/lib/nelmon/cli/check_admin_up_oper_down.py @@ -5,8 +5,9 @@ from nelmon.snmp.oids import cisco_oids as O from nelmon.snmp.args import SnmpArguments from nelmon.snmp.handler import NelmonSnmp +import re -NelmonGlobals(PLUGIN_VERSION='1.2') +NelmonGlobals(PLUGIN_VERSION='1.3') description = """This plugin queries a network device by SNMP to check if there are any interfaces which are in the admin up (no shutdown) but are operationally @@ -24,6 +25,14 @@ def main(): help='Return Warning if interfaces are down') argparser.parser.add_argument('-c', action='store_true', help='Return Critical if interfaces are down') + argparser.parser.add_argument('-d', '--descr', dest='ifdescr_arg', default=None, const=None, + help='Search over Interface descr with regex' + 'example: GigabitEthernet(\d+)/0/(4[78]|[5][0-2])' + 'matches any of: GigabitEthernetx/0/47,48,50,51,52') + argparser.parser.add_argument('-al', '--alias', dest='ifalias_arg', default=None, const=None, + help='Search over Interface alias with regex' + 'example: UPLINK' + 'matches any interfaces with keyword UPLINK on its alias') args = argparser.parser.parse_nelmon_args() @@ -34,6 +43,9 @@ def main(): else: nelmon_exit(C.UNKNOWN, 'Use -w or -c') + ifdescr_arg = args.ifdescr_arg + ifalias_arg = args.ifalias_arg + snmp = NelmonSnmp(args) oidlist = [] @@ -75,8 +87,31 @@ def main(): interface_alias[ifIndex] = value return_string = [] - if len(down_interfaces) > 1: + # Change the down_interfaces only to those that ifDescr matches regex passed to ifdescr_arg + if ifdescr_arg: + down_interfaces = [] + for ifIndex, ifDescr in interface_descr.items(): + # Add the regex from -d command, like: GigabitEthernet(\d+)/0/(4[78]|[5][0-2]) + ifdescr_regex = re.compile(ifdescr_arg) + # Only add to down_interfaces if regex matches + if ifdescr_regex.search(ifDescr): + down_interfaces.append(ifIndex) + + # Change the down_interfaces only to those that ifAlias matches regex passed to ifalias_arg + if ifalias_arg: + down_interfaces = [] + if interface_alias: + for ifIndex, ifAlias in interface_alias.items(): + # Add the regex from -d command, like: UPLINK + ifalias_regex = re.compile(ifalias_arg) + # Only add to down_interfaces if regex matches + if ifalias_regex.search(ifAlias): + down_interfaces.append(ifIndex) + + if len(down_interfaces) > 0: return_string.append("%d interfaces down" % (len(down_interfaces))) + else: + nelmon_exit(C.OK, 'No interfaces down') for ifIndex in down_interfaces: if len(str(interface_alias[ifIndex])) > 0: From 33aa6d8083b3bf918e25fcfe0afec64080a9c186 Mon Sep 17 00:00:00 2001 From: pablodav Date: Thu, 30 Mar 2017 16:41:43 -0300 Subject: [PATCH 02/10] added option to ignore some interface by ifDescr --- lib/nelmon/cli/check_admin_up_oper_down.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/nelmon/cli/check_admin_up_oper_down.py b/lib/nelmon/cli/check_admin_up_oper_down.py index c041fda..80eeebf 100755 --- a/lib/nelmon/cli/check_admin_up_oper_down.py +++ b/lib/nelmon/cli/check_admin_up_oper_down.py @@ -33,6 +33,9 @@ def main(): help='Search over Interface alias with regex' 'example: UPLINK' 'matches any interfaces with keyword UPLINK on its alias') + argparser.parser.add_argument('-ia', '--ignore_alias', dest='ifdescr_ignore_arg', default=None, const=None, + help='Search over Interface ifDescr with regex and ignores that' + 'example: Stack') args = argparser.parser.parse_nelmon_args() @@ -45,6 +48,7 @@ def main(): ifdescr_arg = args.ifdescr_arg ifalias_arg = args.ifalias_arg + ifdescr_ignore_arg = args.ifdescr_ignore_arg snmp = NelmonSnmp(args) @@ -102,12 +106,21 @@ def main(): down_interfaces = [] if interface_alias: for ifIndex, ifAlias in interface_alias.items(): - # Add the regex from -d command, like: UPLINK + # Add the regex from -al command, like: UPLINK ifalias_regex = re.compile(ifalias_arg) # Only add to down_interfaces if regex matches if ifalias_regex.search(ifAlias): down_interfaces.append(ifIndex) + # Change the down_interfaces only to those that ifDescr doesn't match regex passed to ifdescr_ignore_arg + if ifdescr_ignore_arg: + for ifIndex, ifDescr in interface_descr.items(): + # Add the regex from --ia command, like: GigabitEthernet(\d+)/0/(4[78]|[5][0-2]) or Stack + ifdescr_regex = re.compile(ifdescr_ignore_arg) + # Remove from down_interfaces if regex matches + if ifdescr_regex.search(ifDescr): + down_interfaces.remove(ifIndex) + if len(down_interfaces) > 0: return_string.append("%d interfaces down" % (len(down_interfaces))) else: From 56b42ff037284a1d4f3f7a1286933e4fac65a420 Mon Sep 17 00:00:00 2001 From: pablodav Date: Thu, 30 Mar 2017 16:49:32 -0300 Subject: [PATCH 03/10] fix wrong name to ignore command --- lib/nelmon/cli/check_admin_up_oper_down.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/nelmon/cli/check_admin_up_oper_down.py b/lib/nelmon/cli/check_admin_up_oper_down.py index 80eeebf..2a21b03 100755 --- a/lib/nelmon/cli/check_admin_up_oper_down.py +++ b/lib/nelmon/cli/check_admin_up_oper_down.py @@ -33,7 +33,7 @@ def main(): help='Search over Interface alias with regex' 'example: UPLINK' 'matches any interfaces with keyword UPLINK on its alias') - argparser.parser.add_argument('-ia', '--ignore_alias', dest='ifdescr_ignore_arg', default=None, const=None, + argparser.parser.add_argument('-id', '--ignore_descr', dest='ifdescr_ignore_arg', default=None, const=None, help='Search over Interface ifDescr with regex and ignores that' 'example: Stack') @@ -115,7 +115,7 @@ def main(): # Change the down_interfaces only to those that ifDescr doesn't match regex passed to ifdescr_ignore_arg if ifdescr_ignore_arg: for ifIndex, ifDescr in interface_descr.items(): - # Add the regex from --ia command, like: GigabitEthernet(\d+)/0/(4[78]|[5][0-2]) or Stack + # Add the regex from --id command, like: GigabitEthernet(\d+)/0/(4[78]|[5][0-2]) or Stack ifdescr_regex = re.compile(ifdescr_ignore_arg) # Remove from down_interfaces if regex matches if ifdescr_regex.search(ifDescr): From 4d68957f59b86e079472e758535467ffaefca9c4 Mon Sep 17 00:00:00 2001 From: Pablo Estigarribia Date: Tue, 9 May 2017 16:59:20 -0300 Subject: [PATCH 04/10] Update to 1.4.0 --- lib/nelmon/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nelmon/__init__.py b/lib/nelmon/__init__.py index 0179b8a..26d68b5 100644 --- a/lib/nelmon/__init__.py +++ b/lib/nelmon/__init__.py @@ -1,3 +1,3 @@ """Nelmon - Networklore Monitoring Toolkit.""" -__version__ = "1.3.5" +__version__ = "1.4.0" __author__ = 'Patrick Ogenstad' From 1ab231bb529562f1bbe2bfc2ba8b049c1ab9d327 Mon Sep 17 00:00:00 2001 From: Pablo Estigarribia Date: Tue, 9 May 2017 17:02:27 -0300 Subject: [PATCH 05/10] Update to 1.4.0 --- HISTORY.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 4eb8dab..7e0e4eb 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,13 @@ Release History --------------- +1.4.0 (2017-05-09) +++++++++++++++++++ + +* Added options to check interface by ifDescr regex (pablodav) +* Added options to check interface by ifAlias (pablodav) +* Added option to ignore some interface by ifDescr (pablodav) + 1.3.5 (2016-11-04) ++++++++++++++++++ From 08b4841668d033a0ace670b38101f27a43706f1c Mon Sep 17 00:00:00 2001 From: Pablo Estigarribia Date: Tue, 9 May 2017 17:04:55 -0300 Subject: [PATCH 06/10] added setuptools dependency to fix issue with NameError: name 'platform_system' is not defined fixes NameError: name 'platform_system' is not defined --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ef61426..800fd39 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ 'author_email': 'patrick@ogenstad.com', 'license': 'Apache', 'url': 'https://networklore.com/nelmon/', - 'install_requires': ['argparse', 'nelsnmp >= 0.2.3', 'PyYAML', 'requests'], + 'install_requires': ['argparse', 'nelsnmp >= 0.2.3', 'PyYAML', 'requests', 'setuptools>=35.0.2'], 'classifiers': ['Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Intended Audience :: System Administrators'] From 7c1bf698f429002ec17cbd1e4b9c9bbed34cb3b0 Mon Sep 17 00:00:00 2001 From: Pablo Estigarribia Date: Tue, 11 Jul 2017 22:32:31 -0300 Subject: [PATCH 07/10] change version to 1.3.6 as requested by @ongestad --- HISTORY.rst | 2 +- lib/nelmon/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 7e0e4eb..d0a8262 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,7 +3,7 @@ Release History --------------- -1.4.0 (2017-05-09) +1.3.6 (2017-05-09) ++++++++++++++++++ * Added options to check interface by ifDescr regex (pablodav) diff --git a/lib/nelmon/__init__.py b/lib/nelmon/__init__.py index 26d68b5..1d9830e 100644 --- a/lib/nelmon/__init__.py +++ b/lib/nelmon/__init__.py @@ -1,3 +1,3 @@ """Nelmon - Networklore Monitoring Toolkit.""" -__version__ = "1.4.0" +__version__ = "1.3.6" __author__ = 'Patrick Ogenstad' From e6b59b4df944e39ba12a684c4cb878798bd53728 Mon Sep 17 00:00:00 2001 From: Pablo Estigarribia Date: Tue, 11 Jul 2017 22:56:06 -0300 Subject: [PATCH 08/10] update to version 1.3.7 fix problems with nelsnmp 0.2.6 --- HISTORY.rst | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index d0a8262..b911ec9 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,12 +3,18 @@ Release History --------------- +1.3.7 (2017-06-11) +++++++++++++++++++ + +* fix nelsnmp version to 0.2.5 due to bug https://github.com/networklore/nelsnmp/issues/8 (pablodav) + 1.3.6 (2017-05-09) ++++++++++++++++++ * Added options to check interface by ifDescr regex (pablodav) * Added options to check interface by ifAlias (pablodav) * Added option to ignore some interface by ifDescr (pablodav) +* Add setuptools>=35.0.2 to dependencies to avoid installation issues on outdated environments (pablodav) 1.3.5 (2016-11-04) ++++++++++++++++++ diff --git a/setup.py b/setup.py index 800fd39..2395ae2 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ 'author_email': 'patrick@ogenstad.com', 'license': 'Apache', 'url': 'https://networklore.com/nelmon/', - 'install_requires': ['argparse', 'nelsnmp >= 0.2.3', 'PyYAML', 'requests', 'setuptools>=35.0.2'], + 'install_requires': ['argparse', 'nelsnmp==0.2.5', 'PyYAML', 'requests', 'setuptools>=35.0.2'], 'classifiers': ['Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Intended Audience :: System Administrators'] From 096f9414d92ab7ffe0db65ff0d23f4c914e0cefb Mon Sep 17 00:00:00 2001 From: Pablo Estigarribia Date: Tue, 11 Jul 2017 22:58:05 -0300 Subject: [PATCH 09/10] update to version 1.3.7 fix problems with nelsnmp 0.2.6 --- lib/nelmon/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/nelmon/__init__.py b/lib/nelmon/__init__.py index 1d9830e..679cd2e 100644 --- a/lib/nelmon/__init__.py +++ b/lib/nelmon/__init__.py @@ -1,3 +1,3 @@ """Nelmon - Networklore Monitoring Toolkit.""" -__version__ = "1.3.6" +__version__ = "1.3.7" __author__ = 'Patrick Ogenstad' From cd2bbd0c54a9bbb8d529e1ff2b30a2010499aed1 Mon Sep 17 00:00:00 2001 From: Pablo Estigarribia Date: Tue, 18 Jul 2017 10:41:32 -0300 Subject: [PATCH 10/10] change version back to 1.3.6 and also remove dependency on setuptools as tests shown it unnecesary --- HISTORY.rst | 9 ++------- lib/nelmon/__init__.py | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index b911ec9..e932fc2 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,18 +3,13 @@ Release History --------------- -1.3.7 (2017-06-11) -++++++++++++++++++ - -* fix nelsnmp version to 0.2.5 due to bug https://github.com/networklore/nelsnmp/issues/8 (pablodav) - -1.3.6 (2017-05-09) +1.3.6 (2017-07-18) ++++++++++++++++++ * Added options to check interface by ifDescr regex (pablodav) * Added options to check interface by ifAlias (pablodav) * Added option to ignore some interface by ifDescr (pablodav) -* Add setuptools>=35.0.2 to dependencies to avoid installation issues on outdated environments (pablodav) +* fix nelsnmp version to 0.2.5 due to bug https://github.com/networklore/nelsnmp/issues/8 (pablodav) 1.3.5 (2016-11-04) ++++++++++++++++++ diff --git a/lib/nelmon/__init__.py b/lib/nelmon/__init__.py index 679cd2e..1d9830e 100644 --- a/lib/nelmon/__init__.py +++ b/lib/nelmon/__init__.py @@ -1,3 +1,3 @@ """Nelmon - Networklore Monitoring Toolkit.""" -__version__ = "1.3.7" +__version__ = "1.3.6" __author__ = 'Patrick Ogenstad' diff --git a/setup.py b/setup.py index 2395ae2..05b3294 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ 'author_email': 'patrick@ogenstad.com', 'license': 'Apache', 'url': 'https://networklore.com/nelmon/', - 'install_requires': ['argparse', 'nelsnmp==0.2.5', 'PyYAML', 'requests', 'setuptools>=35.0.2'], + 'install_requires': ['argparse', 'nelsnmp==0.2.5', 'PyYAML', 'requests'], 'classifiers': ['Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Intended Audience :: System Administrators']