Skip to content

Munin Plugin

Christian edited this page Jun 26, 2020 · 1 revision

Very basic plugin, but it fits in my setup.

Plugin configuration

[msmtpq]
user root

Munin plugin (msmtpq)

#!/usr/bin/env bash
set -eu -o pipefail
declare -a input=()

# CHANGE THIS LINE TO MATCH YOUR HOME/QUEUE DIRECTORIES!
for queue in {/home,/srv/nfs/home,/mnt/home}/*/.msmtpq/
do
	if [[ -d "$queue" ]]
	then
		input+=( "$queue" )
	fi
done

if [[ "${1:-}" == "autoconf" ]]
then
	echo "no"
	exit
elif [[ "${1:-}" == "config" ]]
then
	echo "graph_title msmtp-yaqi"
	echo "graph_vlabel Mails in queue"
	echo "graph_category mail"
	echo "graph_total Total"

	if [[ "${#input[@]}" -gt 0 ]]
	then
		find "${input[@]}" -maxdepth 0 -type d \
			-printf 'u%U.label %u\nu%U.min 0\nu%U.critical 1\n' \
		| sort -k 1
	fi

	exit
fi

if [[ "${#input[@]}" -gt 0 ]]
then
	find "${input[@]}" -maxdepth 1 \
		\( \
			\( -type d -name '.msmtpq' \) -o \
			\( -type f -name '*-*-*,*' ! -name '*,0' \) \
		\) \
		-printf '%U\n' | sort | uniq -c \
	| awk '{ print "u"$2".value "($1-1); }'
fi
Clone this wiki locally