diff --git a/.env.dist b/.env.dist index 39e509e..a1a3aad 100755 --- a/.env.dist +++ b/.env.dist @@ -1,5 +1,6 @@ # Used by docker-compose DOCKER_PROJECT_NAME= +ZABBIX_HOST_NAME= LDAP_LOG_LEVEL=0 diff --git a/README.md b/README.md index 888e428..eee373f 100755 --- a/README.md +++ b/README.md @@ -58,3 +58,21 @@ docker exec -it xxxx-crowdsec-1 cscli alerts remove --ip=x.x.x.x docker exec -it xxxx-mailserver-1 fail2ban-client banned docker exec -it xxxx-crowdsec-1 setup fail2ban unban x.x.x.x ``` + +## Empty queue for an email + +```sh +mailq | tail +2 | awk 'BEGIN { RS = "" } /postmaster@domain.intranet$/ { print $1 }' | tr -d '*!#' | postsuper -d - +``` + +## Re-queue emails for an email + +```sh +mailq | tail +2 | awk 'BEGIN { RS = "" } /postmaster@domain.intranet$/ { print $1 }' | tr -d '*!#' | postsuper -r - +``` + +## Mails in queue + +```sh +mailq | cut -d ' ' -f 1 | sort | uniq | wc -l +``` diff --git a/postfix-stats.sh b/postfix-stats.sh new file mode 100644 index 0000000..34c5869 --- /dev/null +++ b/postfix-stats.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +set -eu + +ME=$(realpath $(dirname $0)) + +if [ ! -f $ME/.env ]; then + echo "Missing env: $ME/.env" + exit 1 +fi + +# Load up .env +set -o allexport +# Source the file +. $ME/.env +set +o allexport + +CONTAINER_NAME="${DOCKER_PROJECT_NAME}-mailserver-1" + +# See: https://serverfault.com/a/577766/336084 +for q in active bounce corrupt defer deferred flush hold incoming maildrop; do + zabbix_sender -z $ZABBIX_HOST -s $ZABBIX_HOST_NAME -k "email-monitoring.servers.mx" -o "$(printf '{"data":[{"{#MX_HOST}":"%s", "{#QUEUE_NAME}":"%s"}]}' ${OVERRIDE_HOSTNAME} ${q})" 1>/dev/null +done + +# See: https://serverfault.com/a/577766/336084 +for q in active bounce corrupt defer deferred flush hold incoming maildrop; do + count=$(docker exec $CONTAINER_NAME find /var/spool/postfix/$q ! -type d -print | wc -l) + + if [ ! -z "${1:-}" ]; then + echo $q $count + fi + zabbix_sender -z $ZABBIX_HOST -s $ZABBIX_HOST_NAME -k "email-monitoring.servers.mx.queue[${OVERRIDE_HOSTNAME},$q]" -o "$count" 1>/dev/null +done