Skip to content

Commit

Permalink
Add Zabbix postfix monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Jan 10, 2024
1 parent 57dafd4 commit bf1d9b9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Used by docker-compose
DOCKER_PROJECT_NAME=
ZABBIX_HOST_NAME=

LDAP_LOG_LEVEL=0

Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
33 changes: 33 additions & 0 deletions postfix-stats.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bf1d9b9

Please sign in to comment.