Révision 3a2f2ec7
Plugin snmp__airport: port to python3
| plugins/snmp/snmp__airport | ||
|---|---|---|
| 1 |
#!/usr/bin/python
|
|
| 1 |
#!/usr/bin/env python3
|
|
| 2 | 2 |
""" |
| 3 | 3 |
|
| 4 | 4 |
=head1 NAME |
| 5 | 5 |
|
| 6 |
Munin plugin to monitor various items of data from an Apple Airport Express/Extreme or a Time Capsule.
|
|
| 6 |
Monitor various items of data from an Apple Airport Express/Extreme or a Time Capsule. |
|
| 7 | 7 |
|
| 8 | 8 |
|
| 9 | 9 |
=head1 INSTALLATION |
| ... | ... | |
| 71 | 71 |
try: |
| 72 | 72 |
import netsnmp |
| 73 | 73 |
except ImportError: |
| 74 |
print """ERROR: Unable to import netsnmp.
|
|
| 74 |
print("""ERROR: Unable to import netsnmp.
|
|
| 75 | 75 |
Please install the Python bindings for libsnmp. |
| 76 |
On Debian/Ubuntu machines this package is named 'libsnmp-python'""" |
|
| 76 |
On Debian/Ubuntu machines this package is named 'libsnmp-python'""", file=sys.stderr)
|
|
| 77 | 77 |
sys.exit(-3) |
| 78 | 78 |
|
| 79 | 79 |
DEBUG = None |
| ... | ... | |
| 89 | 89 |
def dbg(text): |
| 90 | 90 |
"""Print some debugging text if DEBUG=1 is in our environment""" |
| 91 | 91 |
if DEBUG is not None: |
| 92 |
print "DEBUG: %s" % text
|
|
| 92 |
print("DEBUG: %s" % text)
|
|
| 93 | 93 |
|
| 94 | 94 |
|
| 95 | 95 |
def usage(): |
| 96 | 96 |
"""Print some usage information about ourselves""" |
| 97 |
print __doc__
|
|
| 97 |
print(__doc__)
|
|
| 98 | 98 |
|
| 99 | 99 |
|
| 100 | 100 |
def parseName(name): |
| ... | ... | |
| 216 | 216 |
try: |
| 217 | 217 |
WANIFINDEX = interfaces.index('mgi1') + 1
|
| 218 | 218 |
except ValueError: |
| 219 |
print "ERROR: Unable to find WAN interface mgi1"
|
|
| 220 |
print interfaces
|
|
| 219 |
print("ERROR: Unable to find WAN interface mgi1")
|
|
| 220 |
print(interfaces)
|
|
| 221 | 221 |
sys.exit(-3) |
| 222 | 222 |
|
| 223 | 223 |
dbg("getExternalInterface: found mgi1 at index: %d" % WANIFINDEX)
|
| ... | ... | |
| 293 | 293 |
clients = getData() |
| 294 | 294 |
|
| 295 | 295 |
if CMD == 'clients': |
| 296 |
print "clients.value %s" % getNumClients()
|
|
| 296 |
print("clients.value %s" % getNumClients())
|
|
| 297 | 297 |
elif CMD == 'dhcpclients': |
| 298 |
print "dhcpclients.value %s" % getNumDHCPClients()
|
|
| 298 |
print("dhcpclients.value %s" % getNumDHCPClients())
|
|
| 299 | 299 |
elif CMD == 'wanTraffic': |
| 300 |
print "recv.value %s" % getExternalInOctets()
|
|
| 301 |
print "send.value %s" % getExternalOutOctets()
|
|
| 300 |
print("recv.value %s" % getExternalInOctets())
|
|
| 301 |
print("send.value %s" % getExternalOutOctets())
|
|
| 302 | 302 |
else: |
| 303 | 303 |
for client in clients: |
| 304 |
print "MAC_%s.value %s" % (client, clients[client][CMD])
|
|
| 304 |
print("MAC_%s.value %s" % (client, clients[client][CMD]))
|
|
| 305 | 305 |
|
| 306 | 306 |
|
| 307 | 307 |
if __name__ == '__main__': |
| ... | ... | |
| 322 | 322 |
|
| 323 | 323 |
if len(sys.argv) > 1: |
| 324 | 324 |
if sys.argv[1] == 'config': |
| 325 |
print """
|
|
| 325 |
print("""
|
|
| 326 | 326 |
graph_category network |
| 327 |
host_name %s""" % DESTHOST |
|
| 327 |
host_name %s""" % DESTHOST)
|
|
| 328 | 328 |
|
| 329 | 329 |
if CMD == 'signal': |
| 330 |
print """graph_args -l 0 --lower-limit -100 --upper-limit 0
|
|
| 330 |
print("""graph_args -l 0 --lower-limit -100 --upper-limit 0
|
|
| 331 | 331 |
graph_title Wireless client signal |
| 332 | 332 |
graph_scale no |
| 333 |
graph_vlabel dBm Signal""" |
|
| 333 |
graph_vlabel dBm Signal""")
|
|
| 334 | 334 |
elif CMD == 'noise': |
| 335 |
print """graph_args -l 0 --lower-limit -100 --upper-limit 0
|
|
| 335 |
print("""graph_args -l 0 --lower-limit -100 --upper-limit 0
|
|
| 336 | 336 |
graph_title Wireless client noise |
| 337 | 337 |
graph_scale no |
| 338 |
graph_vlabel dBm Noise""" |
|
| 338 |
graph_vlabel dBm Noise""")
|
|
| 339 | 339 |
elif CMD == 'rate': |
| 340 |
print """graph_args -l 0 --lower-limit 0 --upper-limit 500
|
|
| 340 |
print("""graph_args -l 0 --lower-limit 0 --upper-limit 500
|
|
| 341 | 341 |
graph_title Wireless client WiFi rate |
| 342 | 342 |
graph_scale no |
| 343 |
graph_vlabel WiFi Rate""" |
|
| 343 |
graph_vlabel WiFi Rate""")
|
|
| 344 | 344 |
elif CMD == 'clients': |
| 345 |
print """graph_title Number of connected clients
|
|
| 345 |
print("""graph_title Number of connected clients
|
|
| 346 | 346 |
graph_args --base 1000 -l 0 |
| 347 | 347 |
graph_vlabel number of wireless clients |
| 348 | 348 |
graph_info This graph shows the number of wireless clients connected |
| 349 | 349 |
clients.label clients |
| 350 | 350 |
clients.draw LINE2 |
| 351 |
clients.info The number of clients.""" |
|
| 351 |
clients.info The number of clients.""")
|
|
| 352 | 352 |
elif CMD == 'dhcpclients': |
| 353 |
print """graph_title Number of active DHCP leases
|
|
| 353 |
print("""graph_title Number of active DHCP leases
|
|
| 354 | 354 |
graph_args --base 1000 -l 0 |
| 355 | 355 |
graph_vlabel number of DHCP clients |
| 356 | 356 |
graph_info This graph shows the number of active DHCP leases |
| 357 | 357 |
dhcpclients.label leases |
| 358 | 358 |
dhcpclients.draw LINE2 |
| 359 |
dhcpclients.info The number of leases.""" |
|
| 359 |
dhcpclients.info The number of leases.""")
|
|
| 360 | 360 |
elif CMD == 'wanTraffic': |
| 361 | 361 |
speed = getWanSpeed() |
| 362 |
print """graph_title WAN interface traffic
|
|
| 362 |
print("""graph_title WAN interface traffic
|
|
| 363 | 363 |
graph_order recv send |
| 364 | 364 |
graph_args --base 1000 |
| 365 | 365 |
graph_vlabel bits in (-) / out (+) per ${graph_period}
|
| ... | ... | |
| 377 | 377 |
send.negative recv |
| 378 | 378 |
send.cdef send,8,* |
| 379 | 379 |
send.max %s |
| 380 |
send.min 0""" % (speed, speed) |
|
| 380 |
send.min 0""" % (speed, speed))
|
|
| 381 | 381 |
else: |
| 382 |
print "Unknown command: %s" % CMD
|
|
| 382 |
print("Unknown command: %s" % CMD, file=sys.stderr)
|
|
| 383 | 383 |
sys.exit(-2) |
| 384 | 384 |
|
| 385 | 385 |
if CMD in ['clients', 'dhcpclients', 'wanTraffic']: |
| ... | ... | |
| 388 | 388 |
else: |
| 389 | 389 |
clients = getData() |
| 390 | 390 |
for client in clients: |
| 391 |
print "MAC_%s.label %s" % (client, client)
|
|
| 391 |
print("MAC_%s.label %s" % (client, client))
|
|
| 392 | 392 |
|
| 393 | 393 |
sys.exit(0) |
| 394 | 394 |
else: |
Formats disponibles : Unified diff