From dedc9683b6c6707d2657f06c3b5094495bc3991a Mon Sep 17 00:00:00 2001 From: Sandro Date: Wed, 8 Jun 2022 01:21:42 +0200 Subject: [PATCH] Raise ValueError in getCounters() Only there are we able to determine if counters are present. nft_cmd() only checks if there is any output at all. --- plugins/network/nft_counters | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/network/nft_counters b/plugins/network/nft_counters index 65af4b5c..51864026 100755 --- a/plugins/network/nft_counters +++ b/plugins/network/nft_counters @@ -124,7 +124,7 @@ def nft_cmd(nftlib, cmd): if len(output) == 0: # more error control - raise ValueError("ERROR: no output from libnftables") + raise RuntimeError("ERROR: no output from libnftables") # transform the libnftables JSON output into generic python data structures ruleset = json.loads(output)["nftables"] @@ -144,8 +144,12 @@ def getCounters(): nft.set_handle_output(True) ruleset = nft_cmd(nft, "list counters") + counters = _find_objects(ruleset, "counter") - return _find_objects(ruleset, "counter") + if len(counters) > 0: + return counters + else: + raise ValueError("No counters in nftables") class MuninNftCountersPlugin(MuninPlugin): @@ -179,7 +183,7 @@ class MuninNftCountersPlugin(MuninPlugin): """ - MuninPlugin.__init__(self, argv, env, debug) + MuninPlugin.__init__(self, argv, env, debug=True) # Munin graph parameters graph_category = "network"