From 8990114eb33e021947ed997f11960dfabfd11474 Mon Sep 17 00:00:00 2001 From: Antoine Van Elstraete Date: Mon, 27 Dec 2021 23:32:47 +0100 Subject: [PATCH] Responses codes --- knot_ | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ knot_responses | 1 + 2 files changed, 53 insertions(+) create mode 100755 knot_ create mode 120000 knot_responses diff --git a/knot_ b/knot_ new file mode 100755 index 0000000..826c590 --- /dev/null +++ b/knot_ @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +import yaml +from sys import argv +from os import getenv + + +def responses(stats, config): + ''' + This will show what knot have responded. + ''' + responses_stats = {} + if 'response-code' not in stats['mod-stats']: + responses_stats.update({'NOERROR': 0}) + else: + for code in stats['mod-stats']['response-code']: + responses_stats.update( + { + code: + stats['mod-stats']['response-code'][code] + } + ) + # Configure the plugin : + if config: + print("graph_title Knot responses") + print("graph_category dns") + print("graph_vlabel responses") + print("graph_args --base 1000 --lower-limit 0") + for code in responses_stats: + print(f"{code}.label {code}") + print(f"{code}.type DERIVE") + print(f"{code}.min 0") + else: # Send the values + for code in responses_stats: + print(f"{code}.value {responses_stats[code]}") + + +if __name__ == '__main__': + # Retrieve datas : + file = getenv('stats_file_path') + with open(file, "r") as stats_file: + stats = yaml.safe_load(stats_file) + if len(argv) > 1 and argv[1] == "config": + config = True + else: + config = False + if "responses" in argv[0]: + responses(stats, config) + elif "proto" in argv[0]: + pass + else: + pass # Nothing happens if no "munin underscore args" diff --git a/knot_responses b/knot_responses new file mode 120000 index 0000000..22ba831 --- /dev/null +++ b/knot_responses @@ -0,0 +1 @@ +knot_ \ No newline at end of file