From 0d775b2827f54d130b5f5c8c5821eeb44022e2a2 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 5 Mar 2018 13:48:38 +0100 Subject: [PATCH 1/2] Implement plugin for monitoring nullmailer. --- plugins/mail/nullmailer_queue | 90 +++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100755 plugins/mail/nullmailer_queue diff --git a/plugins/mail/nullmailer_queue b/plugins/mail/nullmailer_queue new file mode 100755 index 00000000..d5a92867 --- /dev/null +++ b/plugins/mail/nullmailer_queue @@ -0,0 +1,90 @@ +#!/bin/bash + +: <<=cut + +=head1 NAME + +nullmailer_queue - monitor for nullmailer's send queue. + +=head1 APPLICABLE SYSTEMS + +This plugin is applicable to any system running the nullmailer MTA. + +=head1 CONFIGURATION + +This plugin needs to be able to read the nullmailer queue, so it +will need to run as that user or root. + +Additionally, the nullmailer queue directory may vary; in that case you +can specify it with the "queuedir" and "errordir" environment variables. + +Example: + +[nullmailer_queue] +user nullmail + +env.queuedir /var/spool/nullmailer/queue +env.errordir /var/spool/nullmailer/failed + +=head1 INTERPRETATION + +This plugin will draw a stack of 2: the number of emails in the queue, and +the number of emails that have permanently failed sending. The latter has +a warning attached, since those should never happen. + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=head1 VERSION + + 1.0.0 + +=head1 AUTHOR + +Bert Peters + +=head1 LICENSE + +GPLv2 + +=cut + +queuedir=${queuedir:-/var/spool/nullmailer/queue} +errordir=${errordir:-/var/spool/nullmailer/failed} + +case $1 in + autoconf) + if hash nullmailer-queue &> /dev/null; then + [[ -r "$queuedir" ]] && echo yes || echo "no (queue dir not readable)" + else + echo "no (nullmailer not installed)" + fi + ;; + + config) + cat <<-EOF +graph_args -l 0 +graph_title Nullmailer queue +graph_vlabel emails +graph_total total +graph_category mail + +queue.label queued +queue.draw AREASTACK +queue.info Number of emails currently in the queue + +failed.label failed +failed.draw AREASTACK +failed.warning 0:0 +failed.info Number of emails that have permanently failed to send +EOF + ;; + + *) + echo "queue.value $(find "$queuedir" -type f | wc -l)" + # Failed does not exist until there has been a failure, so mute the "file not found" + echo "failed.value $(find "$errordir" -type f 2> /dev/null | wc -l)" + ;; +esac From 4ca4e8d937bc29cba417b704b09ba39e59489db4 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Tue, 6 Mar 2018 11:08:02 +0100 Subject: [PATCH 2/2] Implement suggested changes. --- plugins/mail/nullmailer_queue | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/mail/nullmailer_queue b/plugins/mail/nullmailer_queue index d5a92867..47a0f1e2 100755 --- a/plugins/mail/nullmailer_queue +++ b/plugins/mail/nullmailer_queue @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh : <<=cut @@ -22,7 +22,6 @@ Example: [nullmailer_queue] user nullmail - env.queuedir /var/spool/nullmailer/queue env.errordir /var/spool/nullmailer/failed @@ -56,8 +55,8 @@ errordir=${errordir:-/var/spool/nullmailer/failed} case $1 in autoconf) - if hash nullmailer-queue &> /dev/null; then - [[ -r "$queuedir" ]] && echo yes || echo "no (queue dir not readable)" + if hash nullmailer-queue >/dev/null 2>/dev/null; then + [ -r "$queuedir" ] && echo yes || echo "no (queue dir not readable)" else echo "no (nullmailer not installed)" fi