diff --git a/plugins/network/olsrd b/plugins/network/olsrd index e74568d0..5cf16755 100755 --- a/plugins/network/olsrd +++ b/plugins/network/olsrd @@ -35,14 +35,13 @@ Collect basic information about the neighbours of an OLSR node: This plugin works with the following python interpreters: - * Python 2 * Python 3 * micropython (e.g. OpenWrt) =head1 VERSION - 0.4 + 0.5 =head1 AUTHOR @@ -84,7 +83,7 @@ MICROPYTHON_BIN=$(which micropython || true) if [ -n "$MICROPYTHON_BIN" ]; then "$MICROPYTHON_BIN" -X "heapsize=${MICROPYTHON_HEAP:-512k}" "$0" "$@" else - python "$0" "$@" + python3 "$0" "$@" fi exit $? @@ -93,14 +92,78 @@ exit $? true <{tempfile}' .format(hosts=" ".join(hosts), tempfile=tempfile)) # micropython supports only "os.system" (as of 2015) - thus we need to stick with it for # OpenWrt. - returncode = os.system(command) + returncode = system(command) if returncode != 0: return {} lines = _read_file(tempfile) - os.unlink(tempfile) + unlink(tempfile) # example output for one host: # 192.168.2.41 round-trip min/avg/max = 4.226/4.226/4.226 ms result = {} @@ -293,11 +357,11 @@ def do_config(): # link quality with regard to neighbours print("multigraph olsr_link_quality") print(LQ_GRAPH_CONFIG.format(title="OLSR Link Quality")) - for link in links: + for index, link in enumerate(links): print(LQ_VALUES_CONFIG.format( label=link["remote"], suffix="_{host}".format(host=get_clean_fieldname(link["remote"])), - draw_type="AREASTACK")) + draw_type=("AREA" if index == 0 else "AREASTACK"))) for link in links: print("multigraph olsr_link_quality.host_{remote}" .format(remote=get_clean_fieldname(link["remote"]))) @@ -315,7 +379,7 @@ def do_config(): # neighbour ping print("multigraph olsr_neighbour_ping") - print(NEIGHBOUR_PING_CONFIG.format(title="Ping time of neighbours")) + print(NEIGHBOUR_PING_CONFIG.format(title="Ping time of OLSR neighbours")) for link in links: print(NEIGHBOUR_PING_VALUE .format(host=link["remote"], host_fieldname=get_clean_fieldname(link["remote"]))) @@ -375,11 +439,11 @@ if __name__ == "__main__": if len(sys.argv) > 1: if sys.argv[1] == "config": do_config() - if os.getenv("MUNIN_CAP_DIRTYCONFIG") == "1": + if getenv("MUNIN_CAP_DIRTYCONFIG") == "1": do_fetch() sys.exit(0) elif sys.argv[1] == "autoconf": - if os.path.exists(os.getenv('OLSRD_BIN_PATH', '/usr/sbin/olsrd')): + if access(getenv('OLSRD_BIN_PATH') or '/usr/sbin/olsrd', 0): print('yes') else: print('no') @@ -392,7 +456,7 @@ if __name__ == "__main__": pass else: # unknown argument - sys.stderr.write("Unknown argument{eol}".format(eol=LINESEP)) + sys.stderr.write("Unknown argument{eol}".format(eol=linesep)) sys.exit(1) do_fetch()