1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-29 04:14:55 +00:00

Make plugin behave nicely when running autoconf

Re-raising exceptions will allow PyMunin to decide how to handle
them depending on debug setting.
When in 'autoconf' simply return from __init__ to allow correct
answer to be printed.
This commit is contained in:
Sandro 2022-06-13 17:53:50 +02:00
parent 08b889d9dc
commit 99dfc5d16e

View file

@ -183,7 +183,7 @@ class MuninNftCountersPlugin(MuninPlugin):
""" """
MuninPlugin.__init__(self, argv, env, debug=True) MuninPlugin.__init__(self, argv, env, debug)
# Munin graph parameters # Munin graph parameters
graph_category = "network" graph_category = "network"
@ -191,21 +191,27 @@ class MuninNftCountersPlugin(MuninPlugin):
try: try:
self.counters = getCounters() self.counters = getCounters()
except ValueError: except ValueError:
print("# No counters in nftables. Try adding some first.", if self._argv[1] == "autoconf":
"# See 'munin-doc %s' for more information." % self.plugin_name, return
sep="\n") else:
sys.exit(1) print("# No counters in nftables. Try adding some first.",
"# See 'munin-doc %s' for more information." % self.plugin_name,
sep="\n")
raise
except Exception as err: except Exception as err:
print("# Plugin needs to be run as root since nftables can only be", if self._argv[1] == "autoconf":
"# run as root.", return
"#", else:
"# Use the following setting in the configuration file", print("# Plugin needs to be run as root since nftables can only be",
"# to enable root privileges:", "# run as root.",
"#", "#",
"# [%s]" % self.plugin_name, "# Use the following setting in the configuration file",
"# user root", "# to enable root privileges:",
sep="\n") "#",
sys.exit(err) "# [%s]" % self.plugin_name,
"# user root",
sep="\n")
raise
count_only = self.envGet("count_only") count_only = self.envGet("count_only")
@ -276,14 +282,10 @@ class MuninNftCountersPlugin(MuninPlugin):
""" """
# Any exceptions (e.g. insufficient permissions, missing dependencies)
# will already throw an exception when the plugin is initialized since
# the plugin reads all its data from nftables. So below should always
# return True (print "yes").
try: try:
counters = getCounters() counters = getCounters()
return True return True
except ValueError: except:
return False return False