get_number_of_deferred_mailqueue.sh: add support for configuration file.

This commit is contained in:
Christoph 2018-10-07 14:55:59 +02:00
parent c1934d5bde
commit b497e29755
2 changed files with 92 additions and 15 deletions

View File

@ -0,0 +1,25 @@
# ----------------------------------------------------
# ---
# - Parameter Settings for script 'get_number_of_deferred_mailqueue.sh'.
# ---
# ----------------------------------------------------
# - notification_addresses
# -
# - Where to send notifications
# -
# - Defaults to argus@oopen.de
# -
#notification_addresses="argus@oopen.de"
# - count_warn
# -
# - If number of deferred e-mails exceeds give parameter 'count_warn'
# - an e-mail will be written to adresse(s) given at parameter
# - 'notification_addresses'.
# -
# - Defaults to 100
# -
#count_warn=100

View File

@ -1,9 +1,14 @@
#!/usr/bin/env bash
declare -i count_warn
declare -i count_warn_default=100
script_name="$(basename $(realpath $0))"
working_dir="$(dirname $(realpath $0))"
notification_addresses="ckubu-adm@oopen.de"
conf_file="${working_dir}/conf/${script_name%%.*}.conf"
# ----------
# - Some variables
# ----------
host_name=`hostname -f`
from_address="postfix@$host_name"
@ -11,12 +16,37 @@ content_type='Content-Type: text/plain;\n charset="utf-8"'
postfix_queue_dir=/var/spool/postfix
declare -i count_warn
if [[ $1 =~ ^-?[0-9]+$ ]];then
count_warn=$1
else
count_warn=$count_warn_default
fi
default_notification_addresses="argus@so36.net"
declare -i default_count_warn=100
# ----------
# Base Function(s)
# ----------
info (){
if $terminal ; then
echo ""
echo -e " [ \033[32m\033[1mInfo\033[m ]: $*"
echo ""
fi
}
warn (){
if $terminal ; then
echo ""
echo -e " [ \033[33m\033[1mWarn\033[m ] $*"
echo ""
fi
}
# ----------
# - Some checks ..
# ----------
if [[ -t 1 ]] ; then
terminal=true
@ -24,6 +54,31 @@ else
terminal=false
fi
# ----------
# Read Configurations from $conf_file
# ----------
# - Give your default values here
# -
if [[ -f "$conf_file" ]]; then
source "$conf_file"
else
warn "No configuration file '$conf_file' present.\n
Loading default values.."
fi
# - Commandline parameter overwrites those given at configuration file
# -
if [[ $1 =~ ^-?[0-9]+$ ]];then
count_warn=$1
fi
[[ -n "$notification_addresses" ]] || notification_addresses="$default_notification_addresses"
[[ -n "$count_warn" ]] || count_warn=$default_count_warn
## - Get number of "deferred" mails in postfix queue
@ -84,18 +139,15 @@ if [[ $count -gt $count_warn ]]; then
fi
info "$count messages in postfix deferred queue"
if $terminal ; then
echo ""
#echo "*${host_name}* - $(date +"%d.%m.%Y %H:%M h")"
echo ""
echo "[ Info ]: $count messages in postfix deferred queue"
echo ""
echo ""
echo "Recipient domain and time (age in minutes):"
echo -e " \033[1mRecipient domain and time (age in minutes)\033[m:"
echo "$(qshape deferred)"
echo ""
echo ""
echo "Sender domain and time (age in minutes):"
echo -e " \033[1mSender domain and time (age in minutes)\033[m:"
echo "$(qshape -s deferred)"
echo ""
fi