mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
Plugin snmp__airport: fix code style issues reported by flake8
This commit is contained in:
parent
dacb55010a
commit
ba732fd7ec
2 changed files with 25 additions and 13 deletions
|
@ -49,24 +49,27 @@ Please install the Python bindings for libsnmp.
|
||||||
On Debian/Ubuntu machines this package is named 'libsnmp-python'"""
|
On Debian/Ubuntu machines this package is named 'libsnmp-python'"""
|
||||||
sys.exit(-3)
|
sys.exit(-3)
|
||||||
|
|
||||||
DEBUG=None
|
DEBUG = None
|
||||||
CMDS=['type', 'rates', 'time', 'lastrefresh', 'signal', 'noise', 'rate', 'rx',
|
CMDS = ['type', 'rates', 'time', 'lastrefresh', 'signal', 'noise', 'rate', 'rx', 'tx', 'rxerr',
|
||||||
'tx', 'rxerr', 'txerr']
|
'txerr']
|
||||||
CMD=None
|
CMD = None
|
||||||
DESTHOST=None
|
DESTHOST = None
|
||||||
NUMCLIENTS=None
|
NUMCLIENTS = None
|
||||||
NUMDHCPCLIENTS=None
|
NUMDHCPCLIENTS = None
|
||||||
WANIFINDEX=None
|
WANIFINDEX = None
|
||||||
|
|
||||||
|
|
||||||
def dbg(text):
|
def dbg(text):
|
||||||
"""Print some debugging text if DEBUG=1 is in our environment"""
|
"""Print some debugging text if DEBUG=1 is in our environment"""
|
||||||
if DEBUG is not None:
|
if DEBUG is not None:
|
||||||
print "DEBUG: %s" % text
|
print "DEBUG: %s" % text
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
"""Print some usage information about ourselves"""
|
"""Print some usage information about ourselves"""
|
||||||
print __doc__
|
print __doc__
|
||||||
|
|
||||||
|
|
||||||
def parseName(name):
|
def parseName(name):
|
||||||
"""Examing argv[0] (i.e. the name of this script) for the hostname we should
|
"""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
|
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)
|
dbg("parseName found an inconsistent name: '%s'" % name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def tableToDict(table, num):
|
def tableToDict(table, num):
|
||||||
"""The netsnmp library returns a tuple with all of the data, it is not in any
|
"""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
|
way formatted into rows. This function converts the data into a structured
|
||||||
|
@ -129,6 +133,7 @@ def tableToDict(table, num):
|
||||||
|
|
||||||
return clientTable
|
return clientTable
|
||||||
|
|
||||||
|
|
||||||
def getNumClients():
|
def getNumClients():
|
||||||
"""Returns the number of wireless clients connected to the Airport we are
|
"""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
|
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)
|
dbg("getNumClients: found %d clients" % NUMCLIENTS)
|
||||||
return NUMCLIENTS
|
return NUMCLIENTS
|
||||||
|
|
||||||
|
|
||||||
def getNumDHCPClients():
|
def getNumDHCPClients():
|
||||||
"""Returns the number of DHCP clients with currently active leases. This
|
"""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
|
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)
|
dbg("getNumDHCPClients: found %d clients" % NUMDHCPCLIENTS)
|
||||||
return NUMDHCPCLIENTS
|
return NUMDHCPCLIENTS
|
||||||
|
|
||||||
|
|
||||||
def getExternalInterface():
|
def getExternalInterface():
|
||||||
"""Returns the index of the WAN interface of the Airport. This will only
|
"""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
|
ever be polled via SNMP once per invocation, per getNum*Clients(). See
|
||||||
|
@ -189,14 +196,17 @@ def getExternalInterface():
|
||||||
dbg("getExternalInterface: found mgi1 at index: %d" % WANIFINDEX)
|
dbg("getExternalInterface: found mgi1 at index: %d" % WANIFINDEX)
|
||||||
return WANIFINDEX
|
return WANIFINDEX
|
||||||
|
|
||||||
|
|
||||||
def getExternalInOctets():
|
def getExternalInOctets():
|
||||||
"""Returns the number of octets of inbound traffic on the WAN interface"""
|
"""Returns the number of octets of inbound traffic on the WAN interface"""
|
||||||
return getOctets('In')
|
return getOctets('In')
|
||||||
|
|
||||||
|
|
||||||
def getExternalOutOctets():
|
def getExternalOutOctets():
|
||||||
"""Returns the number of octets of outbound traffic on the WAN interface"""
|
"""Returns the number of octets of outbound traffic on the WAN interface"""
|
||||||
return getOctets('Out')
|
return getOctets('Out')
|
||||||
|
|
||||||
|
|
||||||
def getOctets(direction):
|
def getOctets(direction):
|
||||||
"""Returns the number of octets of traffic on the WAN interface in the
|
"""Returns the number of octets of traffic on the WAN interface in the
|
||||||
requested direction"""
|
requested direction"""
|
||||||
|
@ -211,6 +221,7 @@ def getOctets(direction):
|
||||||
Version=2, DestHost=DESTHOST,
|
Version=2, DestHost=DESTHOST,
|
||||||
Community='public')[0])
|
Community='public')[0])
|
||||||
|
|
||||||
|
|
||||||
def getWanSpeed():
|
def getWanSpeed():
|
||||||
"""Returns the speed of the WAN interface"""
|
"""Returns the speed of the WAN interface"""
|
||||||
ifSpeed = "1.3.6.1.2.1.2.2.1.5.%s" % getExternalInterface()
|
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),
|
wanSpeed = int(netsnmp.snmpget(netsnmp.Varbind(ifSpeed),
|
||||||
Version=2, DestHost=DESTHOST,
|
Version=2, DestHost=DESTHOST,
|
||||||
Community='public')[0])
|
Community='public')[0])
|
||||||
except:
|
except: # noqa: E722 (TODO: specify the expected exceptions)
|
||||||
dbg("getWanSpeed: Unable to probe for data, defaultint to 10000000")
|
dbg("getWanSpeed: Unable to probe for data, defaultint to 10000000")
|
||||||
wanSpeed = 10000000
|
wanSpeed = 10000000
|
||||||
|
|
||||||
return wanSpeed
|
return wanSpeed
|
||||||
|
|
||||||
|
|
||||||
def getData():
|
def getData():
|
||||||
"""Returns a dictionary populated with all of the wireless clients and their
|
"""Returns a dictionary populated with all of the wireless clients and their
|
||||||
metadata"""
|
metadata"""
|
||||||
|
@ -246,6 +258,7 @@ def getData():
|
||||||
|
|
||||||
return clients
|
return clients
|
||||||
|
|
||||||
|
|
||||||
def main(clients=None):
|
def main(clients=None):
|
||||||
"""This function fetches metadata about wireless clients if needed, then
|
"""This function fetches metadata about wireless clients if needed, then
|
||||||
displays whatever values have been requested"""
|
displays whatever values have been requested"""
|
||||||
|
@ -263,6 +276,7 @@ def main(clients=None):
|
||||||
for client in clients:
|
for client in clients:
|
||||||
print "MAC_%s.value %s" % (client, clients[client][CMD])
|
print "MAC_%s.value %s" % (client, clients[client][CMD])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
clients = None
|
clients = None
|
||||||
if os.getenv('DEBUG') == '1':
|
if os.getenv('DEBUG') == '1':
|
||||||
|
@ -352,4 +366,3 @@ send.min 0""" % (speed, speed)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
main(clients)
|
main(clients)
|
||||||
|
|
||||||
|
|
|
@ -412,7 +412,6 @@ plugins/sge/sge_job_stats
|
||||||
plugins/sge/sge_queue_
|
plugins/sge/sge_queue_
|
||||||
plugins/sge/sge_queue_xml_
|
plugins/sge/sge_queue_xml_
|
||||||
plugins/smstools/smstools_
|
plugins/smstools/smstools_
|
||||||
plugins/snmp/snmp__airport
|
|
||||||
plugins/snmp/snmp___bri_se_
|
plugins/snmp/snmp___bri_se_
|
||||||
plugins/snmp/snmp__brocade_ifs
|
plugins/snmp/snmp__brocade_ifs
|
||||||
plugins/snmp/snmp__fn
|
plugins/snmp/snmp__fn
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue