Current File : //proc/3/root/etc/node_exporter/scripts/postfix
#!/bin/bash
check_postfix_mailqueue() {
# Can be set via environment, but default is fetched by postconf (if available,
# else /var/spool/postfix)
SPOOLDIR="/var/spool/postfix"


warning=0
critical=0

# Get values
deferred=`(/bin/test -d $SPOOLDIR/deferred && /bin/find $SPOOLDIR/deferred -type f ) | wc -l`
active=`(/bin/test -d $SPOOLDIR/active && /bin/find $SPOOLDIR/active -type f ) | wc -l`
maildrop=`(/bin/test -d $SPOOLDIR/maildrop && /bin/find $SPOOLDIR/maildrop -type f ) | wc -l`
incoming=`(/bin/test -d $SPOOLDIR/incoming && /bin/find $SPOOLDIR/incoming -type f ) | wc -l`
corrupt=`(/bin/test -d $SPOOLDIR/corrupt && /bin/find $SPOOLDIR/corrupt -type f ) | wc -l`
hold=`( /bin/test -d $SPOOLDIR/hold && /bin/find $SPOOLDIR/hold -type f ) | wc -l`
}

check_postfix_mailqueue
echo "postfix_deferred_mails $deferred"
echo "postfix_active_deliveries $active"
echo "postfix_locally_posted_mails $maildrop"
echo "postfix_incoming_mails $incoming"
echo "postfix_corrupt_mails $corrupt"
echo "postfix_onhold_mails $hold"


if [ $corrupt -gt 0 ]; then
  echo "postfix_mailqueue_status -1"
	exit 0
fi

if [ $warning -gt 0 ] && [ $critical -gt 0 ]; then
   if [ $deferred -gt $critical ]; then
      echo "postfix_mailqueue_status -1"
      exit 0
   elif [ $deferred -gt $warning ]; then
      echo "postfix_mailqueue_status 0"
      exit 0
   else
      echo "postfix_mailqueue_status 1"
      exit 0
   fi
else
   echo "postfix_mailqueue_status 1"
   exit 0
fi