Skip to content
Permalink
Browse files

Plugin snmp__airport: fix code style issues reported by flake8

  • Loading branch information...
sumpfralle committed Aug 13, 2019
1 parent dacb550 commit ba732fd7ec3226e9f15d81df8d41e343b5ac58fc
Showing with 25 additions and 13 deletions.
  1. +25 −12 plugins/snmp/snmp__airport
  2. +0 −1 t/test-exception-wrapper.expected-failures
@@ -49,24 +49,27 @@ Please install the Python bindings for libsnmp.
On Debian/Ubuntu machines this package is named 'libsnmp-python'"""
sys.exit(-3)

DEBUG=None
CMDS=['type', 'rates', 'time', 'lastrefresh', 'signal', 'noise', 'rate', 'rx',
'tx', 'rxerr', 'txerr']
CMD=None
DESTHOST=None
NUMCLIENTS=None
NUMDHCPCLIENTS=None
WANIFINDEX=None
DEBUG = None
CMDS = ['type', 'rates', 'time', 'lastrefresh', 'signal', 'noise', 'rate', 'rx', 'tx', 'rxerr',
'txerr']
CMD = None
DESTHOST = None
NUMCLIENTS = None
NUMDHCPCLIENTS = None
WANIFINDEX = None


def dbg(text):
"""Print some debugging text if DEBUG=1 is in our environment"""
if DEBUG is not None:
print "DEBUG: %s" % text


def usage():
"""Print some usage information about ourselves"""
print __doc__


def parseName(name):
"""Examing argv[0] (i.e. the name of this script) for the hostname we should
be talking to and the type of check we want to run. The hostname should be
@@ -88,6 +91,7 @@ def parseName(name):
dbg("parseName found an inconsistent name: '%s'" % name)
return None


def tableToDict(table, num):
"""The netsnmp library returns a tuple with all of the data, it is not in any
way formatted into rows. This function converts the data into a structured
@@ -129,6 +133,7 @@ def tableToDict(table, num):

return clientTable


def getNumClients():
"""Returns the number of wireless clients connected to the Airport we are
examining. This will only ever be polled via SNMP once per invocation. If
@@ -148,6 +153,7 @@ def getNumClients():
dbg("getNumClients: found %d clients" % NUMCLIENTS)
return NUMCLIENTS


def getNumDHCPClients():
"""Returns the number of DHCP clients with currently active leases. This
will only ever be polled via SNMP once per invocation. If called a second
@@ -167,6 +173,7 @@ def getNumDHCPClients():
dbg("getNumDHCPClients: found %d clients" % NUMDHCPCLIENTS)
return NUMDHCPCLIENTS


def getExternalInterface():
"""Returns the index of the WAN interface of the Airport. This will only
ever be polled via SNMP once per invocation, per getNum*Clients(). See
@@ -176,8 +183,8 @@ def getExternalInterface():

if WANIFINDEX is None:
interfaces = list(netsnmp.snmpwalk(netsnmp.Varbind(iFaceNames),
Version=2, DestHost=DESTHOST,
Community='public'))
Version=2, DestHost=DESTHOST,
Community='public'))
dbg("getExternalInterface: found interfaces: %s" % interfaces)
try:
WANIFINDEX = interfaces.index('mgi1') + 1
@@ -189,14 +196,17 @@ def getExternalInterface():
dbg("getExternalInterface: found mgi1 at index: %d" % WANIFINDEX)
return WANIFINDEX


def getExternalInOctets():
"""Returns the number of octets of inbound traffic on the WAN interface"""
return getOctets('In')


def getExternalOutOctets():
"""Returns the number of octets of outbound traffic on the WAN interface"""
return getOctets('Out')


def getOctets(direction):
"""Returns the number of octets of traffic on the WAN interface in the
requested direction"""
@@ -211,6 +221,7 @@ def getOctets(direction):
Version=2, DestHost=DESTHOST,
Community='public')[0])


def getWanSpeed():
"""Returns the speed of the WAN interface"""
ifSpeed = "1.3.6.1.2.1.2.2.1.5.%s" % getExternalInterface()
@@ -219,12 +230,13 @@ def getWanSpeed():
wanSpeed = int(netsnmp.snmpget(netsnmp.Varbind(ifSpeed),
Version=2, DestHost=DESTHOST,
Community='public')[0])
except:
except: # noqa: E722 (TODO: specify the expected exceptions)
dbg("getWanSpeed: Unable to probe for data, defaultint to 10000000")
wanSpeed = 10000000

return wanSpeed


def getData():
"""Returns a dictionary populated with all of the wireless clients and their
metadata"""
@@ -246,6 +258,7 @@ def getData():

return clients


def main(clients=None):
"""This function fetches metadata about wireless clients if needed, then
displays whatever values have been requested"""
@@ -263,6 +276,7 @@ def main(clients=None):
for client in clients:
print "MAC_%s.value %s" % (client, clients[client][CMD])


if __name__ == '__main__':
clients = None
if os.getenv('DEBUG') == '1':
@@ -352,4 +366,3 @@ send.min 0""" % (speed, speed)
sys.exit(0)
else:
main(clients)

@@ -412,7 +412,6 @@ plugins/sge/sge_job_stats
plugins/sge/sge_queue_
plugins/sge/sge_queue_xml_
plugins/smstools/smstools_
plugins/snmp/snmp__airport
plugins/snmp/snmp___bri_se_
plugins/snmp/snmp__brocade_ifs
plugins/snmp/snmp__fn

0 comments on commit ba732fd

Please sign in to comment.
You can’t perform that action at this time.