From 99dfc5d16e73eae53f6c9635ac7b6f89189c9c8a Mon Sep 17 00:00:00 2001 From: Sandro Date: Mon, 13 Jun 2022 17:53:50 +0200 Subject: [PATCH] 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. --- plugins/network/nft_counters | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/plugins/network/nft_counters b/plugins/network/nft_counters index d03d4eba..66f46d21 100755 --- a/plugins/network/nft_counters +++ b/plugins/network/nft_counters @@ -183,7 +183,7 @@ class MuninNftCountersPlugin(MuninPlugin): """ - MuninPlugin.__init__(self, argv, env, debug=True) + MuninPlugin.__init__(self, argv, env, debug) # Munin graph parameters graph_category = "network" @@ -191,21 +191,27 @@ class MuninNftCountersPlugin(MuninPlugin): try: self.counters = getCounters() except ValueError: - print("# No counters in nftables. Try adding some first.", - "# See 'munin-doc %s' for more information." % self.plugin_name, - sep="\n") - sys.exit(1) + if self._argv[1] == "autoconf": + return + else: + 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: - print("# Plugin needs to be run as root since nftables can only be", - "# run as root.", - "#", - "# Use the following setting in the configuration file", - "# to enable root privileges:", - "#", - "# [%s]" % self.plugin_name, - "# user root", - sep="\n") - sys.exit(err) + if self._argv[1] == "autoconf": + return + else: + print("# Plugin needs to be run as root since nftables can only be", + "# run as root.", + "#", + "# Use the following setting in the configuration file", + "# to enable root privileges:", + "#", + "# [%s]" % self.plugin_name, + "# user root", + sep="\n") + raise 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: counters = getCounters() return True - except ValueError: + except: return False