-
Notifications
You must be signed in to change notification settings - Fork 7
Added options to check interface by ifDescr regex, and also by ifAlias regex #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8ab64ab
33aa6d8
56b42ff
4d68957
1ab231b
08b4841
7c1bf69
e6b59b4
096f941
cd2bbd0
667156d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ dist | |
| # test output | ||
| .coverage | ||
| .tox | ||
| .vscode | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,17 @@ 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') | ||
| argparser.parser.add_argument('-id', '--ignore_descr', dest='ifdescr_ignore_arg', default=None, const=None, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although I know all the "good letters" are already taken I'd like the arguments to include only one letter. Can you think of any other alternatives instead of -al and -id?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I have forgot to answer to it. what do you think about it: instead of '-al' for alias, use: '-s' or '-a' What do you prefer? |
||
| help='Search over Interface ifDescr with regex and ignores that' | ||
| 'example: Stack') | ||
|
|
||
| args = argparser.parser.parse_nelmon_args() | ||
|
|
||
|
|
@@ -34,6 +46,10 @@ def main(): | |
| else: | ||
| nelmon_exit(C.UNKNOWN, 'Use -w or -c') | ||
|
|
||
| ifdescr_arg = args.ifdescr_arg | ||
| ifalias_arg = args.ifalias_arg | ||
| ifdescr_ignore_arg = args.ifdescr_ignore_arg | ||
|
|
||
| snmp = NelmonSnmp(args) | ||
|
|
||
| oidlist = [] | ||
|
|
@@ -75,8 +91,40 @@ 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 -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 --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): | ||
| down_interfaces.remove(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: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these descriptions get quite long with strange linebreaks. Try using
nm_check_admin_up_oper_down -h. It should be enough to add a few\n