Thank you for reading this post, don't forget to subscribe!
Вот мой шаблон
Ставим софт на постфикс, нам понадобится logtail:
apt-get install logtail -y
Создаём файл /etc/zabbix/zabbix_scripts/postfix_data.sh:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
#!/bin/bash MAILLOG=/var/log/mail.log PARTLOG=/tmp/postfix_data_partlog.log OFFSETFILE=/tmp/postfix_data_offset.dat DATAFILE=/tmp/postfix_data.dat LOGTAIL=/usr/sbin/logtail VALS=( 'bounced' 'deferred' 'sent' 'expired' 'reject' 'connect_from' 'connect_to' 'refused' 'queue' ) [ ! -e "${DATAFILE}" ] && touch "${DATAFILE}" && chown zabbix:zabbix "${DATAFILE}" [ ! -e "${PARTLOG}" ] && touch "${PARTLOG}" && chown zabbix:zabbix "${PARTLOG}" # если читаем данные if [ -n "$1" ]; then key=$(echo ${VALS[@]} | grep -wo $1) if [ -n "${key}" ]; then value=$(grep -e "^${key};" "${DATAFILE}" | cut -d ";" -f2) echo "${value}" else exit 2 fi # если пишем данные else "${LOGTAIL}" -f"${MAILLOG}" -o"${OFFSETFILE}" > ${PARTLOG} for i in "${VALS[@]}"; do case ${i} in "bounced") value=$(grep "status=bounced" ${PARTLOG} | wc -l) ;; "deferred") value=$(grep "status=deferred" ${PARTLOG} | wc -l) ;; "sent") value=$(grep "status=sent" ${PARTLOG} | wc -l) ;; "expired") value=$(grep "status=expired" ${PARTLOG} | wc -l) ;; "reject") value=$(grep "NOQUEUE: reject" ${PARTLOG} | wc -l) ;; "connect_from") value=$(grep ": connect from" ${PARTLOG} | wc -l) ;; "connect_to") value=$(grep ": connect to" ${PARTLOG} | wc -l) ;; "refused") value=$(grep "refused to talk to me:" ${PARTLOG} | wc -l) ;; "queue") value=$(mailq | grep -v "Mail queue is empty" | grep -c "^[A-F0-9]") ;; esac grep -q ${i} ${DATAFILE} && sed -i "s/^${i};.*$/${i};${value}/" "${DATAFILE}" || echo "${i};${value}" >> "${DATAFILE}" done fi |
Разрешаем выполнение:
chmod a+x postfix_data.sh
Добавляем данный скрипт в cron от рута:
crontab -e
*/10 * * * * bash /etc/zabbix/zabbix_scripts/postfix_data.sh
service cron restart
Добавляем файл /etc/zabbix/zabbix_agent.d/userparameter_postfix.conf:
UserParameter=postfix[*],/etc/zabbix/zabbix_scripts/postfix_data.sh $1
Перезапускаем агента:
service zabbix-agent restart
Цеплаяем шаблон заббикса к хосту и наблюдаем картинку: