Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
# test output
.coverage
.tox
.vscode
4 changes: 3 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ Release History
1.3.6 (2017-09-30)
++++++++++++++++++

* 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)
* Bugfixes due to changes in nelsnmp


1.3.5 (2016-11-04)
++++++++++++++++++

Expand Down
52 changes: 50 additions & 2 deletions lib/nelmon/cli/check_admin_up_oper_down.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Copy link
Member

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

'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,
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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'
instead of '-id' for ignore description, use: '-x'

What do you prefer?

help='Search over Interface ifDescr with regex and ignores that'
'example: Stack')

args = argparser.parser.parse_nelmon_args()

Expand All @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down