summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2019-06-12 22:23:02 +0200
committerlookshe <github@lookshe.org>2019-06-12 22:23:02 +0200
commit676e4b08127a024a76f0ee0d76cb59a21288d1bb (patch)
tree10cdfbea0fb092388bb5802837c7fa46497f689d
parent8cf5835ff1902c0ad1b242e17bf3022e32e437a9 (diff)
parentbc859e8f29ee3cf4b129db0136c39915d443d376 (diff)
Merge branch 'master' of ssh://git.fucktheforce.de/user/tristan/RetrieveAdBlocklistsHEADmaster
-rw-r--r--dnsmasq-munin-plugin111
1 files changed, 111 insertions, 0 deletions
diff --git a/dnsmasq-munin-plugin b/dnsmasq-munin-plugin
new file mode 100644
index 0000000..5dad33e
--- /dev/null
+++ b/dnsmasq-munin-plugin
@@ -0,0 +1,111 @@
+#!/bin/bash
+# -*- sh -*-
+
+: <<=cut
+
+=head1 NAME
+
+dnsmasq - Plugin to monitor dnsmasq queries
+
+=head1 APPLICABLE SYSTEMS
+
+All systems with "bash", "sed" and "dnsmasq"
+
+=head1 CONFIGURATION
+
+The following is the default configuration
+
+ [dnsmasq]
+ env.logfile /var/log/dnsmasq/dnsmasq.log
+
+The user running this plugin needs read access to the
+dnsmasq logfiles:
+
+ [dnsmasq]
+
+ user root
+
+ =head1 INTERPRETATION
+
+This plugin shows a graph with the number of forwarded, cached and
+blocked dns queries.
+
+=head1 MAGIC MARKERS
+
+ #%# family=auto
+ #%# capabilities=autoconf
+
+=head1 VERSION
+ 0.0.1
+
+=head1 BUGS
+
+=head1 AUTHOR
+
+Me, myself and I
+Based on dnsmasq plugin by: notracking <https://github.com/notracking>
+Based on fail2ban plugin by: Stig Sandbeck Mathisen <ssm@fnord.no>
+
+=head1 LICENSE
+
+GPLv2
+
+=cut
+
+
+##############################
+# Configurable variables
+logfile=${logfile:-/var/log/dnsmasq/dnsmasq.log}
+
+# Print the munin values
+values() {
+ echo -n "dnsmasq_forwarded.value "
+ cat ${logfile} | sed -n "/^$(date --date='5 minutes ago' '+%b %_d %H:%M')/,\$p" | grep ": forwarded" | wc -l
+
+ echo -n "dnsmasq_cached.value "
+ cat ${logfile} | sed -n "/^$(date --date='5 minutes ago' '+%b %_d %H:%M')/,\$p" | grep ": cached" | wc -l
+
+ echo -n "dnsmasq_blocked.value "
+ cat ${logfile} | sed -n "/^$(date --date='5 minutes ago' '+%b %_d %H:%M')/,\$p" | grep "/block.list" | wc -l
+}
+
+# Print the munin config
+config() {
+ echo 'graph_title DNS queries'
+ echo 'graph_info This graph shows the number of queries resolved by dnsmasq'
+ echo 'graph_category network'
+ echo 'graph_vlabel Number of queries'
+
+ echo 'graph_args --base 1000 -l 0'
+ echo 'graph_total total'
+
+ echo 'dnsmasq_forwarded.label forwarded'
+ echo 'dnsmasq_cached.label cached'
+ echo 'dnsmasq_blocked.label blocked'
+}
+
+# Print autoconfiguration hint
+autoconf() {
+ if [ -f ${logfile} ]
+ then
+ echo "yes"
+ else
+ echo "no (${logfile} not found)"
+ fi
+ exit
+}
+
+##############################
+# Main
+
+case $1 in
+ config)
+ config
+ ;;
+ autoconf)
+ autoconf
+ ;;
+ *)
+ values
+ ;;
+esac \ No newline at end of file